Eternal_Student
asked on
PHP form question
Hi - I have two different arrays of checkboxes in a form:
---------
<input name='service[]' value='abcde' type='checkbox' />
...
&
<input name='extra[]' value='abcde' type='checkbox' />
...
--------
There are also other form elements that I check and put into strings to eventually email like so:
--------
/Set recipient email
$myemail = "email@hotmail.com";
//See if the form has been submitted
if($_POST['submit']){
//Assign the text fields to variables
$name = $_POST['name'];
$position = $_POST['position'];
$company = $_POST['company'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$quote = $_POST['quote'];
$further = $_POST['further'];
$other = $_POST['other'];
//Now to validate the form
$errors = array();
if($name == ""){
array_push($errors, "You did not enter your name!");
}
if($email == ""){
array_push($errors, "You did not enter an email address!");
}
else if(ereg("[A-Za-z0-9_-]+([. ]{1}[A-Za- z0-9_-]+)* @[A-Za-z0- 9-]+([.]{1 }[A-Za-z0- 9-]+)+", $email)) {
$emailadd = "valid";
}
else {
$emailadd = "invalid";
}
if ($emailadd == "invalid") {
array_push($errors, "That does not appear to be a valid email address!");
}
//If there are no errors then send the email
if(count($errors) == 0){
$to = "$myemail";
$subject = "Enquiry";
$body = "Name: $name \n Email: $email \nPosition: $position \nCompany: $company \nAddress: $address \nPostcode: $postcode \nPhone no: $phone \nFax no: $fax \n\n$quote ";
$header = "From: $email";
mail($to, $subject, $body, $header);
}
}
?>
--------
Now, my question is, how do I add each selected checkbox and its' value into a string to email correctly? Taking into account that there are two groups of checkboxes?
Many thanks.
---------
<input name='service[]' value='abcde' type='checkbox' />
...
&
<input name='extra[]' value='abcde' type='checkbox' />
...
--------
There are also other form elements that I check and put into strings to eventually email like so:
--------
/Set recipient email
$myemail = "email@hotmail.com";
//See if the form has been submitted
if($_POST['submit']){
//Assign the text fields to variables
$name = $_POST['name'];
$position = $_POST['position'];
$company = $_POST['company'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$quote = $_POST['quote'];
$further = $_POST['further'];
$other = $_POST['other'];
//Now to validate the form
$errors = array();
if($name == ""){
array_push($errors, "You did not enter your name!");
}
if($email == ""){
array_push($errors, "You did not enter an email address!");
}
else if(ereg("[A-Za-z0-9_-]+([.
$emailadd = "valid";
}
else {
$emailadd = "invalid";
}
if ($emailadd == "invalid") {
array_push($errors, "That does not appear to be a valid email address!");
}
//If there are no errors then send the email
if(count($errors) == 0){
$to = "$myemail";
$subject = "Enquiry";
$body = "Name: $name \n Email: $email \nPosition: $position \nCompany: $company \nAddress: $address \nPostcode: $postcode \nPhone no: $phone \nFax no: $fax \n\n$quote ";
$header = "From: $email";
mail($to, $subject, $body, $header);
}
}
?>
--------
Now, my question is, how do I add each selected checkbox and its' value into a string to email correctly? Taking into account that there are two groups of checkboxes?
Many thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Now, if it's selected:
echo "My output....";
if (isset($_GET['abcde'])) { echo "Checkbox was selected..."; }
Does this help?