Jump to content

<form>'s name


midnite

Recommended Posts

i have several forms with different names. Each with its own submit buttons. But they all send to the same php. Such as:

<form name="one" method="post" action="same.php">...</form><form name="two" method="post" action="same.php">...</form>

In "same.php", is it possible to retrieve the value one or two? So that i know which form is sending.Thanks!

Link to comment
Share on other sites

Um, if you have a submit button inside the form, it will only take the information from that form. At least for everything I've done it has. And if you want to avoid potential mix ups, make sure each field has a different name then have the page process the fields you actually want processed. You could also have something like this:

<form action="same.php?form=one" method="post">...</form><form action="same.php?form=two" method="post">...</form>

And have your PHP look like:

<?php$form = mysql_real_escape_string($_GET['form']); //I use mysql escape to prevent injection attacksif($form == "one") {*code for one*}elseif($form == "two") {*code for two*}

Link to comment
Share on other sites

thanks ragae and justsomeguy. i think i will use the name of the submit button. It is a bit disappointing that the name of the <form> seems to be redundant (or i dont know what it is used for ...?)

Link to comment
Share on other sites

It's not sent to the server on submit. Javascript is the only thing that has access to it. I actually never use a name for my forms, if I want Javascript to access the form I just give it an ID and access it that way.

Link to comment
Share on other sites

when i need to access a form, i use a CSS selector to look through the document, since i usually know where the forms are going to be in relation to the document and other div's

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...