Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can add checkboxes to the form by simply adding a checkbox input element:</p> <pre><code>&lt;input type="checkbox" name"myCheckbox" value="true" /&gt; </code></pre> <p>set the <code>value=""</code> to whatever you want. You can then pick up the <code>value</code> in your PHP script using:</p> <pre><code>$myCheckbox = $_POST['myCheckbox']; </code></pre> <p>The variable <code>$myCheckbox</code> will then contain the value of the checkbox with name 'myCheckbox' in the form if it was checked, or it'll be blank if the checkbox was not checked.</p> <p>You can then add the value to the email as you have with the other variables, i.e.</p> <pre><code>$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;&lt;strong&gt;myCheckbox value: &lt;/strong&gt; {$myCheckbox}&lt;/p&gt; &lt;p&gt;This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}&lt;/p&gt;"; </code></pre> <p>If you wanted to keep the checked / not checked status on the form if it's submitted and fails validation for whatever reason, then you can add the checkbox value to the <code>$returndata</code> variable:</p> <pre><code>$returndata = array( 'posted_form_data' =&gt; array( 'name' =&gt; $name, 'email' =&gt; $email, 'telephone' =&gt; $telephone, 'enquiry' =&gt; $enquiry, 'message' =&gt; $message, 'myCheckbox' =&gt; $myCheckbox, ), 'form_ok' =&gt; $formok, 'errors' =&gt; $errors ); </code></pre> <p>This will send it back to the form and then you need to alter the checkbox to look for this value as the other elements do, and add a value of 'checked=Checked"' to the checkbox if it was previously checked:</p> <pre><code>&lt;input type="checkbox" name"myCheckbox" value="true" &lt;?php echo ($sr &amp;&amp; !$cf['form_ok'] &amp;&amp; $cf['posted_form_data']['myCheckbox]=="true") ? 'checked="checked"' : '' ?&gt; /&gt; </code></pre> <p>where the <code>true</code> part of the line <code>$cf['posted_form_data']['myCheckbox]=="true"</code> is the <code>value=""</code> value of the checkbox.</p> <p>I hope that makes sense.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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