For me the big problem is action='foo.php'

Unless I am mistaken, any submit button would send the form to foo.php by POST, so I would need a second form to have an alternate action page.

I made a table to show the user's contents in the shopping cart, with a text box for them to alter their item quantities. The submit button for the form is the checkout button, but how would I make another button called update to send the form to a different page to change the shopping cart details if they altered their quantities?

About the only way I can figure is to query the shopping cart table again and make a second form but not show anything other than the submit button, which would be the second button.

What do you guys think? I've been beating my brain over this for two days now.

Any help would be appreciated.

use javascript take other buuon's type as button put

secondform.submit()

and make another form name as secondform this will send u to another form

I'm sorry, can you elaborate on that just a little more? I understand that I am supposed to use javascript, but I'm kind of confused. I have to make another form anyway is what you're saying?

Thank you for your reply.

wait i will give u code of this

try this code little study need here i was using some varible cooming from last page

<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<table width="550" border="0" align="center" cellpadding="10" cellspacing="0">
    <tr> 
        <td class="text">Step 2 Of 2 : Confirm Order </td>
    </tr>
</table>
<p id="errorMessage"><?= $errorMessage; ?></p>
<form action="<?= $_SERVER['PHP_SELF']; ?>?step=4" method="post" name="frmCheckout" id="frmCheckout">
    <table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
        <tr class="entryTableHeader"> 
            <td colspan="2" class="label"><strong>Contact Information</strong></td>
        </tr>
        <tr> 
            <td width="150" class="label"><span class="f13">Name</span></td>
            <td class="content"><?= $_POST[hidShippingFirstName]; ?><input name="hidShippingFirstName" type="hidden" id="hidShippingFirstName" value="<?= $_POST[hidShippingFirstName]; ?>">
            <input type="hidden" name="passw" value="<?=$_POST[passw] ?>"/>
            <input type="hidden" name="amount" value="<?=$_POST[amount] ?>"/></td>
        </tr>
        <tr> 
            <td width="150" class="label">Email Id </td>
            <td class="content"><?= $_POST[hidShippingLastName]; ?><input name="hidShippingLastName" type="hidden" id="hidShippingLastName" value="<?= $_POST[hidShippingLastName]; ?>"></td>
        </tr>
		<tr> 
            <td width="150" class="label"><span class="f13">Alternate Email ID</span></td>
            <td class="content"><?= $_POST[hidShippingemialid]; ?>
                <input name="hidShippingemialid" type="hidden" id="hidShippingemailid" value="<?= $_POST[hidShippingemialid]; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="label">Address</td>
            <td class="content"><?= $_POST[hidShippingAddress1]; ?>
                <input name="hidShippingAddress1" type="hidden" id="hidShippingAddress1" value="<?= $_POST[hidShippingAddress1]; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="label"><span class="f13">Organisation</span></td>
            <td class="content"><?= $_POST[hidShippingAddress2]; ?>
                <input name="hidShippingAddress2" type="hidden" id="hidShippingAddress2" value="<?= $_POST[hidShippingAddress2]; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="label"><span class="f13">Designation</span></td>
            <td class="content"><?= $_POST[hidShippingPhone];  ?>
                <input name="hidShippingPhone" type="hidden" id="hidShippingPhone" value="<?= $_POST[hidShippingPhone]; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="label"><span class="f13">Country</span></td>
            <td class="content"><?= $_POST[hidShippingState]; ?> <input name="hidShippingState" type="hidden" id="hidShippingState" value="<?= $_POST[hidShippingState]; ?>" ></td>
        </tr>
        
    </table>
    <p align="center"> 
        <!--<input name="btnBack" type="button" id="btnBack" value="&lt;&lt; Modify Shipping/Payment Info" onClick="window.location.href='checkout.php?step=1';" class="box"> -->
        <input type="button" value="<< Go Back" onclick="javascript:window.document.frmback.submit();;"/>
        &nbsp;&nbsp; 
        <input name="btnConfirm" type="submit" id="btnConfirm"  value="Confirm Order &gt;&gt;" class="box">
