Skip Navigation

[Resolved] add the id form in function

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to check multiple form IDs with CRED form validation hook cred_form_validate

Solution:
Basically, you can use OR logical operator in order to check multiple form IDs within the cred_form_validate hook.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/add-the-id-form-in-function/#post-620848

Relevant Documentation:

This support ticket is created 6 years, 10 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by massimoS527 6 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#620825

I have this piece of code of a function

//validate if specific form
    if ($form_data['id']==348) 
 

and I need to add other modules id, I tried like this:

    if ($form_data['id']==348,349) 
 

it gives me an error

#620841

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - its easy. You should try the following line of code:

if ($form_data['id']==348 or  $form_data['id']==349) 
#620847

it gives me an error:

syntax error, unexpected 'or' (T_LOGICAL_OR)

here is the complete code:

add_filter('cred_form_validate','func_validate_taxonomy_select',10,2);
function func_validate_taxonomy_select($error_fields, $form_data)
{
    //field data are field values and errors
    list($fields,$errors)=$error_fields;
 
    //validate if specific form
    if ($form_data['id']==348) or $form_data['id']==349) 
    {
        //check my_field value
        if ($fields['creatura-sesso']['value'][0] == '0')
        {
            //set error message for my_field
            $errors['creatura-sesso']='fai una scelta';
        }
           
         //check my_field value
        if ($fields['creatura-specie']['value'][0] == '0')
        {
            //set error message for my_field
            $errors['creatura-specie']='fai una scelta';
        }
           
         //check my_field value
        if ($fields['creatura-vita-assieme']['value'][0] == '0')
        {
            //set error message for my_field
            $errors['creatura-vita-assieme']='fai una scelta';
        }
           
          }
    //return result
    return array($fields,$errors);
}
 
#620848

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I dont know why it's throwing syntax error.

could you please make sure that if condition brackets are properly open and closed.

For example:

if ($form_data['id']==348  || $form_data['id']==349) {

// your code goes here

}

#620869

solution

if ($form_data['id']==348 or  $form_data['id']==349)