Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Do not email form fields that are left blank
    text
    copied!<p>Currently I am making an online enquiry form with a set of fields that are non-mandatory. </p> <p>If a non-mandatory form field is not filled-in out, I would like to make it so that it doesn't come through in the processed email.</p> <p>For instance; if someone does not enter their telephone number, the "Telephone: $atelephone" component does not come through. </p> <pre><code>if ($atelephone != '') { echo "Telephone: ".$atelephone; } </code></pre> <p>I figure the code should have something like above put in it, though I am struggling to connect the dots. Any help would be greatly appreciated. (I hope this makes sense).</p> <pre><code>&lt;?php // Base form items $asender = $HTTP_POST_VARS['name'] ." &lt;". $HTTP_POST_VARS['email'] ."&gt;"; $asubject = "Email Enquiry: ".$HTTP_POST_VARS['subject']; $arecipient = "recipient@websiteaddress.com.au"; /*******************************************************/ // Mail form variables // $aname = $HTTP_POST_VARS['name']; $aemail = $HTTP_POST_VARS['email']; $atelephone = $HTTP_POST_VARS['telephone']; $asuburb = $HTTP_POST_VARS['suburb']; $aenquiry = $HTTP_POST_VARS['enquiry']; mail("$arecipient","$asubject", " =========================================== Please note: this is an email generated from the Website. =========================================== Name: $aname Email: $aemail Telephone: $atelephone Suburb: $asuburb Message: $aenquiry ================================ ","FROM:$asender"); header('Location: /thank-you.php'); ?&gt; </code></pre>
 

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