Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd checkboxs to PHP form
    primarykey
    data
    text
    <p>I have a form which I created using PHP (something I do no understand nearly as much as i'd like) - I made the form using an online tutorial a while back, cannot quite remember where from and can't find it again, however the form works as it should so i'm content.</p> <p>The only thing is, I need to add checkboxes to my form, <strong>they do not need to validate</strong> (if nothing is checked, the form can still be sent, if they are all checked the form can still be sent..)</p> <p>What I do need to happen is for the e-mail that is sent back to me, to let me know which checkboxes were ticked.</p> <p>This is my HTML/PHP page:</p> <pre><code>&lt;!--Contact Form Section --&gt; &lt;div id="contact-form" class="clearfix"&gt; &lt;?php //init variables $cf = array(); $sr = false; if(isset($_SESSION['cf_returndata'])){ $cf = $_SESSION['cf_returndata']; $sr = true; } ?&gt; &lt;form method="post" action="process.php"&gt; &lt;input type="email" id="email" name="email" placeholder="Your e-mail" value=" &lt;?php echo ($sr &amp;&amp; !$cf['form_ok']) ? $cf['posted_form_data']['email'] : '' ?&gt;" required="required" /&gt; &lt;input type="text" id="name" name="name" placeholder="Your name" value="&lt;?php echo ($sr &amp;&amp; !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?&gt;" required="required" /&gt; &lt;textarea id="message" name="message" placeholder="Your message..." required="required" data-minlength="20"&gt;&lt;?php echo ($sr &amp;&amp; !$cf['form_ok']) ? $cf['posted_form_data']['message'] : '' ?&gt;&lt;/textarea&gt; &lt;span id="loading"&gt;&lt;/span&gt; &lt;input type="submit" value="&amp;nbsp;" id="submit-button" /&gt; &lt;ul id="errors" class="&lt;?php echo ($sr &amp;&amp; !$cf['form_ok']) ? 'visible' : ''; ?&gt;"&gt; &lt;li id="info"&gt;There is a problem:&lt;/li&gt; &lt;?php if(isset($cf['errors']) &amp;&amp; count($cf['errors']) &gt; 0) : foreach($cf['errors'] as $error) : ?&gt; &lt;li&gt;&lt;?php echo $error ?&gt;&lt;/li&gt; &lt;?php endforeach; endif; ?&gt; &lt;/ul&gt; &lt;p id="success" class="&lt;?php echo ($sr &amp;&amp; $cf['form_ok']) ? 'visible' : ''; ?&gt;"&gt;Thanks for your message!&lt;/p&gt; &lt;/div&gt; &lt;/form&gt; &lt;?php unset($_SESSION['cf_returndata']); ?&gt; &lt;!--End Contact Form Section --&gt; </code></pre> <p>And here is my process PHP document:</p> <pre><code>&lt;?php if( isset($_POST) ){ //form validation vars $formok = true; $errors = array(); //submission data $ipaddress = $_SERVER['REMOTE_ADDR']; $date = date('d/m/Y'); $time = date('H:i:s'); //form data $name = $_POST['name']; $email = $_POST['email']; $telephone = $_POST['telephone']; $enquiry = $_POST['enquiry']; $message = $_POST['message']; //validate form data //validate name is not empty if(empty($name)){ $formok = false; $errors[] = "You have not entered a name"; } //validate email address is not empty if(empty($email)){ $formok = false; $errors[] = "You have not entered an email address"; //validate email address is valid }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $formok = false; $errors[] = "You have not entered a valid email address"; } //validate message is not empty if(empty($message)){ $formok = false; $errors[] = "You have not entered a message"; } //validate message is greater than 20 characters elseif(strlen($message) &lt; 20){ $formok = false; $errors[] = "Your message must be greater than 20 characters"; } //send email if all is ok if($formok){ $headers = "From: Goldie Locks online contact form" . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $emailbody = "&lt;p&gt;You have received a new message from the enquiries form on your website.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Name: &lt;/strong&gt; {$name} &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Email Address: &lt;/strong&gt; {$email} &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Message: &lt;/strong&gt; {$message} &lt;/p&gt; &lt;p&gt;This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}&lt;/p&gt;"; mail("MY EMAIL!","New Enquiry",$emailbody,$headers); } //what we need to return back to our form $returndata = array( 'posted_form_data' =&gt; array( 'name' =&gt; $name, 'email' =&gt; $email, 'telephone' =&gt; $telephone, 'enquiry' =&gt; $enquiry, 'message' =&gt; $message ), 'form_ok' =&gt; $formok, 'errors' =&gt; $errors ); //if this is not an ajax request if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){ //set session variables session_start(); $_SESSION['cf_returndata'] = $returndata; //redirect back to form header('location: ' . $_SERVER['HTTP_REFERER']); } } </code></pre> <p>As you can see from looking at the html code, I took out some of the functions of the PHP but left them in the PHP process (such as enquiry type and telephone number) because I Was completely unsure what would break what.</p> <p>All I need to do is add check boxes to the html/php document (5 to be precise) and have the ones that are ticked show up in the e-mail I receive when some one fills out the page.</p> <p>Hopefully this is an easy thing for someone with PHP knowledge, but sadly I have very very little. Hope some one can help, if you need any more info please comment and i'll try my best.</p> <p>Thank you </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload