Im using form_alter on a views exposed filter form. There are 2 date fields (start-date and end-date) which are exposed filters that Ive hidden from the user. I want to populate the url argument of these 2 fields when the form is submitted.
Ive tried both methods using a submit and validation callback but neither seems to work.
My form_alter is:
function mymodule_form_views_exposed_form_alter(&$form,
FormStateInterface $form_state, $form_id) {
if ($form['#id'] == 'views-exposed-form-my-form-id') {
...
...
$form['#submit'][] = '_my_custom_submit';
$form['#validate'][] = '_my_custom_validate';
}
My callback looks like:
function _my_custom_validate($form, FormStateInterface $form_state) {
// Pass date range selection to date fields.
$date_range = $form_state->getValue('date-range');
$date_range_split = explode(":", $date_range, 2);
$start_date = $date_range_split[0];
$end_date = $date_range_split[1];
$form_state->setValue('start-date', $start_date);
$form_state->setValue('end-date', $end_date);
$input = &$form_state->getUserInput();
$input['start-date'] = $start_date;
$input['end-date'] = $start_date;
$form_state->setUserInput($input);
}
When I dpm() any of my vars above I see the data but I can not get it passed into the url's arg on submit so I keep getting http://domain.com&start-date=&end-date=
How can I populate/modify the url args after the user clicks submit but before the page reloads?
If theres any other info that I can provide that may be helpful, please let me know.
Thanks!