Forums

Capturing a var in the URL and filling in a form field

labiere 18 Oct, 2010
I feel like I should understand this with all that I've read, but I can't seem to get it to work.

A user visits my form - cal it 'enter_code' - a simple textbox that asks for a coupon code. I have PHP running On Submit that checks the validity of the code and redirects appropriately. Provided the code is a good one, they get directed to another form - called 'myform' - which has the code affixed as a variable in the URL to the second form:

$url = 'http://www.domain.com/index.php?option=com_chronocontact&chronoformname=myform&coupon=coupon123';

In 'myform' I have 2 dropdown input fields as well as a hidden item named 'coupon' that I set with an empty value in the form HTML. What I want is to have the value of the hidden item to be set dynamically to "coupon123" so that when I submit this second form (myform), the coupon data can be passed again as a variable affixed in the URL.

I have played in the OnSubmit area and in the Redirect plugin Extra Code area to set this, but I must be missing something. When I look at the source code when I land on the 'myform' page I see the hidden value set to '', which makes sense, but when i submit again and move on to another page how do I change the value before the submit so that I see the code again in the following page?
GreyHead 19 Oct, 2010
Hi labiere,

If I understand correctly I think this should do what you need
<?php
if ( !$mainframe->isSite() ) { return; }
$coupon = JRequest::getString('coupon', '', 'get');
?>
<input type='hidden' name='coupon' value='<?php echo $coupon; ?>' />


Bob
This topic is locked and no more replies can be posted.