tags:

views:

238

answers:

5

Hi, I'm creating a registration page and I would like to give the user the opportunity to review their information and go back and edit it before clicking a confirm button which inserts it into the database.

Is there a way to include two submit buttons which point to different scripts or would I have to duplicate the entire form but use hidden fields instead?

Any advice appreciated.

Thanks.

A: 

you can

like :

http://sureshk37.wordpress.com/2007/12/07/how-to-use-two-submit-button-in-one-html-form/

via php

<!--    userpolicy.html      -->
<html>
<body>
<form action="process.php" method="POST">
    Name <input type="text" name="username">
    Password <input type="password" name="password">
    <!--  User policy goes here           -->

    <!--            two submit button            -->
    <input type="submit" name="agree" value="Agree">
    <input type="submit" name="disagree" value="Disagree">
</form>
</body>
</html>

/*         Process.php         */
<?php
if($_POST['agree'] == 'Agree') {
    $username = $_POST['username'];
    $password = $_POST['password'];
      /* Database connection goes  here */

}
else {
    header("Location:http://user/home.html");
}
?>

or via javascript

Haim Evgi
+6  A: 

You can use two submit buttons with different names:

<input type="submit" name="next" value="Next Step">
<input type="submit" name="prev" value="Previous Step">

And then check what submit button has been activated:

if (isset($_POST['next'])) {
    // next step
} else if (isset($_POST['prev'])) {
    // previous step
}

This works because only the activated submit button is successful:

  • If a form contains more than one submit button, only the activated submit button is successful.
Gumbo
+2  A: 

As for every other HTML input element you can just give them a name and value pair so that it appears in the $_GET or $_POST. This way you can just do a conditional check depending on the button pressed. E.g.

<form action="foo.php" method="post">
    <input type="text" name="input">
    <input type="submit" name="action" value="Add">
    <input type="submit" name="action" value="Edit">
</form>

with

$action = isset($_POST['action']) ? $_POST['action'] : null;
if ($action == 'Add') {
    // Add button was pressed.
} else if ($action == 'Edit') {
    // Edit button was pressed.
}

You can even abstract this more away by having actions in an array.

BalusC
A: 

You can do it thoug javascript.

That way you can make 2 buttons or you let the user view the data before you actually save anything.

Laus Brandt
A: 

I certainly wouldn't repeat the form, that would be a fairly self-evident DRY violation. Presumably you will need the same data checks every time the form is submitted, so you could perhaps just have the one action and only run through the "add to database" part when the user hits the "approve" button.

glenatron