Set value if field empty (unanswered) at submit?

Home Forums Quform WordPress Set value if field empty (unanswered) at submit?

This topic is: resolved
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #26374
    katw
    Participant

    I have a radio button field called “status” with multiple options.

    This is not required, and “Validate submitted value” is enabled.

    On submit, if the field is empty I want to populate the field with a value.

    Is this possible?

    I didn’t want use the default value option as I didn’t want to influence the users answer.

    As no answer is an answer in itself.

    The value I want to set (if field empty) is coincidentally one of the option values.

    #26459
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #26479
    katw
    Participant

    Does the

    post_set_form_values

    hook run after the form has successfully passed validation?

    So I can trust the data within the field?

    Thanks

    #26482
    katw
    Participant

    Question 2.

    I assume QuForm doesn’t validate the value you assign to the field?

    OR

    Does it still honour the “Validate submitted value” setting on the form field advanced settings?

    If YES = still checked THEN {

    Can this new value be added to the option value array?

    So that the change is accepted AND EditEntry mode now shows the expanded set of radio button options for editing the entry?

    }

    If NO = not checked THEN {

    What happens with Edit Entry mode?

    Will a new radio button option be added to the existing set and be selected?

    }

    WHY? I may like to add a new option value to the values defined to make it stand out as a “non answer”.

    #26486
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #26497
    katw
    Participant

    I have confirmed from testing the post_set_form_values hook is subject to validation.

    So setting a field value outside those options prescribed will result in an error “Not a valid value” on submit.

    So this hook requires one of the values prescribed if “Validate submitted value” is active in field options.

    I will experiment with your suggestions. Thanks Ally

    Question 3:

    What does the parameter 'id' => 0 do in your addOptions() function?

    Does it define position order? Is it a unique id reference?

    I had a quick look at the function reference in Multi.php but couldn’t see how ID was applied there.

    • This reply was modified 6 years, 9 months ago by katw. Reason: Add followup query
    #26499
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #26503
    katw
    Participant

    Thanks good to know.

    What happens if you are adding multiples? Is the ID treated as a string?

    So you could use “00”, “000” for any extra options you want to create?

    Or would it be better to assert an ID in high number range?

    #26504
    katw
    Participant

    I re-activated “Validate submitted value” on the radio group field AND added your function to change the $validator:

    add_filter('quform_entry_pre_process_1', function (array $result, Quform_Form $form) {
        $propstatus = $form->getElement('quform_1_31');//property status radio group
    
        if ($propstatus) {
            $validator = $propstatus->getValidator('inArray');
    
            if ($validator) {
                $haystack = $validator->config('haystack');
                $haystack[] = 'Query';// <---- NEW VALUE as set in quform_post_set_form_values_1(function)
                $validator->setConfig('haystack', $haystack);
            }
        }
    
        return $result;
    }, 10, 2);

    On submit I get the validation fail, outside range notice "This value is not valid"

    The quform_entry_pre_process_X hook isn’t executed.

    BTW I changed your “InArray” string to “inArray”. May be semantics or may be important ?

    Note I am using the quform_post_set_form_values hook to set the out-of-range option value.

    • This reply was modified 6 years, 9 months ago by katw. Reason: Added debugging info
    • This reply was modified 6 years, 9 months ago by katw. Reason: Added more debugging info for consideration
    #26509
    katw
    Participant

    On further investigation the wrong hook is being used to coerce the validator a submit.

    BEFORE: quform_entry_pre_process_#.

    This is not run at form submission/processing but used with edit entry form.

    AFTER: Changing the hook to quform_pre_process_# solved the issue and allowed the form to be submitted with an option value outside prescribed range.

    Am I correct I need to repeat this code and process, this time using the hook you gave
    quform_entry_pre_process_# for entries to be editable when value is outside range?

    • This reply was modified 6 years, 9 months ago by katw. Reason: Solution and query on edit view
    #26544
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #26548
    katw
    Participant

    Yes thanks. All good. Close ticket

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy