/    Sign up×
Community /Pin to ProfileBookmark

I have a form with a text field on it
In the action of the form i need to use the value of the field in the header.
How do i get this value from the form

Here is the code where i am trying to get the value of the “qty” textfield into the form action

[code=php]
<form action=”cart.php?qty=<?php echo $_POST[‘qty’]; >” method=”post” name=”form1″ class=”style15″>
<p><strong>Quantity</strong>:<input name=”qty” type=”text” id=”qty” value=”1″ size=”2″ maxlength=”4″></p>
<p><input name=”Submit” type=”submit” value=”Add to Cart”></p>
</form>i have used $_POST but i dont know if this will take data from the previous page.
[/code]

i must have the qty in the form action i cannot use the $_POST method to get the field value on the next page as ive already tried this but it doesnt work with the rest of my code

Thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleMar 25.2007 — You will need to do this using javascript since it will need to be done client side. Why is it you can not retrieve the value when the form has been submitted?
Copy linkTweet thisAlerts:
@NightShift58Mar 26.2007 — i must have the qty in the form action i cannot use the $_POST method to get the field value on the next page as ive already tried this but it doesnt work with the rest of my code[/QUOTE]This statement, in practical terms, make absolutely no sense whatsoever.

But okay - let's assume that it's really so, for the sake of this example. Using javascript is not an option you need to use for this. The simpler method would be the following: Define your form as follows:[code=php]<form action="cart.php?qty=getfrompost" method="post" name="form1" class="style15">[/code]Then, in your "cart.php" script, at or very near the top:[code=php]<?php
IF (isset($_GET['qty']) AND $_GET['qty'] == "getfrompost") :
$_GET['qty'] = $_POST['qty'];
ENDIF;
?>[/code]
This will work but it's more in the "hack" category and shouldn't be considered a real solution.

The reason I use a placeholder for the GET is to make sure that only this form is considered for automatic copying of the $_POST['qty'] to $_GET['qty']. If you intend to do it for all forms, then just remove the IF and any incoming $_POST['qty'] will be copied to $_GET['qty'].
Copy linkTweet thisAlerts:
@jasonahouleMar 26.2007 — While that is all correct, it was stated that the value could not be retrieved on the next page. While that makes absolutely no sense to me, using javascript would allow the passing of the value for "qty" in the URL.
Copy linkTweet thisAlerts:
@NightShift58Mar 26.2007 — Of course he can.

If he can't, I can't and you can't and the whole PHP universe as we know it would collapse.
×

Success!

Help @bunny1 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.26,
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,
)...