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
https://forums.phpfreaks.com/topic/74168-2-submit-buttons-in-one-form-hmmmmm/
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.

 

????

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>

Archived

This topic is now archived and is closed to further replies.

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