Hi @sistunix
Thanks for additional explanation!
Since plugin doesn’t know if selected date is “today” or not, your idea with additional hidden fields is actually a good shot but then – we still need another additional field and custom code as plugin cannot compare two fields in conditions; it can only compare field against defined values.
But all in all, with additional fields, conditions configurations and custom code, I believe it should be doable. Here is how:
1. Add a “hidden-1” field to the form and set its “Default value (optional)” to “Date”. Make sure that the date format there is exactly the same as date format set in your datepicker field – this is critically important!
2. Add a “hidden-2” field to the form and set its “Default value (optional)” to “Custom value”, then set that value to 0.
3. Now you want to add following custom code to the site:
<?php
add_filter( 'forminator_prepared_data', 'wpmudev_update_hidden_field_custom', 10, 2 );
function wpmudev_update_hidden_field_custom( $prepared_data, $module_object ) {
$form_ids = array(3010); // Please change the form ID.
if ( ! in_array( $module_object->id, $form_ids ) ) {
return $prepared_data;
}
$date = $prepared_data['hidden-1'];
$datediff = $prepared_data['date-1'];
if ( $date == $datediff ) {
$prepared_data['hidden-2'] = 1;
}
return $prepared_data;
}
add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_change_hidden_field_custom', 10, 3 );
function wpmudev_change_hidden_field_custom( $entry, $module_id, $field_data_array ) {
$form_ids = array(3010); // Please change the form ID.
if ( !in_array( $module_id, $form_ids ) ) {
return;
}
foreach ( $field_data_array as $key => $value ) {
if ( strpos( $value['name'], 'hidden-2' ) !== false ) {
Forminator_CForm_Front_Action::$info['field_data_array'][$key]['value'] = sanitize_text_field( Forminator_CForm_Front_Action::$prepared_data['hidden-2'] );
}
}
}
a) create an empty file with a .php extension (e.g. “forminator-date-compare.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install on server
b) copy and paste code into it
c) in both these lines in code (there are two of them!)
$form_ids = array(3010); // Please change the form ID.
replace number 3010 with the ID of your form; form ID is the number you see in the form shortcode
d) in this line you may need to adjust your datepicker field ID if it’s different than “date-1”:
$datediff = $prepared_data['date-1'];
But I’m assuming that it’s “date-1” and both hidden fields are accordingly “hidden-1” and “hidden-2” and set as explained in points 1 and 2 above.
e) save the file.
At this point depending on if the date chosen is “today” or other date, the “hidden-2” field value saved will either be 0 (different date) or 1 (today) and we can use it for redirects.
4. In form’s “behavior” settings in “Submission” behavior:
a) add one “Redirect user to URL” behavior
– set URL user should be taken to if the date is NOT today
– set rule to “Process behavior if All of the conditions below match”
– and add condition: “Hidden-2 is not 1”
b) add another “redirect user to URL” behavior
– set URL user should be taken to if the date IS today
– set rule to “Process behavior if All of the conditions below match”
– and add condition: “Hidden-2 is 1”
Note: there should only be these two redirects/submission behaviors set. If you have more, you need to set other conditions for them so there would never be “clash” where two are processed at the same time. I hope that makes sense.
At this point:
– if user select “today” date from datepicker – they’d be redirected to one URL after submission
– and if they select different date (than today) from datepicker – they’d be redirected to a different URL after submission.
—-
Now if you also want that “today” redirect to only happen if it’s before 7 AM you should be able to simply set additional condition for the redirect based on yet another hidden field; such hidden field should be set to include “submission time” – but there should be no need for additional custom code since time is predefined (you just set condition like “is less” or “does not contain”).
Best regards,
Adam