Skip Navigation

[Resolved] CRED Validation hook

This support ticket is created 9 years 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by tamasN 9 years ago.

Assigned support staff: Luo Yang.

Author
Posts
#240372

Hello!
I have the following problem with CRED validation hook:
1. I placed the following code to functions.php (found in the plugin documentation):

add_filter('cred_form_validate','my_validation',10,2);
function my_validation($field_data, $form_data)
{
// field data are field values and errors
 
list($fields,$errors)=$field_data;
 
// print the field values
 
print_r($fields);
 
// validate if specific form
 
if ($form_data['id']==5020)
 
if ($fields['username']['value']!='correct_value')
 
// set error message per field
 
$errors['username']='Wrong Value';
  
// return result
 
return array($fields,$errors);
}

2. I made a cred form, with one filed, called 'username'

3. wp-config.php -> DEBUG true

4. I got the following error message in blank browser page, after submit form:

Array ( [username] => Array ( [value] => ergewfdsg [name] => username [type] => textfield [repetitive] => 0 [validation] => Array ( [required] => Array ( [active] => 1 [value] => 1 [message] => This field is required ) ) ) [form_submit_1] => Array ( [value] => Submit [name] => form_submit_1 [type] => submit [repetitive] => ) [_cred_cred_wpnonce] => Array ( [value] => 6e0523580d [name] => _cred_cred_wpnonce [type] => hidden [repetitive] => ) [_cred_cred_prefix_post_id] => Array ( [value] => 5114 [name] => _cred_cred_prefix_post_id [type] => hidden [repetitive] => ) [_cred_cred_prefix_form_id] => Array ( [value] => 5020 [name] => _cred_cred_prefix_form_id [type] => hidden [repetitive] => ) [_cred_cred_prefix_form_count] => Array ( [value] => 1 [name] => _cred_cred_prefix_form_count [type] => hidden [repetitive] => ) )
Notice: Undefined index: cred_form_5020_1_username in ..\wp-content\plugins\cred-frontend-editor\classes\Form_Builder.php on line 965

Fatal error: Call to a member function addError() on a non-object in ..\wp-content\plugins\cred-frontend-editor\classes\Form_Builder.php on line 965

I couldn't debug this error.

Thank You,
Tamás

#240473

Hi Tamás,

There is a known bug in current version of CRED, I am sending a development version of CRED with bug fix, please try and feedback if the problem is fixed.

#240650

Now it works fine!
Thank you!