Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Need help in checkbox

the mail() function

Moderators: macek, egami, gesf

Need help in checkbox

Postby setin » Sat Jul 23, 2011 12:06 pm

Hello everyone iam new to this forum iam creating a form in php where i want when a user select to check-box in form then the checkbox value will be submited to the admin below is my form coding in php
value is showing but only 1 value is showing even i have selected 3 checkboxes iam confused how to fetch value from foreach and show below in my table.
This is html form
<label for="website">Country</label>
<input name="country[]" type="checkbox" value="India" />India
<input name="country[]" type="checkbox" value="Australia" />Australia
<input name="country[]" type="checkbox" value="UK" />UK

This is php code for form
<?php
$to = "";
$Subject = "Testing Subject";
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$website = $_REQUEST["website"];
$food = $_REQUEST["food"];
$drink = $_REQUEST["drink"];
$country = $_REQUEST["country"];
foreach ($country as $statename)
{
echo "$statename";
}
$comment = $_REQUEST["comment"];
echo $result = "<table>
<tr>
<td><strong>Contact Inforamtion</strong> </td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Name</td>
<td>$name</td>
</tr>
<tr>
<td>Email</td>
<td>$email</td>
</tr>
<tr>
<td>Website</td>
<td>$website</td>
</tr>
<tr>
<td>Food</td>
<td>$food</td>
</tr>
<tr>
<td>Drink</td>
<td>$drink</td>
</tr>
<tr>
<td>Country</td>
<td>$test</td>
</tr>
<tr>
<td>Comments</td>
<td>$comment</td>
</tr>
</table>";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
mail($to,$Subject,$result,$headers);
?>
setin
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Jul 23, 2011 12:00 pm

Re: Need help in checkbox

Postby bigjoe11a » Tue Sep 27, 2011 1:21 pm

It looks like your trying to set them in a array() and I'm not sure about that
//the html file
Code: Select all
<form>
<label for="website">Country</label>
<input name="c1" type="checkbox" value="India" />India
<input name="c2" type="checkbox" value="Australia" />Australia
<input name="c3" type="checkbox" value="UK" />UK
</form>


//the php code.
Code: Select all
<?php

$choices = array();

// Your using post to get the values

if(isset($_POST['c1'])) {
$choices[0] = $_POST['c1'];
} else if (isset($_POST['c2'])) {
$choices[1] = $_POST['c2'];
} else if (isset($_POST['c2'])) {
$choices[2] = $_POST['c3'];
}

foreach (choice as choices) {
echo 'Your choices are ' . choice;
}
?>


Try that
User avatar
bigjoe11a
New php-forum User
New php-forum User
 
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA


Return to PHP coding => Mail

Who is online

Users browsing this forum: Pavinash and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.