• Resolved p.castaldi

    (@pcastaldi)


    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, 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
    [css] http://pastebin.com/NaTMx8ie
    [php] http://pastebin.com/y6q0XxCL
    [js] http://pastebin.com/EtvcvPjn and 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://ww.wp.xz.cn/plugins/contact-form-7/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Validating disabled fields; pre-set conditional values and fields’ is closed to new replies.