• Resolved chiucs123

    (@chiucs123)


    Hi all,

    Would like a little help on using wpforms_process() to assign error message to a field with type name. A name typed field includes 3 possible subfields including first, middle and last. I find the error message only gets to highlight the last name part as there is no way of specifying which subfield to highlight. It doesn’t allow assigning to only the first name.

    The way the error message is assigned is:
    wpforms()->process->errors[$form_id][$field_id] = esc_html__('message', 'wpforms');

    A sample public form response ajax submission returns:
    {"success":false,"data":{"errors":{"general":{"header":""},"field":{"wpforms[fields][0][last]":"message"}}}}

    Any help would be appreciated. Thanks.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @chiucs123,

    In this case, instead of:
    wpforms()->process->errors[$form_id][$field_id] = esc_html__('message', 'wpforms');

    You can add the error on the top of the form like this:
    wpforms()->process->errors[ $form_data['id'] ]['header'] = esc_html__('message', 'wpforms');

    Just like the sample code here to validate the name field.

    Also, further customization on this code is outside our support scope here.

    Hope this helps!

    Hi @chiucs123,

    We haven’t heard back from you in about a week, so I’m going to go ahead and close this thread for now. But if you’d like us to assist further, please feel welcome to continue the conversation.

    Thanks!

    Thread Starter chiucs123

    (@chiucs123)

    Hi @niksebastian,

    Thank you for your suggestion.

    For our use case, we would like to alert the user on more than one matter, to assist our users better, we want to display the error message right next to the spot where they need to take action, hence we do not want to place it on the header.

    Is native support for that subfield available, rather than placing the error message somewhere potentially unrelated?

    We understand code customization is beyond the scope, so we would like to see if there is an appropriate setting to achieve this before heading to custom code this part. We prefer the official/suggested way for sustainability considerations.

    Best regards,
    Jason

    • This reply was modified 2 years, 8 months ago by chiucs123.

    Hi @chiucs123,

    Thank you for your patience here!

    Please know that we currently do not have an inbuilt feature to achieve what you have mentioned. I have gone ahead and marked your vote to consider this as a feature request.

    For further customization, you can make use of the wpforms_wp_footer_end action and add the validation to be displayed instantly. Here is an example of the dev doc

    Hope this helps! 🙂

    Hi @chiucs123,

    Just a heads up– We haven’t heard back from you in about a week, so I’m going to go ahead and close this thread for now. But if you’d like us to assist further, please feel welcome to continue the conversation.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to assign error messages via wpforms_process’ is closed to new replies.