How to deal with two submit buttons in a form?

I don't understand this,

if I do this and I click the check out button, the page won't go to the check out page,

<form action="cart.php" method="post" id="form-cart"> <button name="update" id="update" type="submit" value="Update cart">Update cart</button> <button name="checkout" id="checkout" type="submit" value="Check out">Check out</button> </form>

It only does if I change the name="checkout" to name="cart-checkout",

<form action="cart.php" method="post" id="form-cart"> <button name="update" id="update" type="submit" value="Update cart">Update cart</button> <button name="cart-checkout" id="checkout" type="submit" value="Check out">Check out</button> </form>

It works that way but does not make any sense to me, do you know why it does it that way?

So I tried to use <a> tag inside the <button> tag and it goes to the check out page,

<form action="cart.php" method="post" id="form-cart"> <button name="update" id="update" type="submit" value="Update cart">Update cart</button> <button name="checkout" id="checkout" type="submit" value="Check out"><a href="checkout.php">Check out</a></button> </form>

But does it a valid html to put <a> tag inside the <button> tag?

-------------Problems Reply------------

Why not change the buttons to:

<input name="update" id="update" type="submit" value="Update cart">
<input name="cart-checkout" id="checkout" type="submit" value="Check out">

Then in PHP (on cart.php) you can do:

<?php
if($_POST){
if(isset($_POST['update']){
// process update
} else if(isset($_POST['cart-checkout']){
// process cart checkout
// or uncomment the below line to forward to checkout.php
// header("Location: checkout.php");
}
}
?>

What about making one <button> that simply acts like a <a href=""> ?

-edit-

Whoops, sorry, misread. <button onclick="window.location='/nextpage';"> ?

I would actually use JavaScript here with an onclick event, which will take you to the checkout page.

Category:php Views:6 Time:2011-11-28

Related post

  • Submitting a rails remote_form with external submit button 2010-03-03

    I'm trying to submit a rails form using a submit trigger that is outside of the form tags. So I have my form: <% remote_form_for Package.new, :url => { :action => :rate_shop, :ids_sales_order_id => params[:ids_sales_order_id], :id => @

  • Which submit button was pressed? 2011-09-16

    In this jsfiddle http://jsfiddle.net/littlesandra88/eGRRb/ have I submit buttons that are auto-generated. Each table row gets an unique ID number, and if needed each submit button can get the same unique number as well. Question The problem is that t

  • Dealing with the "deadspace" when an submit button is styled using sliding doors 2012-04-13

    I have got some markup that looks like this: <div class="button"> <span class="image"></span> <input type="submit" value="Test button"> </div> The CSS: .button{ background: url('http://img33.imageshack.us/img33/4108/left

  • What is the best approach for (client-side) disabling of a submit button? 2008-09-05

    Details: Only disable after user clicks the submit button, but before the posting back to the server ASP.NET Webforms (.NET 1.1) Prefer jQuery (if any library at all) Must be enabled if form reloads (i.e. credit card failed) This isn't a necessity th

  • jquery/js - How do I select the parent form based on which submit button is clicked? 2008-11-22

    I have a web page with 3 forms on it. Not nested, just one after the other (they are almost identical, just one hidden variable that's different). A user will only fill in one form, and I'd like to validate/etc all the forms with only one JS script.

  • What are the best practices for dealing with the Back Button in IE (and Firefox) 2009-11-20

    I know this in old issue but I can't figure out the best practices for dealing with the back button. I'm writing a web application with lots of data movement between the browser and the backend server. I currently use post and of course when the user

  • Can I determine which Submit button was used in javascript? 2010-02-19

    I have a very simple form with a name field and two submit buttons: 'change' and 'delete'. I need to do some form validation in javascript when the form is submitted so I need to know which button was clicked. If the user hits the enter key, the 'cha

  • (php) How do make my submit button work in ie 2010-04-12

    My form works in firefox but not ie. I've tried using a hidden text field (fail)... I tried using an image instead of a submit button (fail)... are there any other solutions? Here is my form: <?php print "<table width='522' cellpadding='2' cell

  • HTML Form submit buttons 2010-04-19

    I know, this might be a very basic question but I am not 100% sure on the topic. When submitting forms, is there a precise value that needs to be passed in order to inform that a certain button was pressed... or can any value be passed in relation to

  • How to make the value in submit button ,transparent? 2010-05-18

    I have a submit button in a form and i use a css class which sets a background image as the submit button. I need to give a value to this submit button, but i dont want it to be displayed to the user. If i set the css color property to transparent it

  • Chrome: On pressing Enter on a Textbox of a Submits page without calling onClick of submit button on that form 2010-06-04

    I have a scenario in which I have 2 Submit Buttons in a form for going back and forward. Both the buttons have different JavaScript associated with it. It is working great if we press these buttons to navigate. But when in Google Chrome, when someone

  • How do I create multiple submit buttons for the same form in Rails? 2010-06-12

    I need to have multiple submit buttons. I have a form which creates an instance of Contact_Call. One button creates it as normal. The other button creates it but needs to have a different :attribute value from the default, and it also needs to set th

  • Submit button doesnt submit form but checks the validations 2010-06-27

    The submit button works only for validating the javascript in the question.js file, but it doesnt do the basic function, which is submiting the form itself! Your help is very appreciated. `Ruby page code containing the form element <script type="t

  • Multiple Submit Buttons problem in Struts2 2011-01-01

    Trying to work with multiple submit buttons within a single form in struts2 application but not able to work. here is the jsp code i am using <tr> <td class="button"><input type="submit" value="Import" name="destinationImport" class="b

  • How to make a submit button display as a link? 2011-01-07

    This is not working in IE: .text-button { background: transparent; text-decoration: none; cursor: pointer; } <input type="submit" class="text-button" value="vote+"/> It displays a square button. --------------Solutions------------- Copied from

  • Submit button not working unless change input 2011-03-23

    I have a form calculator, when customer submit the form(input.php), it will open another page display the results(output.php target _blank). However, when they want to use the same page(input.php) to get the result again, the submit button not workin

  • Will a spam bot be able to submit a form if there is no submit button on the page? 2011-04-04

    Just wondered if anyone knows if a spam bot will be able to submit a form if there is no submit button on the page. Just trying to do some very basic spam prevention without using CAPTCHA. The thought is to use jQuery to render the submit button if t

  • Is it possible for user to submit a form if submit button is disabled? (Asking because of PHP validation) 2011-06-15

    When my form loads on the page, the submit button is disabled by default. Is it possible for a user to submit the form with this submit button disabled? (Either maliciously or by accident.) I ask because I have the form information being validated by

  • Why serialize does not include submit button name? 2011-06-18

    Why serialize (Jquery) does not include submit button name? In PHP I normally do this: if (isset($_POST['submit_signup'])) { print_r($_POST); //Then check firstname, password, etc POSTS } That don't work, what is the solution to this? --------------S

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.222 (s). 11 q(s)