This support ticket is created 5 years, 4 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I am trying to:
I created some "Add Custom Post Forms" with these options >> Are you interested to: 1) BUY / 2) SELL. I need the customer to be forced to click on one of them (buy or sell, not both - just one) and I don't know how to make the selection required.
From your support forum I tried this function:
function my_validation($field_data, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$field_data;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==25559)
{
//check if field is selected
if (empty($fields['wpcf-type_of_proposal']['value']))
{
//set error message for featured image
$errors['wpcf-type_of_proposal'] = 'Please Specify if you are looking to Buy or Sell';
}
}
//return result
return array($fields,$errors);
}
This works only with one form. When I try to create a similar function for other forms (with other ID's) it does not work.
I need the user to check only one of those two fields (image attached), I need the selection to be required.
For you to see that page you must create a free account.
That is what I'm telling you. I created that function and it only works with one form (the form with the ID 25621). How can I make that function to work on multiple forms?
When I try to save the functions file I get this message:
"
Changes you made to the PHP code have been canceled due to an error on line 227 of the wp-content / themes / kleo-child / functions.php file. Please correct and try saving again.
syntax error, unexpected 'if' (T_IF)
"
This is what I have now:
function my_validation($field_data, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$field_data;
//uncomment this if you want to print the field values
//print_r($fields);
$form_ids = array(25559,25621,25640)
//validate if specific form
if (in_array($form_data['id'],$form_ids))
{
//check if field is selected
if (empty($fields['wpcf-type_of_proposal']['value']))
{
//set error message for featured image
$errors['wpcf-type_of_proposal'] = 'Please Specify if you are looking to Buy or Sell';
}
}