views:

26

answers:

1

Hello,

So I have:

<input type="text" id="keyword" placeholder="placeholder" value="" />

What is the best way to go about defining the value based on the link?

ie.

http://mysite.com/valueplacer?=thisisthevalue

Does this:

<input type="text" id="keyword" placeholder="placeholder" value="thisisthevalue" />

Thanks!

+3  A: 
<input type="text" id="keyword" placeholder="placeholder" value="<?php echo htmlspecialchars($_GET['q']); ?>" />

This is assuming that you are going to place a q there in the query string, as the key for the variable. This means the query string will look like

http://mysite.com/valueplacer?q=thisisthevalue

The htmlspecialchars() is for security.

If you actually do want your URL to look like that, you will need to parse $_SERVER['REQUEST_URI'].

I would not recommend doing it like that. Just use GET params as how they were intended.

alex
Sorry, use the GET params as they were intended?
John Franklin
@John I mean, just do `?q=value` not `?=value` (unless that was a typo).
alex
@alex ah gotcha, yea I overlooked that. Thanks..going to try it out.
John Franklin
@alex hmmm. Doesn't seem to be working. I have index.php in a directory(foo) on mysite.com. So, http://mysite.com/foo/?q=thisisthevalue.And then I have <input type="text" onfocus="" id="keyword" placeholder="foo" value="<?php echo htmlspecialchars($_GET['q']);?>" /> in index.php
John Franklin