}
// Create a html_button object
- $form = new html_form();
- $form->button->text = $linkname;
+ $form = new single_button($url, $text, 'post');
$form->button->title = $title;
$form->button->id = $id;
- $form->url = $url;
$form->add_class($class);
// Parse the $options string
// Cast $options to array
$options = (array) $options;
- $form = new html_form();
- $form->url = new moodle_url($link, $options);
- $form->button->text = $label;
- $form->button->disabled = $disabled;
- $form->button->title = $tooltip;
- $form->method = $method;
- $form->id = $formid;
+
+ $button = new sibngle_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$id));
if ($jsconfirmmessage) {
- $form->button->add_confirm_action($jsconfirmmessage);
+ $button->button->add_confirm_action($jsconfirmmessage);
}
- $output = $OUTPUT->single_button($form);
+ $output = $OUTPUT->single_button($button);
if ($return) {
return $output;
* @var mixed $url A moodle_url including params or a string
*/
public $url;
- /**
- * @var array $params Optional array of parameters. Ignored if $url instanceof moodle_url
- */
- public $params = array();
/**
* @var boolean $showbutton If true, the submit button will always be shown even if JavaScript is available
*/
public function __construct(array $options = null) {
parent::__construct($options);
$this->button = new html_button();
- $this->button->text = get_string('ok');
+ $this->button->text = get_string('go');
}
/**
throw new coding_exception('A html_form must have a $url value (string or moodle_url).');
}
- if (!($this->url instanceof moodle_url)) {
- $this->url = new moodle_url($this->url, $this->params);
+ if (is_string($this->url)) {
+ $this->url = new moodle_url($this->url);
}
if ($this->method == 'post') {
+ // automatic CSRF protection
$this->url->param('sesskey', sesskey());
}
}
public static function make_button($url, array $params=null, $label=null, $method='post', array $formoptions=null) {
+ //TODO: to be removed soon, repalced by ew single_button()
$form = new html_form($formoptions);
$form->url = new moodle_url($url, $params);
if ($label !== null) {
}
+/**
+ * A component representing a simple form with only one button.
+ *
+ * @copyright 2009 Petr Skoda
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+class single_button extends html_form {
+ /**
+ * Constructor
+ * @param string|moodle_url
+ * @param string $label button text
+ * @param string $method get or post submit method
+ * @param array $options associative array form attributes + {disabled, title}
+ */
+ public function __construct($url, $label, $method='post', array $options=null) {
+ parent::__construct($options);
+ $this->url = $url;
+ $form->method = $method;
+ $this->button->text = $label;
+ if (!empty($options['disabled'])) {
+ $this->button->disabled = true;
+ }
+ if (!empty($options['title'])) {
+ $this->button->title = $options['title'];
+ }
+ }
+}
+
+
/**
* Component representing a list.
*
* Returns a form with single button.
* If first parameter is html_form instance all other parameters are ignored.
*
- * @param string|moodle_url|html_form $url_or_form
+ * @param string|moodle_url|single_button $singlebutton_or_form
* @param string $label button text
* @param string $method get or post submit method
* @param array $options associative array {disabled, title}
* @return string HTML fragment
*/
- public function single_button($url_or_form, $label=null, $method='post', array $options=null) {
- if ($url_or_form instanceof html_form) {
- $form = $url_or_form;
+ public function single_button($singlebutton_or_form, $label=null, $method='post', array $options=null) {
+ if ($singlebutton_or_form instanceof single_button) {
+ $button = $singlebutton_or_form;
if (func_num_args() > 1) {
debugging('html_form instance used as first parameter of $OUTPUT->single_button(), all other parameters are ignored.');
}
} else {
- $form = html_form::make_button($url_or_form, null, $label, $method);
- $form->button->disabled = !empty($options['disabled']);
- if (!empty($options['title'])) {
- $form->button->title = $options['title'];
- }
+ $button = new single_button($url_or_form, $label, $method, $options);
}
- return $this->button($form);
+ return $this->button($button);
}
/**
if ($this->securewindow_required($canpreview)) {
$this->_securewindowrule->print_start_attempt_button($buttontext, $strconfirmstartattempt);
} else {
- $form = html_form::make_button($this->_quizobj->start_attempt_url(), array('cmid' => $this->_quizobj->get_cmid()), $buttontext);
+ $form = new single_button(new moodle_url($this->_quizobj->start_attempt_url(), array('cmid' => $this->_quizobj->get_cmid())), $buttontext);
if ($strconfirmstartattempt) {
$form->button->add_confirm_action($strconfirmstartattempt);
}
*/
public function make_review_link($linktext, $attemptid) {
global $OUTPUT;
- $form = new html_form();
- $form->button->text = $linktext;
- $form->button->title = $form->button->text;
- $form->url = $this->_quizobj->review_url($attemptid);
+ $form = new single_button($this->_quizobj->review_url($attemptid), $linktext);
$form->button->add_action(new popup_action('click', $form->url, 'quizpopup', $this->windowoptions));
return $OUTPUT->single_button($form);
}
'sesskey' => sesskey(),
);
-$form = html_form::make_button($attemptobj->processattempt_url(), $options, get_string('finishattempt', 'quiz'));
+$form = new single_button(new moodle_url($attemptobj->processattempt_url(), $options), get_string('finishattempt', 'quiz'));
$form->id = 'responseform';
$form->button->add_confirm_action(get_string('confirmclose', 'quiz'));