Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

TodVader

macrumors 6502a
Original poster
Sep 27, 2005
596
0
Quebec, Canada
I created a search form that changes "SPACE" for "+". (done with javascript) When I click on submit, it goes to searchresults.php. When I add:

Code:
<?php echo $_REQUEST["text"]; ?>

between <p> and </p>, it works fine and shows the search with + signs instead of spaces.

Here's the place where I need it:
Code:
<?php
require_once '/PATH/carp.php';
// Add any desired configuration settings before CarpCacheShow
// using "CarpConf" and other functions
CarpConf('cborder',''); 
CarpConf('caorder',''); 
CarpConf('descriptiontags','table|/table|tr|/tr|td|/td|a|/a|img|br');
CarpConf('maxitems','15');
CarpConf('cacheinterval','10');
CarpConf('poweredby',''); 
CarpCacheShow('http://rss.api.eba...r=y&satitle=<?php echo $_REQUEST["text"]; ?>&afmp=&sacat=80070&saslop=1&fss=0');
?>

(it's almost at the end if you can't find it)

Here's the problem: it doesn't convert to the value because it sees it as part of the url.

I know it isn't my search form because it works when I use the PHP request outside of the url.

The above code works if I replace the PHP tag with the actual search. ex: wanted+item+search

This is part of a script that shows eBay RSS feeds.

Thanks to anyone willing to help me!
 
You can't nest <?php ?> tags.

Do this instead:

PHP:
CarpCacheShow("http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&satitle={$_REQUEST["text"]}");

Also any variables inside single quotes won't be parsed (read), any variables inside double quotes will.

Also when accessing array values you must put them inside curly braces {} when using in a string.

Just a couple of php gottchas, nothing too serious.

Also — you probably won't to check (validate) user input before using it in your code.
 
Also when accessing array values you must put them inside curly braces {} when using in a string.

I wondered about that. I ran into it recently and didn't bother looking up how to do it.

I agree on elppa's solution too, that's what I saw as being wrong.
 
Thanks to both of you, it now works! It took me a couple hours creating it but it was well worth it. I couldn't find that last little thing on google and I'm glad you found it.
 
I thought everything was over but I discovered a new problem with my friend IE. When you enter 2 words or more and press enter instead of the submit button, it doesn't apply my javascript so there is a space in between the 2 words instead of a +. I tested with IE7, Safari, Mac firefox, PC Firefox. Everywhere else except IE will apply the javascript just as if I clicked on submit.

Here's the code for my submit button:
Code:
<input type=submit name=action value="Search!"
onClick="replaceChars(document.subform.text.value);">

Is there some code I could add to my search field similar to the onclick of the submit button? I tried adding the onclick to the field but it didn't work obviously.

This search thing is starting to be a pain. It started out as a 20 minute thing in my head.:rolleyes:

If anyone needs the URL to help me, ill pm it to you.

Thank you very much for any help.
 
Instead of onclick try using onsubmit. If that doesn't work try onchange, but the onsubmit should take care of it.
 
After trying what you said, it didn't work so I googled onClick and realised I was putting my javascript command in the submit button code instead of the form code. I took the code you gave me, put in after <form... and removed my onclick from the submit button.

It worked!

It's incredible how much web design has changed in 10 years (I stopped for approximately 10 years and started again a couple months ago). It's like starting over again with all that CSS, Javascript and PHP.

Thanks for the help

It was my error but safari & firefox were smart enough to understand what I wanted.
 
After trying what you said, it didn't work so I googled onClick and realised I was putting my javascript command in the submit button code instead of the form code. I took the code you gave me, put in after <form... and removed my onclick from the submit button.

It worked!

Doh, yeah that was a brain fart on my part, at least you figured it out though.
 
Doh, yeah that was a brain fart on my part, at least you figured it out though.
You mean on my part :cool: Without you mentioning onsubmit, I don't think I would have though of changing it. In my mind, since you submit using the submit button, the code had to be there but now that I see it the right way, it seems more logical that way.

Thanks, you save me countless hours fixing "stupid" problems when google can't help me anymore hehe.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.