Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tell name of form from php script ... ?

Status
Not open for further replies.

dbeezzz

Technical User
Nov 30, 2005
54
KR
Is there anyway to tell the name of the form being submitted from the php script. I have multiple forms on my page and I want to be able to distinguish between them easily.

I don't want to have to send them to different directories or parse the name attributes unless I have to.
 
Huh?

Have a hidden field with the form name. On the next page call it.
<form>
<input type="hidden" name="school_form1" value="sf1"/>
blah blah
</form>

<form>
<input type="hidden" name="school_form2" value="sf2"/>
blah blah
</form>

On the next script echo it:
echo $_POST['school_form'];


I dont know if that is what you want?
 
building on itech20059's post, perhaps it would be better just to call the hidden field the same thing in each form and just adjust the value. then use switch to determine what you want to do when you get to the receiving page. otherwise you have the problem of determining which variable is set.

thus
Code:
<form action="somepage.php" method="post">
<input type="hidden" name="formname" value="sf1"/>
blah blah
</form>

<form action="somepage.php" method="post">
<input type="hidden" name="formname" value="sf2"/>
blah blah
</form>


//receiving page
$form = isset($_POST['formname'])?$_POST['formname']:"blank";

switch ($form):
  case "sf1":
  //take action
  break;
  case "sf2":
  //take a different action
  break;
  deafult:
  echo " arrived in error?";
endswitch;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top