Hello - I am new to the php world, but learning quickly.
I am working on a custom shopping cart page, index.php.
The form contains:
<FORM METHOD=POST ACTION="index.php">
In the form I have 'onchange="this.form.submit()" for the qty textbox's, so when the users enters or changes a qty the form submits and refreshes with a (php) calculated price based on quantity.
The form works great , but I cannot figure out how to add a button on the form to POST the variables to a new page.
I have tried adding a sub-form inside of the form with the cart button using
<FORM METHOD=POST ACTION="cart.php">
but it seems to ignore the cart.php, and if I add the button outside the form I lose all of the variables?
Any tips or suggestions appreciated -
Rob
How to post variables to a new page
Moderator: General Moderators
Re: How to post variables to a new page
Until you learn a little more and can apply some kind of ajax here I'd just let the user update the form via an "update" link or button. I would be annoyed if every time I changed something on a form the page reloaded.Perlyman wrote:In the form I have 'onchange="this.form.submit()" for the qty textbox's, so when the users enters or changes a qty the form submits and refreshes with a (php) calculated price based on quantity.
You can't use "sub-forms"Perlyman wrote:The form works great , but I cannot figure out how to add a button on the form to POST the variables to a new page.
I have tried adding a sub-form inside of the form with the cart button using
<FORM METHOD=POST ACTION="cart.php">
but it seems to ignore the cart.php, and if I add the button outside the form I lose all of the variables?
Any tips or suggestions appreciated -
Rob
Use a seperate submit button...
Code: Select all
<insert type="submit" name="submit" value="Submit"><insert type="submit" name="submit" value="Update">Code: Select all
switch($_POST['submit']){
case "Update":
// Do update stuff
break;
default:
// Do submit stuff
break;
}Thanks for the help TNSG.
I agree the onchange re-submitting is annoying, I originally had an 'Add to Cart' button but the client insisted on 'automatic' updating of the price.
But I'll work on him some more....
So if I use:
Can you point me in the direction of what syntax to use to call another page inside of php (and send the variables).
Thanks,
Rob
I agree the onchange re-submitting is annoying, I originally had an 'Add to Cart' button but the client insisted on 'automatic' updating of the price.
But I'll work on him some more....
So if I use:
Code: Select all
switch($_POST['submit']){
case "Update":
// Do update stuff
break;
default:
// Do submit stuff
break;
}Thanks,
Rob
Just to give you an idea...
Code: Select all
<?php
if(isset($_POST['posted'])){
switch($_POST['submit']){
case "Update":
// Do update stuff
echo "Updated";
break;
default:
// Do submit stuff
echo "Submitted";
break;
}
}
?>
<form method="post" action="#">
<input type="hidden" name="action" value="posted">
<input type="submit" name="submit" value="Submit"><input type="submit" name="submit" value="Update">
</form>