Title: HTML select validation
Last modified: January 20, 2020

---

# HTML select validation

 *  Resolved [Sabina](https://wordpress.org/support/users/pessimisticoptimist/)
 * (@pessimisticoptimist)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/html-select-validation/)
 * Hello,
 * I have added an HTML <select> directly to a form so that I could use the <optgroup
   > function to create sorted groups with headings. I have added a ‘required’ attribute
   to the <select> element, and have set a null value to the first option so that
   it acts as a placeholder. Unfortunately the null value isn’t being caught during
   validation and the form submits even if a selection is not made.
 * Would I be able to add custom validation to my functions files to return an error
   code on null submissions for this particular HTML select? I know very little 
   PHP and tried referring to the Developer’s Cookbook but got lost very quickly.
   Would I have to create a custom form tag for it first before I can create a custom
   validation? Any guidance would be greatly appreciated.
 * The code in question is as follows:
 *     ```
       <select required class="wpcf7-select" name="bond-type" id="bond-selection">
           <option value="" selected disabled hidden>- Choose Your Bond -</option>
           <optgroup label="Construction & Service Contracts">
               <option value="Bid Bond">Bid Bond (to bid on a new job)</option>
               <option value="Perf & Pmt">Performance & Payment Bond (for an awarded contract)</option>
               <option value="Maintenance">Stand Alone Maintenance Bond (for a warranty)</option>
               <option value="Supply">Supply Bond (for a supplier)</option>
           </optgroup>
           <optgroup label="Bond Line">
               <option value="Bond Line">Pre-Qualify for Contractors (determine my max limits)</option>
           </optgroup>
           <optgroup label="Commercial/License & Permit/Misc. Bonds">
               <option value="Gen Bus or Permit">General Business License or Permit Bond (not listed otherwise)</option>
               <option value="Auto">Auto/Motor Vehicle Dealer License Bond</option>
               <option value="Freight Broker">BMC-84 Freight Broker Bond (FMCSA compliance)</option>
               <option value="Contractor">Contractor License or Permit Bond</option>
               <option value="Collection">Collection Agency License Bond</option>
               <option value="Health/Gym/Spa">Health Club/Gym/Spa Bond</option>
               <option value="Insurance">Insurance Broker License Bond</option>
               <option value="Lost Title">Lost Title (for a vehicle)</option>
               <option value="Lottery">Lottery Bond</option>
               <option value="Medicare">Medicare/Medicaid Bond (CMS/DMEPOS)</option>
               <option value="Money Transm">Money Transmitter License Bond</option>
               <option value="Mortgage">Mortgage Broker/Banker License Bond</option>
               <option value="Tax">Tax Bonds (alcohol, fuel, tobacco, etc.)</option>
               <option value="Telemarket">Telemarketing/Solicitation License Bond</option>
               <option value="Union">Union Wage & Welfare Bond (union dues)</option>
               <option value="Utility">Utility Bonds (required for utility payments)</option>
           </optgroup>
       </select>
       ```
   
    -  This topic was modified 6 years, 4 months ago by [Sabina](https://wordpress.org/support/users/pessimisticoptimist/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhtml-select-validation%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/html-select-validation/#post-12346634)
 * I suggest creating a custom form-tag first in this case. After that you can implement
   a custom validation more simply.
 * See
    - [Adding A Custom Form-Tag](https://contactform7.com/2015/01/10/adding-a-custom-form-tag/)
    - [Using Values from A Form-Tag](https://contactform7.com/2015/02/27/using-values-from-a-form-tag/)
 *  Thread Starter [Sabina](https://wordpress.org/support/users/pessimisticoptimist/)
 * (@pessimisticoptimist)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/html-select-validation/#post-12359460)
 * That’s what I was afraid of, lol. Unfortunately that’s way, way over my head,
   I tried and failed a few times before reaching out here.
 * I’m all set though, luckily just found a commercially available plugin called
   Quform that has the optgroup functionality I need.
 * Thanks anyway!
    -  This reply was modified 6 years, 4 months ago by [Sabina](https://wordpress.org/support/users/pessimisticoptimist/).
      Reason: spelling

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘HTML select validation’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Sabina](https://wordpress.org/support/users/pessimisticoptimist/)
 * Last activity: [6 years, 4 months ago](https://wordpress.org/support/topic/html-select-validation/#post-12359460)
 * Status: resolved