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: -
Picture of Amir Mustafa
Re: Send processed form data to a new page that displays results
 

Hello,

Did you success in sending data to the next page. I am facing similar issue. My current page contains lots of parameters and on form submit all the parameters are lost. Therefore not able to receive data.

Can you please guide me how to send data to the next page.

M CODE:
/* Class :Start */
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir.'/completionlib.php');
require_once($CFG->libdir. '/coursecatlib.php');

class traininginfo_form extends moodleform {

function definition () {
            $mform =$this->_form;
            $mform->addElement('header', 'descriptionhdr', 'Notes');
    $mform->setExpanded('descriptionhdr');

        
       $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
$mform->addHelpButton('shortname', 'shortnamecourse');
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_TEXT);


$this->add_action_buttons(false, 'submit');
        }
    }

    $ti_form = new traininginfo_form('gradeform.php');    // how to receive data in this new page
    /* if ($ti_form->is_cancelled()) {
        echo '<h1>not received</h1>';
        // Redirect to somewhere if the user clicks cancel
    }

    if ($data = $ti_form->get_data()) {
        echo '<h1>data received</h1>';
        // Do something with the data, then redirect to a new page
    } */

    // You should really output the page header before this
    $ti_form->display();

Thank you for your help in advance.

 
Average of ratings: -
Picture of Amir Mustafa
Re: Send processed form data to a new page that displays results
 

Hello,

I succeeded, it was basic $_REQUEST data;

when we use 

echo '<pre>'; print_r($_REQUEST); in the target page it shows all the data.

Happy me smile

 
Average of ratings: -