See Release Notes
Long Term Support Release
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Test form repeat elements and delete button 19 * 20 * @copyright 2021 Marina Glancy 21 * @package core_form 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once(__DIR__.'/../../../../../config.php'); 26 27 defined('BEHAT_SITE_RUNNING') || die(); 28 29 global $CFG, $PAGE, $OUTPUT; 30 require_once($CFG->libdir.'/formslib.php'); 31 $PAGE->set_url('/lib/form/tests/behat/fixtures/repeat_with_delete_form.php'); 32 require_login(); 33 $PAGE->set_context(context_system::instance()); 34 35 /** 36 * Class repeat_with_delete_form 37 * 38 * @copyright 2021 Marina Glancy 39 * @package core_form 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 41 */ 42 class repeat_with_delete_form extends moodleform { 43 /** 44 * Form definition 45 */ 46 public function definition() { 47 $mform = $this->_form; 48 $repeatcount = $this->_customdata['repeatcount']; 49 50 $repeat = array(); 51 $repeatopts = array(); 52 53 $repeat[] = $mform->createElement('header', 'testheading', 'Heading {no}'); 54 55 $repeat[] = $mform->createElement('text', 'testtext', 'Test text {no}'); 56 $repeatopts['testtext']['default'] = 'Testing'; 57 $repeatopts['testtext']['type'] = PARAM_TEXT; 58 59 $repeat[] = $mform->createElement('submit', 'deleteel', 'Delete option {no}', [], false); 60 61 $this->repeat_elements($repeat, $repeatcount, $repeatopts, 'test_repeat', 62 'test_repeat_add', 1, 'Add repeats', true, 'deleteel'); 63 64 $this->add_action_buttons(); 65 } 66 } 67 68 $repeatcount = optional_param('test_repeat', 1, PARAM_INT); 69 $form = new repeat_with_delete_form(null, array('repeatcount' => $repeatcount)); 70 71 echo $OUTPUT->header(); 72 if ($data = $form->get_data()) { 73 echo "<pre>".json_encode($data->testtext)."</pre>"; 74 } else { 75 $form->display(); 76 } 77 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body