Jump to content

2 Submit Buttons in one form - HMMmmm


bri0987

Recommended Posts

Hello again all. :) Shopping Cart for Custom PC configuration

 

QUICK INFO...

 

configuration.php >>> I have TWO buttons on my Form.

 

1.) Update Price

2.) Add to Cart

 

Clicking on "Add to Cart" submits the FORM method POSTS to >>> cart.php

 

I cant figure out how to make it so when I click the button "Update Price"

... I can get the FORM to POST back to the same page (configuration.php , not cart.php)... The reason for this is that I plan on grabing the $_POST["Selected_Prices"] data and uploading the price at the top of the page and next to the "Add to cart" button. Of course this is just for users to make their lives easier.

 

Anyone have any help about this...

 

Let me know.

Link to comment
Share on other sites

add a if statement.

 

if($_POST['submit']){

 

}elseif($_POST['update']){

 

}

 

name the submit bottom submit and the update update.

 

But isn't the problem with this code that "No matter what button is clicked" both of them get submitted with the form.

So if my 2 submit buttons (one name=submit , two name=update) they will still both send to the $_POST.

 

????

Link to comment
Share on other sites

nope, you are giving each bottun a name so the code takes the bottun that have been pressed.

 

here is a code so you can test.

 

<?php
if($_POST['submit']){

echo 'you have submited the form';
}elseif($_POST['update']){

echo 'the form have been update';	
}else{

echo 'nothing has been done';
}
?>

<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <label>submit
  <input type="submit" name="submit" id="submit" value="Submit" />
  </label>
  <br />
  <label>update
  <input type="submit" name="update" id="update" value="update" />
  </label>
  <br />
  <label>
  nothing
  <input type="submit" name="nothing" id="nothing" value="nothing" />
  </label>
</form>

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.