I am working on a jquery mobile app. Now i want the user to be able to send a checklist. So i made a checklist and now i have to send it to an email adress. Can someone please tell me how to do this? I know it should be done with PHP, but my PHP skills are not that great. I know how to make and send a contact form but in a contact form there are no checkboxes that need to be filled in and sent.
This is the code in my HTML page:
<form id="form1" method="post" action="checklist.php">
<fieldset class="ui-corner-all" >
<div class="ui-checkbox">
<input id="checkbox-t0" class="custom" type="checkbox" name="checkbox-t0">
<label for="checkbox-t0">
<span class="ui-btn-inner ui-corner-top">
<span class="ui-btn-text">Vehicle checked for damage</span>
</span>
</label>
</div>
<div class="ui-checkbox">
<input id="checkbox-t1b" class="custom" type="checkbox" name="checkbox-t1b">
<label for="checkbox-t1b">
<span class="ui-btn-inner">
<span class="ui-btn-text">Oil checked</span>
</span>
</label>
</div>
<div class="ui-input-text">
<label for="achternaam" data-theme="a">
<span class="ui-btn-inner">
<span class="textbox"> Last name: </span></span>
</label>
<input type="text" name="achternaam">
</div>
</fieldset>
<fieldset>
<div class="ui-block-a"><button type="submit" name="submit" data-theme="a" >Send</button></div>
</fieldset></form>
There are more checkboxes, but it's not really necessary to show a hundred checkboxes here.
So how do I get the form to be submitted to a certain e-mail adress? Any help would be great, thank you!
I'm Dutch so some words are written in Dutch.
Do as you would normally do with your contact forms, a check box is just another type of input, the only difference is that if its not checked then no value will be sent in the POST and if no value attribute is set for the checkbox then it will default to on.
The simplest way to check if the value is not present in the POST (e.g not checked) is to build an array of all your inputs, and then loop through that, checking that each one is present within the POST array, if not handle accordingly, this will also eliminate unwanted POST values that don't want to handle.
<?php
//Check for POST
if($_SERVER['REQUEST_METHOD']=='POST'){
//All your inputs
$expecting = array('achternaam','checkbox-t0','checkbox-t1b');
//Start building your email
$email_content = '';
foreach($expecting as $input){
//Is checkbox?
if(substr($input,0,8)=='checkbox'){
$email_content .= ucfirst($input).':'.(isset($_POST[$input]) && $_POST[$input] == 'on' ? 'True' : 'False'.'<br />');
//achternaam and other non checkbox-* keys
}else{
$email_content .= ucfirst($input).':'.(!empty($_POST[$input]) ? $_POST[$input] : 'Unknown').'<br />';
}
}
/* Achternaam:Lawrence<br />Checkbox-t0:False<br />Checkbox-t1b:False<br /> */
print_r($email_content);
/* Mail it
if(mail('the_email_to_send_too@example.com', 'My Subject', wordwrap($email_content))){
//mail sent
}else{
//mail failed 2 send
}
*/
}
?>