Cameron
Cameron

Reputation: 28853

Input value based on query string

How could I pass a query string value such as domain.com/register?invite=MR5OMxTyjYmTjcwNTyQjTZMyY5YY into a input box on a page?

For example say I had this: <input type="text" name="invite" value="" />

I'm using PHP

To clarify what I mean, if a person loaded that URL, then the value would be automatically filled in with the query string of invite.

Upvotes: 0

Views: 2549

Answers (5)

Jacob Relkin
Jacob Relkin

Reputation: 163288

Simple:

<?php $invite = (array_key_exists('invite', $_GET)) ? htmlspecialchars($_GET['invite']) : ''; ?>
<input type="text" name="invite" value="<?php echo $invite; ?>" />

Upvotes: 4

Chandu
Chandu

Reputation: 82933

Try this:

<input type="text" name="invite" value='<?php echo $_GET["invite"]; ?>'  />

Upvotes: 1

Sander
Sander

Reputation: 1274

Try fetching the invite key with $_GET['invite'] from the address bar (validate it first of course to prevent XSS attacks ;) ) and then place it in your input field within that value part as $invite for example so you end up with value="$invite"

Hope that helps!

Upvotes: 1

Dalton Conley
Dalton Conley

Reputation: 1615

<input type="text" name="invite" value="<?php if(isset($_GET['register'])) echo $_GET['register']; ?>" />

This isn't secure at all, but it gives you a start.

Upvotes: 1

scragz
scragz

Reputation: 6700

<input type="text" name="invite" value="<?php echo $_REQUEST['invite']; ?>" />

Upvotes: 0

Related Questions