Home › Toolset Professional Support › [Resolved] add custom message to generic field
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.
This topic contains 1 reply, has 1 voice.
Last updated by Christopher Amirian 3 weeks, 1 day ago.
Assisted by: Christopher Amirian.
Hi,
Welcome to Toolset support. To display a custom error message when the cred_generic_field is left empty, you can achieve this using Toolset's built-in form validation features by leveraging the cred_form_validate hook as a custom code:
Add Validation Hook in custom code:
add_filter('cred_form_validate', 'custom_validate_competition_field', 10, 2); function custom_validate_competition_field($error_fields, $form_data) { // Replace 1234 with your actual CRED form ID if ($form_data['id'] == 1234) { // Check if the custom select field is empty if (empty($_POST['this-competition-id'])) { $error_fields['this-competition-id'] = 'Please select a competition from the list.'; } } return $error_fields; }
- The cred_form_validate filter runs before form submission.
- Replace 1234 with your actual CRED form ID.
- The $_POST['this-competition-id'] checks the field value.
- If empty, the custom error message "Please select a competition from the list." is shown.
Display the Field in Your Form
Modify your form to include an error message placeholder for the field like this:
[cred_generic_field type='select' field='this-competition-id'] { "required":1, "default":[], "options":[{"value":"8132","label":"第五屆全港中樂大賽"}] } [/cred_generic_field] <div class="cred-error-message" style="color: red;">[cred_field field='this-competition-id' error='true']</div>
Thanks.