</form>
<form action="<?= $_SERVER['PHP_SELF']; ?>?step=1" method="post" name="frmback" id="frmCheckout">
<input name="hidShippingFirstName" type="hidden" id="hidShippingFirstName" value="<?= $_POST[hidShippingFirstName]; ?>" />
<input type="hidden" name="passw" value="<?=$_POST[passwd] ?>"/>
<input type="hidden" name="amount" value="<?=$_POST[amount] ?>"/>
<input name="hidShippingLastName" type="hidden" id="hidShippingLastName" value="<?= $_POST[hidShippingLastName]; ?>" />
<input name="hidShippingemialid" type="hidden" id="hidShippingemialid" value="<?= $_POST[hidShippingemialid]; ?>" />
<input name="hidShippingAddress1" type="hidden" id="hidShippingAddress1" value="<?= $_POST[hidShippingAddress1]; ?>" />
<input name="hidShippingAddress2" type="hidden" id="hidShippingAddress2" value="<?= $_POST[hidShippingAddress2]; ?>" />
<input name="hidShippingPhone" type="hidden" id="hidShippingPhone" value="<?= $_POST[hidShippingPhone]; ?>" />
<input name="hidShippingState" type="hidden" id="hidShippingState" value="<?= $_POST[hidShippingState]; ?>">
</form>

now u also have problem than reply

If they have javascript disabled, you'll never be able to update the quantites.

Think of adding an item, the same as changing quantities, overall it is a change.

You could repost the quantities and reflect them that way along with any new additional items.

If they have javascript disabled, you'll never be able to update the quantites.

Think of adding an item, the same as changing quantities, overall it is a change.

You could repost the quantities and reflect them that way along with any new additional items.

Thanks for both of you trying to help me. dickersonka, I thought about that javascript thing, but then I also realized that many sites on the internet DO use javascript, and if a person had it disabled, there would be a vast number of sites they couldn't view or browse correctly, so basically the user is told, enable javascript or you can't use this site. Cookies are the same way. I'm not arguing with you, you just presented an opportunity for me to ask a question that I've been wondering for a long time, and that is, how can you possibly cater to a user that has everything disabled? I mean almost every site on the web now uses javascript. This was the very reason I never bothered trying to learn javascript until now: the user might not even have it enabled, so why script in it? In a way I agree with you, but I was just wondering that.

As far as reposting, do you mean to make the page its own action page and re-POST the data back to the same page? If not, I guess I am totally lost.

Thank for your patience, guys.

diode

i use javascript for client side validation, not for functionality

lets say for a field that will be submitted needs to be a minimum of 8 characters, they type 4, and i can use javascript to warn them, but also validate server side that the input is 8 chars

this will ensure that your data is still valid, but adds an extra element just for look and feel on client side

with javascript enabled or disabled, this will work, just whether the client side gets a message before postback

yes i would repost the data back to itself, if its a button for submitting, read back the data, then redirect to final cart page with your updated data, otherwise stay on this page

Adding two submit buttons to the form allows you to send different GET or POST params depending on which submit button was pressed.

If you give a name and value for each Button, then in the POST, you'll get the name=value of the button set.

Eg: Your buttons are:

<input type="submit" name="action" value="Update" />
<input type="submit" name="action" value="Checkout" />

Then when the user clickes Update, you get:

$_POST['action'] = 'Update';

If the user clicks Checkout:

$_POST['action'] = 'Checkout';

This can be used by PHP to carry out the necessary task without involving JavaScript on the client side. It doesn't give you separate pages, just one page, but different values for the parameter named by the submit buttons.

If you want separate pages to handle the request, you can involve a "controller" into your PHP code, that will include() the correct file depending on the submit button clicked.

eg: controller.php

if ($_POST['action'] = 'Update') {

require_once('update.php');

} else if ($_POST['action'] = 'Checkout') {

require_once('checkout.php');

} else {

echo 'Action not specfied';

}

This is all server side however, so the client/browser still sees the url as controller.php?action=update or controller.php?action=checkout

The benefit is that you don't need JavaScript, and so will support http clients that dont' have JS or have JS turned off.

See also the <button> tag. It has better support for this as it allows a label different from the value attribute.

http://www.w3.org/TR/html401/interact/forms.html#h-17.5


eg:

<button name="action" value="update">Update Cart</button>
<button name="action" value="checkout">Checkout Now!</button>

With <input> you have to use the value attribute as the label. This makes the server side code dependent on a display item, rather then data/logic (Your model is dependent on the view if worded in the MVC pattern/paradigm) not the best thing.

eg:

If you wanted the checkout button to read "Checkout Now", you'd need to change the server side code to test the value to be "Checkout Now" if you use an <input>.
If you use <button>, you can rename the visual aspect, while keeping the controller logic the same.

ps: you could always make the dependency a variable that PHP will understand and write to HTML as well: eg:

define('checkout_label', 'Checkout Now');

if ($_POST['action'] = checkout_label) {
  require('checkout.php');
}

but I still think <button> is better.

commented: Nice examples +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.