1

I have a page in my moodle block which has some parameters passed in the url.This is what it looks like: http://localhost/blocks/learning_strategizer/viewlp.php?lp_id=1-2

This page(viewlp.php) is calling a form with parameters from lp_id:

$customdata=array(substr($lp_id,2));
$form = new viewlpstudent_form(null,$customdata);

This form is pulling out data based on the lp_id and taking in user choices. It has an action button obviously in the end. When I click the action button, I need to fetch the user choices from the form as well as the URL parameter that I sent to the form (substr($lp_id,2))

But problem is: when I click the action button the parameter is lost and becoming null. Is there anyway to fix this.

Amrita Deb
  • 165
  • 1
  • 3
  • 15

1 Answers1

0

You need to create a hidden field in the form that will contain the lp_id parameter. So inside the definition method of the form add the following:

$_form->addElement('hidden', 'lp_id', $this->_customdata['lp_id']);
$_form->setType('lp_id', PARAM_INT); // or choose another PARAM_XXX type if not integer

And $customdata array should be associative to be able to properly get the parameter:

$customdata = array('lp_id' => substr($lp_id,2));
$form = new viewlpstudent_form(null, $customdata);
  • Thanks for your answer. But this alone doesnt work since on submission when the page gets refreshed $lp_id was getting null. One has to also add the below to set the value in the form : `$mform->setDefault('lp_id', $this->_customdata[0]);` – Amrita Deb Dec 05 '19 at 13:55