views:

42

answers:

1

I have a Wordpress website that needs to display a 3rd party newsletter signup form. This sign-up form has lots of fields and takes up its own full page.

I want to display a simple "enter email address, hit submit" form at the top of every page. When the user hits submit, it should take them to the full form, where their email address is already pre-populated in the appropriate field.

What's a good way to pass the input value from the short form to the long form? I'm inclined to use the URL somehow, but I've never approached it before.

(My skills: expert XHTML/CSS. competent with WP theme hacking. comfortable enough with PHP and Javascript to move things around, but not enough to write them from scratch.)

Thanks!


ETA: Here's the shell of what worked (thanks for the solutions!):

Form One

<form method="get" action="form2.php">

email:
<input type="text" name="email" value="" />

<input type="submit" />

</form>

Form One (form2.php)

<form>

Email field:
<input type="text" value="<?php echo $_GET["email"]; ?>" />

</form>
+2  A: 

you just send the value of the first email form via the get or post method and in the php/html for the second form use <input type="text" name="email" value"$_POST['firstFormsName']" />

of course this example assumes you're using the post method in your form on the first page.

Jamie
Thanks! That works!
sarahdopp
Beware of [XSS](http://en.wikipedia.org/wiki/Cross-site_scripting).
BalusC
@BalusC That script would only be vulnerable to XSS if it used $_GET or $_REQUEST. In this case $_POST is fine.
Adrian
@Adrian: that's absolutely false. POST variables are just as vulnerable to being injected by a third party as GET variables (eg. imagine evildomain.com hosting a `<form method="POST" action="http://www.mydomain.com/form.php">` and automatically posting it via JS. In any case, `htmlspecialchars()` *must* be used to insert any text content into HTML regardless of where it came from: this is a simple matter of correctness, regardless of whether the bug is exploitable or not. `value="<?php echo htmlspecialchars($_POST['email']); ?>"`
bobince