General developer forum

Send processed form data to a new page that displays results

 
Picture of Seaim Khan
Send processed form data to a new page that displays results
 

I'm currently creating an Advanced Search for my site. I have three files; advanced.php, advanced_form.php, and results.php.

I define the form on advanced_form.php and process the data on advanced.php after it is submitted, as such:


$mform = new advanced_form(new moodle_url('/blocks/frontpagesearch/results.php'), null, 'get');
if ($mform->is_cancelled()) {
redirect(new moodle_url('/my/'));
} elseif ($mform->is_submitted()) {
// Data processed here and sent to new page
// Do something with $mform->get_data()->foo
} else { echo $OUTPUT->header(); echo $OUTPUT->heading($pagetitle); $mform->display(); echo $OUTPUT->footer(); }


I tried various methods to send the processed data to the next page. However, when I try to access the GET variable on results.php, not only am I missing the data I processed, but some of the data is different from the original data found in $mform->get_data(). Example, I have a date_selector field that returns a UNIX timestamp in get_data(), but in results.php, I get an array with day, month, and year.


I am at a loss on how exactly I should approach this and any help would be appreciated. If you need me to clarify on anything, just let me know. Thank you

 
Average of ratings: -
Davo
Re: Send processed form data to a new page that displays results
Core developersParticularly helpful MoodlersPlugin developers

Unless you really have a good reason to do this, the more usual way of using forms is to leave the form to submit to the current page. That way, any validation errors can be displayed on the original form, before the data is processed.

 
Average of ratings: -