• Hi,

    is there a possibility to activate field validation depending on a checkbox? I have created a form with input fields which are only active when a checkbox is checked. Now I want that these fields are mandatory when the checkbox is checked and that they will be mentioned in the error display. When the checkbox is not checked, these fields should be kept out of the validation.

    Is there a way to inject this data into your validation process?

    thx for your help
    dan

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author xnau webdesign

    (@xnau)

    There are three ways this is possible. The first is to use a regex that will accept a blank alternative, so that the field can either be blank or meet the regex pattern.

    That is an easy way to go, but does not force the user to fill in the field, it only forces them to fill it in with a certain kind of information or nothing.

    The rest will require some coding knowledge:

    you can create a custom validation method using the Participants Database API

    you can use a custom template with javascript to conditionally require the field be filled in

    Thread Starter Ghostflasher

    (@ghostflasher)

    Hi,

    thanks for your reply. I checkt the API but don’t understand to use it actually. Do u have an examplecode for “pdb-before_validate_field”?

    best regards
    dan

    Plugin Author xnau webdesign

    (@xnau)

    I posted a tutorial on setting up a custom validation:

    Custom Field Validation

    Thread Starter Ghostflasher

    (@ghostflasher)

    Thank you! I’ll check it out tomorrow morning!

    Thread Starter Ghostflasher

    (@ghostflasher)

    How can I let a fields validation pass, when another field is checked?

    e.g.

    if( $field->name === 'field_a') {
    

    if( $field->value == ‘yes’ ) {

      /* code to set field_b->error_type = 'valid'
    

    }
    `}

    Thread Starter Ghostflasher

    (@ghostflasher)

    sorry, formating got messed up

    Plugin Author xnau webdesign

    (@xnau)

    This is where you would access the $_POST array, it will contain all the values that are getting submitted at that point. You would check that array for the value of the other field.

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

The topic ‘selective form validation’ is closed to new replies.