You could make it a self acting form and do an if/else check on which submit button was pressed to determine what action to do.
<?PHP
if ($_POST['updatePrice']) {
// we're here because the updatePrice button has been hit - update the price code
// goes here, and then we store all the information from the form into an array
// so we can echo it out later in the form
$submitted = array('name' => $_POST['name'], 'price' => $updatedPrice);
}
elseif ($_POST['addToCart']) {
// cart code here
// probably a redirect. if errors, populate $submitted for echoing current data
// and then output error
$submitted = array('name' => $_POST['name'], 'price' => $_POST['price']);
$error = 'You must fill out all fields.';
}
else {
// form probably not submitted or first access - blank $submitted
$submitted = array('name' => '', 'price' => '');
}
// now we output the form and any errors, as well as populate data
if (isset($error)) {
echo '<span style="color: red;">'.$error.'</span><br />';
}
echo '<form name="multiform" action="'.$_SERVER['PHP_SELF'].'" method="post">
Name: <input type="text" name="name" value="'.$submitted['name'].'" /><br />
Price: <input type="text" name="price" value="'.$submitted['price'].'" /><br />
<input type="submit" name="addToCart" value="Add to Cart" /><input type="submit" name="updatePrice" value="Update Price" /></form>';
?>
Something like that may work. But I don't know how having two submit buttons like that will work - you may need to use a type="button" on one of them and use some JS voodoo to make it submit, I'm not sure. Or possibly radio buttons along side a submit button, but that's rather kludgy.
Meh.