Jump to content

help with submit buttons


c_pattle

Recommended Posts

I was wondering if you can have a form that has different actions depending on what submit button is pressed.  I have two button and with one I was to use

 

<form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="post">

 

and with the other I want to use

 

<form action="preview.php" method="post">

 

I was to do this because I want to user to be able to preview their content before submitting.  I want the preview page to use the post variables as the value of the input fields so the user doesn't have to input their data again.  However because the form doesn't redirect the user to the preview page I have to save all the post variables as session variables. 

Link to comment
Share on other sites

I was wondering if you can have a form that has different actions depending on what submit button is pressed.  I have two button and with one I was to use

Most certainly can!

 

in the receiver script, you would just do this:-

if (isset($_POST['submit']) && ($_POST['submit'] == "First Button")){//call this button what you like!
//process form 1 'First Button' here
}
else{
//redirect back to form, processing error
header("location: yourfilenamehere");
}

if (isset($_POST['submit']) && ($_POST['submit'] == "Second Button")){//call this button what you like!
//process form 2 'Second Button' here
}
else{
//redirect back to form, processing error
header("location: yourfilenamehere");
}

 

There are simpler ways to action this, but it all down to this next part really!

 

<form action="yourfilename" method="POST">
<div>
CONTAINER FOR ALTERNATING CONTENT can be ajax/js etc
<input type="submit" name="submit" value="First Button"><--this changes depending what div is visible
</div>
</form>

 

Just depends of what div is set as visible as to what submit button gets made visible... this is pseudo code, and only offers the concept of how to construct this, there are other ways, but this is just the first that springs to mind, just google "div switcher" to see the options available, I use this similar sort of thing for doing single/multiple uploads, and it works a treat..

 

Rw

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.