put PHP tags in SRC of a link

Discussion in 'Web Design and Development' started by TodVader, May 8, 2008.

  1. TodVader macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #1
    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!
     
  2. elppa macrumors 68040

    elppa

    Joined:
    Nov 26, 2003
    #2
    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.
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    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.
     
  4. TodVader thread starter macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #4
    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.
     
  5. TodVader thread starter macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #5
    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.
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    Instead of onclick try using onsubmit. If that doesn't work try onchange, but the onsubmit should take care of it.
     
  7. TodVader thread starter macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #7
    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.
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    Doh, yeah that was a brain fart on my part, at least you figured it out though.
     
  9. TodVader thread starter macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #9
    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.
     

Share This Page