Jump to content

[SOLVED] Form actions


KevinM1

Recommended Posts

yes.

If you have two submit buttons with different names.

<input type="submit" name="action1" value="submit something">
<input type="submit" name="action2" value="submit something else">

 

then on the page you're submitting two have something like:

if(isset($_POST['action1'])){
     //do something
}elseif(isset($_POST['action2'])){
     //do something else
}

Link to comment
https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287918
Share on other sites

yes.

If you have two submit buttons with different names.

<input type="submit" name="action1" value="submit something">
<input type="submit" name="action2" value="submit something else">

 

then on the page you're submitting two have something like:

if(isset($_POST['action1'])){
     //do something
}elseif(isset($_POST['action2'])){
     //do something else
}

 

True, but I was thinking more along the lines of:

<?php

if(isset($_POST['submit1'])){
   //use <form action='$_SERVER['PHP_SELF']'>
}

else if(isset($_POST['submit2'])){
   //use <form action='formhandler.php'>
}

?>

Link to comment
https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287955
Share on other sites

you can't change the form action after it's been submitted.

try something like this:

<?php

if(isset($_POST['submit1'])){
   //action code on this page
}elseif(isset($_POST['submit2'])){
   //re-direct to other page
   require('formhandler.php');
}
?>

 

Yeah, I figured as much.  It's unfortunate, as I was hoping to use the post method rather than get, but oh well.

Link to comment
https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287971
Share on other sites

the code I've supplied will work fine and it's using post, not get.

Just set the form action to $_SERVER['PHP_SELF'].

The at the top of the page have a small statement checking if the form has been submitted. If it has it checks whether to include another page or echo the form.

 

When you use require() the required page will be able to read any post variables, so it will still work for you.

I use this method a lot on my sites.

Link to comment
https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287976
Share on other sites

the code I've supplied will work fine and it's using post, not get.

Just set the form action to $_SERVER['PHP_SELF'].

The at the top of the page have a small statement checking if the form has been submitted. If it has it checks whether to include another page or echo the form.

 

When you use require() the required page will be able to read any post variables, so it will still work for you.

I use this method a lot on my sites.

 

OH, okay.  Nice.  Thanks! :)

Link to comment
https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287983
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.