I have several user forms. There is one group of user fields where I want to know the diet wishes of someone. This field is mentioned in several other user forms. There is one question if the client is allergic. Conditional logic opens een mutli line field asking them what allergic it is. This field needs to be required. I can't make it required in the user fields level because then they will show up in every form where I can't delete them. In the normal mode I haven't any option to make the field required so I have to switch to expert mode. How can I make the field required there? I read that I have to add code to functions.php but is this really neccessary? It feels not right to have to add so much code for only to make something required. Why is this?
Chatgpt says "[cred_field field='user_email' value='' urlparam='user_email' required="required"]: This line makes the email field required.". But I in in doubt if this is the case.
Hello. Thank you for contacting the Toolset support.
Do you mean that you want to set the mutli line field required in one form but not with others - are you using the same field with other forms?
If you can share problem URL of your form on frontend and share admin access details, once I review your current setup I will be able to guide you in the right direction.
*** 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 have set the next reply to private which means only you and I have access to it.
Can you please share information for what form you want to make the field required and what is the field name and share frontend URL of the page where you added the form.
Yes but on frontend where on what page I can see the form? hidden link
===>
Thank you for sharing the above URL but I do not able to see any form on the above URL. Can you please guide me how can I see the form or do I need to login as frontend user? if yes, please share access details for frontend user.
I have set the next reply to private which means only you and I have access to it.
I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link
add_filter('cred_filter_field_before_add_to_form', 'func_set_conditional_required', 10, 1);
function func_set_conditional_required($field){
$form_id = 0;
$form_html_id = $field['form_html_id'];
if ( isset($form_html_id) ) {
$parts = explode( '_', $form_html_id);
$form_id = (int) $parts[2];
}
$field_slugs = array('vul-aan-welke-allergie-je-hebt');
if($form_id==1447 and in_array($field['id'],$field_slugs)){
// in some cases $fields['data'] is an empty string, so you'll need to first set it's expected format for PHP 7.1 compatibility
if (!is_array($field['data'])) {
$field['data'] = array();
}
$field['data']['validate']['required'] = array (
'active' => 1,
'message' => 'This field is required'
) ;
}
return $field;
}
Well - Honestly, I do not have answer for that and I do not know why it's so difficult as I'm not the right person to answer the question you asked, as I'm not the decision maker and do not decide weather features should be added to product or not.
I'm happy to share the solution and glad to know that solution I share help you to resolve your issue.