Problem passing the correct variable in a Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sree78
Forum Commoner
Posts: 39
Joined: Tue May 20, 2003 11:38 am

Problem passing the correct variable in a Form

Post 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:
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

Code: Select all

if ($Selection = Trial)
change to:

Code: Select all

if ($_POST['selection '] == "Trial")
sree78
Forum Commoner
Posts: 39
Joined: Tue May 20, 2003 11:38 am

Post 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..
Post Reply