Ok new plan. I’m going to make each have a validator to check post for the value of the Select field and make my own is_required validator. I’ll post code once I get it working for anyone else who it may help.
Hi,
thanks for the 5-star review :).
If you will be having problem with the customization, please post the code snippet you are working on i should be able to help you with that.
Creating a custom is_required validator which would be conditional based on the value selected in the dropdown seems like a good solution.
One other approach you can try is making all fields optional and in adverts_form_load checking the submitted value and if needed making the fields required.
It would be something like this
add_filter( "adverts_form_load", function( $form ) {
if( $form["name"] != "advert" ) {
return $form;
}
if( $_POST['select-to-check'] != 'make-fields-required' ) {
// leave the fields as optional
return $form;
}
$make_required = array( "field_1", "field_2" );
foreach( $form["field"] as $k => $field ) {
if( in_array( $field["name"], $make_required" ) ) {
$form["field"][$k]["is_required"] = true;
$form["field"][$k]["validator"][] = array( "name" => "is_required" );
}
}
return $form;
} );
Where ‘select-to-check’ is actual name of dropdown and ‘make-fields-required’ is actual value which makes fields named “field_1”, “field_2” required, so you would need to adjust the values to your needs.
That’s way better than what I was going to do. Perfect! Sorry, I took so long to respond. I have been working on this major project constantly for a couple of months now. Big help thank you!