Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Continue to Pass Elements in a Multi-Part Form

DZone's Guide to

How to Continue to Pass Elements in a Multi-Part Form

·
Free Resource

If you want to break a long form up into smaller parts, you need some way to pass all of the information along to the last page. Using hidden form elements and a foreach loop, we can do this with a quick snippet of php.

Here's the premise. At the bottom of each page after the first, loop through the $_POST array and create a hidden form element with the given name and value. When the information reaches the last script, it'll be as if the user entered everything onto the form in one page.

foreach ($_POST as $key => $value) { 
echo '<input type="hidden" name="' . $key . '" value="' . $value . '" />' . "\r\n";
}

If on the first page a user enters his name ('Bob') into a text field named 'firstname', you'll end up with this on every subsequent page.

<input type="hidden" name="firstname" value="Bob" />

That's all there is to it. Now go play with some forms.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}