Notice: Undefined property: stdClass::$addbutton in ...

Notice: Undefined property: stdClass::$addbutton in ...

by Gavin Neale -
Number of replies: 1

Hoping someone with more moodle plugin and forms experience might be able to help me with this. I have a form that when a user presses a submit button I check if it has been pressed and run some code. 


In my _form class I have:

    $mform->addElement('submit', 'addbutton', "Add Period");


in my non_form.php page I then have after submission:

62   if ($mform->is_cancelled()) {

63           echo'Cancel button pressed';

64   } else if ($fromform = $mform->get_data()) {

65           if($fromform->addbutton =="Add Period") { ....


This all works fine but when I turn on moodle debugging I can see the following error and I am wondering if I am doing anything wrong. The error line number corresponds to line 65 above:

Notice: Undefined property: stdClass::$addbutton in /Applications/MAMP/htdocs/moodle/blocks.....


Thanks,

Gavin


Average of ratings: -
In reply to Gavin Neale

Re: Notice: Undefined property: stdClass::$addbutton in ...

by Gavin Neale -

Just looking through some moodle code and I can see that people also use:

     if(isset($fromform->addbutton)) {

this fixed my problem. Hope this is the correct way to do this submission checking.

Gavin