/    Sign up×
Community /Pin to ProfileBookmark

form action help

hi guys, ive just finished a shopping cart and i need some help putting 2 url’s into form buttons.

here are the two links:

[code]
<a href=”cart.php?action=remove_item&id=<?php echo $row[“itemId”]; ?>”>Remove</a>

<a href=”cart.php?action=empty_cart”>-Empty Cart-</a>
[/code]

now i need to put these into form buttons and i cant get it to work, here is what i have so far: (just for the remove cart so far)

[code]
<form name=”cart” method=”GET” action=””>

<input type=”submit” value=”Reset” onclick=”form.action=cart.php?action=empty_cart” class=”button” />

<input type=”submit” value=”Continue” onclick=”form.action=’details.php'” class=”button” />

</form>
[/code]

the continue button works. but the Reset button doesnt. am i doing this the right way?

any help would be much appreciated! thanx

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobNov 21.2004 — No, you aren't doing this the right way. You are relying on users with Javascript (not to mention, that I don't think this will work). What if you get a user with Javascript disabled? The far more secure method of doing this would be:

<i>
</i>&lt;form name="cart" method="POST" action="submit.php"&gt;

&lt;input type="submit" value="Reset" name="reset" alt="Reset" class="button" /&gt;

&lt;input type="submit" value="Continue" name="continue" alt="Continue" class="button" /&gt;

&lt;/form&gt;


Now, in your PHP code you check like this:

[code=php]
<?PHP
if(isset($_POST['reset']))
{
//empty cart
} elseif(isset($_POST['continue'])) {
//continue with form
}
?>
[/code]


I'd also advise against using the GET method for a form. Try not to use Get, unless you're using query strings. Like a dynamic link. And try to minimize the variables you pass through query strings. If you're going to have a form, take advantage and use POST instead.
[code=php]

[/code]
×

Success!

Help @Css_Calav spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...