Amending function so that it runs automatically
Posted: Tue Jan 05, 2010 9:40 am
Hi,
I have a function that runs whenever a form is submitted using $_POST. However, I want this function to run when the page first loads also as I have changed slightly the way the form works and I believe this work exactly how I want it.
The function is:
How can I change this so that it runs automatically and not reliant on the form.
This is also some of the code from the form as this might be helpful:
If anyone can help it would be greatly appreciated! I am so close to completing this script but keep encountering things that I never foresaw!
Thanks!
Russ
I have a function that runs whenever a form is submitted using $_POST. However, I want this function to run when the page first loads also as I have changed slightly the way the form works and I believe this work exactly how I want it.
The function is:
Code: Select all
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart = $newcart;How can I change this so that it runs automatically and not reliant on the form.
This is also some of the code from the form as this might be helpful:
Code: Select all
<form action="basket.php?action=update" method="post" id="cart">
<input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" />
<button type="submit">Update cart</button>
</form>Thanks!
Russ