By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

multi-form variables

P: n/a
I have read quite a few posts and can't seem to find the answer to my
question. I need to be able to pass from fields to PHP from severel
different forms on a page. I have had to create multiple forms
because I am dynamically adding and subtracting form elememts of
various types in javascript based on user activity. My problem now is
getting all of these different form fields to PHP so I can write them
to MySQL. I am open to any suggestions and will try using cookies,
javascript arrays, hidden form fields, or whatever it takes. The only
drawback is I have to use multiple forms so combining forms is not an
option.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Greg Mascherino wrote:
I need to be able to pass from fields to PHP from severel
different forms on a page.
Only if they have the same name.

[...]
I am open to any suggestions and will try using cookies,
javascript arrays, hidden form fields, or whatever it takes.
Maybe (I don't know JavaScript) you can pull all values from all forms
when you click a "submit" and put them in hidden fields of another form
and POST _that_ form to PHP.

The only
drawback is I have to use multiple forms so combining forms is not an
option.


try this:

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<pre>'; print_r($_POST); echo '</pre>';
}
echo <<<HTML
Form1:
<form name="form1" action="" method="post">
<input type="hidden" name="both" value="both"/>
<input type="hidden" name="oneonly" value="oneonly"/>
<input type="submit"/>
</form>
<br/><hr/><br/>
Form2:
<form name="form2" action="" method="post">
<input type="hidden" name="both" value="both"/>
<input type="hidden" name="twoonly" value="twoonly"/>
<input type="submit"/>
</form>
HTML;
?>
When you submit the first form you'll be able to access $_POST['both']
and $_POST['oneonly'], but not $_POST['twoonly'].

Likewise for submitting the second form -- no $_POST['oneonly'].

--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

P: n/a
You must not use multiple forms.

Why do you think you have to?

--
mfg Christian (Chronial "at" web.de)

--
Composed with Newz Crawler 1.5 http://www.newzcrawler.com/
Jul 17 '05 #3

P: n/a
Hello,

On 12/15/2003 06:31 PM, Greg Mascherino wrote:
I have read quite a few posts and can't seem to find the answer to my
question. I need to be able to pass from fields to PHP from severel
different forms on a page. I have had to create multiple forms
because I am dynamically adding and subtracting form elememts of
various types in javascript based on user activity. My problem now is
getting all of these different form fields to PHP so I can write them
to MySQL. I am open to any suggestions and will try using cookies,
javascript arrays, hidden form fields, or whatever it takes. The only
drawback is I have to use multiple forms so combining forms is not an
option.

You may want to take a look at this class. It passes fields between
pages using just hidden fields.

http://www.phpclasses.org/multipageforms

--

Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.