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
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
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');
}
?>

Link to comment
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.