Skip Navigation

[Resolved] Display fields errors in Form Error Message

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Christian Cox 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1503725
Capture.PNG

Hi
I am trying to display error message of each fields in Form's Error message. Currently it only shows number of fields with error. For example I left 10 fields blank which were required. So Form's default error message would be "The post was not saved because of the following 10 problems:". But I want to list the fields names or field's short names there in the error message so that It can help user to understand the error message and help to go to targeted fields with error and correct the error.

So Please let me know how to fix it.

#1503909
Screen Shot 2020-02-11 at 1.58.51 PM.png

Hi, for front-end validation of required fields there's not an easy way to extend this error message. However, for backend validation using the cred_form_validate API, you can add your own custom error message to display for each field. For example, here is some backend validation code:

add_filter( 'cred_form_validate', 'tssupp_form_validation', 10, 2 );
function tssupp_form_validation( $data, $form_data ) {
  $forms = array( 12345 );
  if( in_array( $form_data['id'], $forms ) ){
    list($fields,$errors)=$data;
    $errors['book-date'] = __('Too old', 'your-language-domain');
    $data =array($fields,$errors);
  }
  return $data;
}

You can see the error message returned here in the screenshot.

If you would like to add custom messages to the front-end validation script, I encourage you to submit your suggestion here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
That will let our team know the feature is important for your site.

#1504065

This is been really annoying experience with Toolset and its addons, especially form. Because there are so many important features missing, and to make things work well, There is no proper solution that can make it work smoothly.

So will you mind what would be a complicated way to make it work for frontend form?

#1504139

Making Fields Required in A Frontend Post form:<br>
I am really getting mad because of worst quality form functionalities which only claims to provide best features for non-techy users on Landing page, but really is just against it.

I have been struggling to make my form fields required in the frontend form, But these are not working and if I make all the fields required in the custom fields then If any field is conditionally hidden (Which is a required field) then form doesn't get submitted which is ridiculous. I am not expert enough in Javascript so that I can apply a large validation code to validate every single conditionally visible field and get this work done. So its completely a super messy system which is now only wasting my time and nothing else.

#1505223

Here is an API example that shows how to make a form field required with backend validation:

add_filter('cred_filter_field_before_add_to_form', 'required_user_fields_func', 10, 2);
function required_user_fields_func($field, $computed_values){
  if(in_array($field['id'], array('single-cb1'))){
    $field['data'] = is_array($field['data']) ? $field['data'] : array();
    $field['data']['validate']['required'] = array (
      'active' => 1,
      'value' => 1,
      'message' => 'This field is required'
    );
  }
  return $field;
}

You asked how to achieve validation on the front-end, but I don't have a good answer for that. There is no JavaScript API for Forms, so I don't have a code example to share. I only have backend validation APIs, so I have shared an example for requiring a custom field here. If you're having trouble implementing this API, or it doesn't seem to work for a specific field, please show me which field you are trying to validate and I can provide a working code sample.