Page 1 of 1

Two Forms on the Same PHP page

Posted: Tue Apr 13, 2004 8:14 am
by neophyte
How do you set up form tags for two or more forms on the same php page? How does that affect accessing the $_POST variables?

Posted: Tue Apr 13, 2004 8:18 am
by patrikG
You can't.

Posted: Tue Apr 13, 2004 8:23 am
by kettle_drum
You can give the forms a name, and since you can only submit one form at a time the variable names can be the same - you just need identify which form was sent.

Is this what you want?

DOH

Posted: Tue Apr 13, 2004 8:23 am
by neophyte
Yeah, exactly. How do you do that?

Replied

Posted: Tue Apr 13, 2004 8:42 am
by neophyte
How do you set up the form tags with names and then identify which form is submitted?

Posted: Tue Apr 13, 2004 8:45 am
by Bill H

Code: Select all

<form type="post" action="action.php">
<input type=hidden name="Form1" value=1>
// rest of form with inputs etc
<input type="submit">
<form>

<form type="post" action="action.php">
<input type=hidden name="Form2" value=1>
// rest of form with inputs etc.
<input type="submit">
<form>
and

Code: Select all

<?php

if (isset($_POST['Form1']))
{
    // Form1 was sumbitted
}
else
{
    // Form 2 was submitted
}

?>

Posted: Tue Apr 13, 2004 8:46 am
by kettle_drum
You can name the forms with <form name="blah"> and then to identify which was sent you can either have a hidden field in each form that says which form it is.

Weird

Posted: Tue Apr 13, 2004 9:22 am
by neophyte
I got a strange browser phenom yesterday. I have to forms. Neither are named. In IE 5.5 on XP the action of the first form was used as opposed to the second form's action when the submit button for the second form was hit. I didn't have any problems with that on Mozilla with a Mac or Linux platform. Now that's weird. Or does anybody know what happened there?

Posted: Tue Apr 13, 2004 9:34 am
by JAM
I've read about this phenomena many moons ago also. I can to the fully recall the complete article about it, but it was while discussing various IE bugs.

I belive it falls under the issue about how good different browsers support the tag-standards. You know, the ever lasting discussion about:

Code: Select all

<p>text</p>
as opposed to

Code: Select all

text<p>
just to mention a very small example.

Don't take my words on it tho, might be taken out of context somewhere else. But if someone finds a good resource or article on it, do post a link here.

Posted: Tue Apr 13, 2004 10:59 am
by liljester
or you could name the submit buttons differently and check wich one was submitted...

Posted: Tue Apr 13, 2004 11:08 am
by kettle_drum
AS long as you close the forms before starting the next one you should be fine.

.:Forgot from last post:.
You could also use a javascript function to sort out what fields to send depending on what button is clicked.

IDIOT

Posted: Tue Apr 13, 2004 1:42 pm
by neophyte
Don't forget to close </form with a ">". DOH.