Hi there
I'd like to ensure ALL fields when added to forms are required. Tried adding a 'checked="yes"' to the input type declaration but didn't seem to do it.
Any ideas?
Hi there
I'd like to ensure ALL fields when added to forms are required. Tried adding a 'checked="yes"' to the input type declaration but didn't seem to do it.
Any ideas?
Rather than having to mark each field required when creating a new form, you want the default to be required for all fields you add. Is that correct? That way the default for a form would be all fields required rather than no fields required.
Correct! All added fields should be 'required' as default.
I am checking with the developers to see if there is a filter you can use to make this happen. I'll post when I find out. Thanks for your patience.
Alex provided the following code:
[php]
add_filter("gform_pre_render", "set_required");
add_filter("gform_validation", "check_required");
function set_required($form){
foreach($form["fields"] as &$field)
$field["isRequired"] = true;
return $form;
}
function check_required($validation_result){
foreach($validation_result["form"]["fields"] as &$field){
if(GFFormDisplay::is_empty($field, $validation_result["form"]["id"])){
$field["failed_validation"] = true;
$field["validation_message"] = "This field is required.";
$validation_result["is_valid"] = false;
}
}
return $validation_result;
One side effect of doing it this way is that the form builder will NOT show that fields are required (because they're not at that point.) They are made required when the form is displayed to a visitor.
There are two functions, two filters there. The set_required function will make each field required before the form is rendered. The check_required handles the validation upon submit.
Let me know if you need any assistance implementing this. This code will be added to your functions.php file in your current theme.
http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F