Title: Validating disabled fields; pre-set conditional values and fields
Last modified: August 22, 2016

---

# Validating disabled fields; pre-set conditional values and fields

 *  Resolved [p.castaldi](https://wordpress.org/support/users/pcastaldi/)
 * (@pcastaldi)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/validating-disabled-fields-pre-set-conditional-values-and-fields/)
 * Hello there.
 * There are cases in which one may want to disable some fields from user manual
   changes, though considering them valid.
 * For example, you might want to set a certain field (say “MilesAway”) to a certain
   pre-set value (say “100”) when a certain option (say “Chicago”) from a certain
   select (say “City”) is chosen.
 * Then you might want to prevent the pre-set field “MilesAway” to be changed by
   the user. The problem is that the validation function of CF7 returns an error
   for each mandatory pre-set and disabled field when you submit the form.
 * Not knowing how to make it work via php, the only way I found to achieve having
   the information displayed for the user in a disabled-like-style is by adding 
   a span after the “effective” CF7 field, style it as a disabled field, and hiding
   the “effective” CF7 field when a pre-set is loaded via query.
 * You can see it working (with a few other workarounds) at [this link](http://www.il-polistirolo.it/vendita-polistirolo-polistirene/decorazione-architettonica/profili-in-polistirolo-polistirene-espanso-eps/),
   choosing the tab “Richiedi quotazione”, then selecting the value “A catalogo”
   from the select “Tipo prodotto”, and then selecting any value from the select“
   Codice prodotto”.
 * At this point, based on the selected value of “Codice prodotto”, my jquery script
   should (would, hopefully) consequentially set the `.val()` to something and the`.
   prop("disabled", true)` for a couple of fields (namely “Base” and “Altezza”) 
   in order to have “pre-set conditional values” that a user cannot edit but the
   system can manage.
 * But, for the upstated reason of validation fault, I have to work around it via
   jquery ending up in a `<label>` followed by no “effective” field (just a span
   disguised as a field); I believe mine is a non-solution.
 * Does anybody know `an add_filter()` or `add_action()` technique hooking into 
   CF7 to make disabled fields validate?
 * PasteBins for my code:
    [html] [http://pastebin.com/PVaUGtQg](http://pastebin.com/PVaUGtQg)[
   css] [http://pastebin.com/NaTMx8ie](http://pastebin.com/NaTMx8ie) [php] [http://pastebin.com/y6q0XxCL](http://pastebin.com/y6q0XxCL)[
   js] [http://pastebin.com/EtvcvPjn](http://pastebin.com/EtvcvPjn) and [http://pastebin.com/xSLcdUFs](http://pastebin.com/xSLcdUFs)
 * (hopefully, they might be useful for other implementations of conditional fields
   and values via jquery in CF7)
 * Thank you so much in advance!
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [p.castaldi](https://wordpress.org/support/users/pcastaldi/)
 * (@pcastaldi)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/validating-disabled-fields-pre-set-conditional-values-and-fields/#post-5817568)
 * For the solution, [see my post here](https://wordpress.org/support/topic/this-is-how-to-have-simulated-conditional-fields-in-cf7-with-jquery).

Viewing 1 replies (of 1 total)

The topic ‘Validating disabled fields; pre-set conditional values and fields’ 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/)

## Tags

 * [Conditional Fields](https://wordpress.org/support/topic-tag/conditional-fields/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 1 reply
 * 1 participant
 * Last reply from: [p.castaldi](https://wordpress.org/support/users/pcastaldi/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/validating-disabled-fields-pre-set-conditional-values-and-fields/#post-5817568)
 * Status: resolved