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';
}
}