Link to home
Start Free TrialLog in
Avatar of Eternal_Student
Eternal_StudentFlag for United Kingdom of Great Britain and Northern Ireland

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.

ASKER CERTIFIED SOLUTION
Avatar of babuno5
babuno5
Flag of India image

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
Why do you give it the name "service[]" ? Just name it "service" to make it easier on yourself.

Now, if it's selected:

echo "My output....";
if (isset($_GET['abcde'])) { echo "Checkbox was selected..."; }


Does this help?