Link to home
Start Free TrialLog in
Avatar of sunflowersh
sunflowersh

asked on

Urgent : How to send a radio button value via email?

Hello Experts,

I would like people to fill out a contact form and send those values via email. Email script works fine. The problem that I'm having is with sending selected radio button's value.

For example, if a user selects the second radio button using the sample code below, the email shows "Yes2" for each line calling $Primary. If it's possible, I would to show Yes or blank rather than Yes2 or Yes3 on the email message.

--- Desired email out put -----
Paticipant 1
Primary Contact:

Paticipant 2
Primary Contact: Yes

Paticipant 3
Primary Contact:
----------------------------------

Here is the sample code:

<---- Form Code --->

<?
if ($Primary == "Yes") {
    $Primary_checked = "checked";
} else {
    $Primary_checked = "";
}

if ($Primary == "Yes2") {
    $Primary2_checked = "checked";
} else {
    $Primary2_checked = "";
}

if ($Primary == "Yes3") {
    $Primary3_checked = "checked";
} else {
    $Primary3_checked = "";
}
?>

<input name="Primary" type="radio" value="Yes" <?php echo $Primary_checked;?>>
<input name="Primary" type="radio" value="Yes2" <?php echo $Primary2_checked;?>>
<input name="Primary" type="radio" value="Yes3" <?php echo $Primary3_checked;?>>
.....

--- Email Script ---
$emailBody ="\nParticipant 1\n \n";
$emailBody .="Primary Contact: ${_REQUEST['Primary]} \n";
$emailBody .="\nParticipant 2\n \n";
$emailBody .="Primary Contact: ${_REQUEST['Primary]} \n";
$emailBody .="\nParticipant 3\n \n";
$emailBody .="Primary Contact: ${_REQUEST['Primary]} \n";
$emailBody .="\nParticipant 4\n \n";
$emailBody .="Primary Contact: ${_REQUEST['Primary]} \n";
.....

Thanks in advance.
Avatar of venkateshwarr
venkateshwarr

You can find the substring...
For example,

$emailBody ="\nParticipant 1\n \n";
if (substr($_REQUEST['Primary'],0,3)=="Yes")  $emailBody .="Primary Contact:  Yes \n";
.
.
.

venkat
or simply,
if ($_REQUEST['Primary'])  $emailBody .="Primary Contact:  Yes \n";
Avatar of sunflowersh

ASKER

Thank you for the post.

I tried both of them, but I see "Yes" in all the paticipants' Primary Contact line.

I would like to show only one Yes in an e-mail message so we know who the primary contact is.

try this..
Here I am finding the index of "Yes" and

$pno = $_REQUEST['Primary']{3};
$totalparticpants = 6; // change the number according to your requirement....

for($i=1;$i<=totalparticpants;$i++)
{
$emailBody ="\nParticipant $i \n \n";
if($pno == $i) $emailBody .="Primary Contact: Yes \n";
else $emailBody .="Primary Contact: \n";
}
ASKER CERTIFIED SOLUTION
Avatar of venkateshwarr
venkateshwarr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much for your help, ven.

I started using hidden fields. It works ok, but the code gets ugly. Thanks for the clean code.
$pno = $_REQUEST['Primary']{3};

Could you tell me what {3} mean??
It means the fourth character in the string $_REQUEST['Primary'] string.