Commit 5292fa22 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add onclick,onsubmit,id attributes; add form name to class of form

elements.
parent 31378080
......@@ -130,6 +130,13 @@ class Form {
*/
private $action = '';
/**
* The javascript function that the form will be submitted to.
*
* @var string
*/
private $onsubmit = '';
/**
* The tab index for this particular form.
*
......@@ -202,6 +209,7 @@ class Form {
$form_defaults = array(
'method' => 'post',
'action' => '',
'onsubmit' => '',
'elements' => array()
);
$data = array_merge($form_defaults, $data);
......@@ -212,8 +220,8 @@ class Form {
$data['method'] = 'get';
}
$this->method = $data['method'];
$this->action = $data['action'];
$this->onsubmit = $data['onsubmit'];
if (isset($data['tabindex'])) {
$this->tabindex = intval($data['tabindex']);
......@@ -364,9 +372,10 @@ class Form {
*/
public function build() {
$result = '<form';
foreach (array('name', 'method', 'action') as $attribute) {
foreach (array('name', 'method', 'action', 'onsubmit') as $attribute) {
$result .= ' ' . $attribute . '="' . $this->{$attribute} . '"';
}
$result .= ' id="' . $this->name . '"';
if ($this->fileupload) {
$result .= ' enctype="multipart/form-data"';
}
......@@ -634,7 +643,7 @@ class Form {
* @return string The attributes for the element
*/
public static function element_attributes($element, $exclude=array()) {
static $attributes = array('accesskey', 'class', 'dir', 'id', 'lang', 'maxlength', 'name', 'size', 'style', 'tabindex');
static $attributes = array('accesskey', 'class', 'dir', 'id', 'lang', 'maxlength', 'name', 'onclick', 'size', 'style', 'tabindex');
$elementattributes = array_diff($attributes, $exclude);
$result = '';
foreach ($elementattributes as $attribute) {
......@@ -722,15 +731,18 @@ function form_render_element($element, Form $form) {
throw new FormException('No form renderer specified for form "' . $form->get_name() . '"');
}
$element['id'] = Form::make_id($element);
$element['class'] = Form::make_class($element);
$newelement = $element;
$newelement['class'] = (isset($newelement['class'])
? $newelement['class'] . ' ' . $form->get_name() : '');
$builtelement = $function($newelement, $form);
// Prepare the prefix and suffix
$prefix = (isset($element['prefix'])) ? $element['prefix'] : '';
$suffix = (isset($element['suffix'])) ? $element['suffix'] : '';
return $prefix . $rendererfunction($function($element, $form), $element) . $suffix;
return $prefix . $rendererfunction($builtelement, $element) . $suffix;
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment