Page 1 of 1

Problem passing the correct variable in a Form

Posted: Thu Jul 10, 2003 11:54 am
by sree78
Hi

I am having problem getting PHP to pass the correct variable from a form.

The case
-----------
I have one form which generate's 2 different type of replies automatically depending on which one of the variable it gets from the form.

Like for an example

Choose : Trial (radiobutton) Purchase(radiobutton)

If the user chooses Purchase, fills up the rest of the form and hit's submit then Reply B will be sent to the administrator else Reply A will be sent.

I can make this to work if I have different name for the fields like for an example


<input name="trial" value="trial" type="radio"/>Purchase
<input name="purchase" value="purchase" type="radio"/>Trial


The problem is, if I have different name, then I cannot have a validation script for this because it asks to fill both the field just because it has different Name

If I put the same name .. like for an example

<input name="selection" value="trial" type="radio"/>Purchase
<input name="selection" value="purchase" type="radio"/>Trial

then it only sents Reply A even if I choose Purchase as my option.

My code looks like this
--------------------------

<?

if ($Selection = Trial)
{
$to = "email@w.sag";
$subject = "Reply A";
$body="";
$fd = fopen ("trial.html", "r");
while (!feof ($fd))

{ $buffer = fgets($fd, 4096);
$body .= $buffer;
if (!strlen($buffer)) continue;
}

fclose ($fd);

$body = preg_replace("/#XXX#/", $XXX, $body);
$body = preg_replace("/#XXX#/", $XXX, $body);

} else {

$to = "email@w.sag";
$subject = "Reply B";
$body="";
$fd = fopen ("purchase.html", "r");
while (!feof ($fd))

{ $buffer = fgets($fd, 4096);
$body .= $buffer;
if (!strlen($buffer)) continue;
}

fclose ($fd);

$body = preg_replace("/#XXX#/", $XXX, $body);
$body = preg_replace("/#XXX#/", $XXX, $body);

}
?>

If I replace if ($Selection = Trial) with if ($trial)
the form works. I am trying my best to have the the Radio field name the same so i could have a validation script for it. Any ideas are highly appreciated. Thanks a million :roll:

Posted: Thu Jul 10, 2003 12:17 pm
by redhair

Code: Select all

if ($Selection = Trial)
change to:

Code: Select all

if ($_POST['selection '] == "Trial")

Posted: Thu Jul 10, 2003 2:34 pm
by sree78
Thanks a lot redhair .... It worked great... I tried the samething ut instead of $_POST I did $_REQUEST.. I got mixed up a lot.. anyway thanks a million.. I really appreciate it..