Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any way possible to apply form requirements to a drop down field in a PHP contact form?
    primarykey
    data
    text
    <p>I would like to create a requirement that if nothing is selected from a drop down field in my contact form that a message will come up saying "Please choose", and the form will not be able to be submitted unless something is chosen. I have gotten requirements to work on all of my text input forms, but cannot figure out how to create one for the drop down field. </p> <p>The drop down HTML looks like this:</p> <pre><code>&lt;div class='container'&gt; &lt;label for='destemail' &gt; Which department are you trying to reach?*&lt;/br&gt; You must select a department.&lt;/label&gt;&lt;/br&gt; &lt;select name="destemail" id="destemail"&gt; &lt;?php foreach ($emailAddresses as $name =&gt; $email) { ?&gt; &lt;option value="&lt;?php echo htmlspecialchars($name); ?&gt;"&gt;&lt;?php echo htmlspecialchars($name) ; ?&gt;&lt;/option&gt; &lt;?php } ?&gt;&lt;/select&gt; &lt;span id='contactus_destemail_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; </code></pre> <p>I got the other form requirements to work like so:</p> <p>The HTML -</p> <pre><code>&lt;div class='container'&gt; &lt;label for='name' &gt;Your Full Name*: &lt;/label&gt;&lt;br/&gt; &lt;input type='text' name='name' id='name' value='&lt;?php echo $formproc-&gt;SafeDisplay('name') ?&gt;' maxlength="50" /&gt;&lt;br/&gt; &lt;span id='contactus_name_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; </code></pre> <p>The Javascript -</p> <pre><code>&lt;script type='text/javascript'&gt; &lt;![CDATA[ var frmvalidator = new Validator("contactus"); frmvalidator.EnableOnPageErrorDisplay(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); &lt;/script&gt; </code></pre> <p>The PHP -</p> <pre><code>//name validations if(empty($_POST['name'])) { $this-&gt;add_error("Please provide your name"); $ret = false; } </code></pre> <p>I tried the exact same coding for the drop down but with the different id names where appropriate, and it didn't work. Why doesn't this same method work for the drop down?</p> <p>Help much appreciated!</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. 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