I have a single line repeating field with slug voyage-vessel. This field is populated through a CRED Generic Field that has dynamically generated options (code below).
<div class="form-group">
<label>Which Vessel/s is this Voyage Available on?<span style="color: red;">*</span></label>
<div class="checkbox-scroll-area">
<p>Scroll for more...</p>
[cred_generic_field field='voyage-vessel' type='checkboxes' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="dynamically-generated-list-of-vessels"] ]
}
[/cred_generic_field]
</div>
</div>
I am trying to make this field required.
I have tried changing the required value in the above code to 1 but this did not work.
I have also tried validating using php as below...
// CRED Forms - Voyage Taxonomies Required
add_filter('cred_form_validate', 'cred_voyage_taxonomies_required',10,2);
function cred_voyage_taxonomies_required($field_data, $form_data)
{
list($fields,$errors)=$field_data;
$forms = [ 90, 110 ];
// if a specific form
if ( in_array( $form_data['id'], $forms ) )
{
if ( empty($fields['sailing-regions']['value'][0]) )
{
$errors['sailing-regions']='Please specify the sailing region/s this series takes place in.';
}
if ( empty($fields['embarkation-country']['value'][0]) )
{
$errors['embarkation-country']='Please specify the embarkation country.';
}
if ( empty($fields['disembarkation-country']['value'][0]) )
{
$errors['disembarkation-country']='Please specify the disembarkation country.';
}
if ( empty($fields['voyage-categories']['value'][0]) )
{
$errors['voyage-categories']='Please specify at least 1 voyage category.';
}
if (empty($fields['wpcf-voyage-vessel']['value'][0]))
{
$errors['voyage-vessel'] = 'Please select at least 1 vessel.';
}
if ( empty($fields['wpcf-secondary-title']['value']) )
{
$errors['wpcf-secondary-title']='Please specify the voyage name.';
}
}
return array($fields,$errors);
}
Everything except voyage-vessel validation works using the above code.
I have also tried using the following variations to validate voyage-vessel but they do not work either...
if ( $fields['wpcf-voyage-vessel']['value'] == '' )
{
$errors['voyage-vessel'] = 'Please select at least 1 vessel.';
}
if (empty($fields['wpcf-voyage-vessel']['value'][0]))
{
$errors['voyage-vessel'] = 'Please select at least 1 vessel.';
}
if (empty($fields['wpcf-voyage-vessel']['value']))
{
$errors['voyage-vessel'] = 'Please select at least 1 vessel.';
}
Please can you advise on how to make this field required?
could you please share problem URL where you added the CRED form and access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.