Commit 5f5dc05f authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Removed some debug lines. Made sure action is set correctly. Do ajax

requests by the correct method. Call message/error javascript functions
with better parameters
parent 7e3f060a
......@@ -642,8 +642,6 @@ class Form {
foreach ($this->get_elements() as $element) {
$result[$element['name']] = $this->get_value($element);
}
log_debug($result);
log_debug($_POST);
return $result;
}
......@@ -709,24 +707,20 @@ EOF;
throw new FormException('At least one submit-type element is required for AJAX forms');
}
$action = ($this->action) ? $this->action : 'editsitepage.php';
$action = ($this->action) ? $this->action : basename($_SERVER['PHP_SELF']);
$method = ($this->get_method() == 'get') ? 'GET' : 'POST';
$result .= <<<EOF
// This does a post. Gets are much simpler in mochikit and we
// could check whether there are any big fields (like wysiwyg,
// textarea) and do a get (doSimpleXmlHttpRequest) instead if
// there aren't any.
var req = getXMLHttpRequest();
req.open('POST','{$action}');
req.open('{$method}', '{$action}');
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
var d = sendXMLHttpRequest(req,queryString(data));
d.addCallbacks(
function (result) {
var data = evalJSONRequest(result);
debugObject(data);
if (data.error) {
{$this->name}_message(data.message);
{$this->name}_message(data.message, 'error');
for (error in data.errors) {
{$this->name}_set_error(error + '_msg', data.errors[error]);
{$this->name}_set_error(data.errors[error], error);
}
EOF;
......
......@@ -68,4 +68,12 @@ function form_render_wysiwyg($element, $form) {
. '>' . hsc($form->get_value($element)) . '</textarea>';
}
/**
* @todo document: basically, the required rule now works better, as stripping
* tags out takes away a whole bunch of hidden stuff
*/
function form_is_empty_wysiwyg($value, $element) {
return strip_tags($value) === '';
}
?>
......@@ -52,8 +52,10 @@ function form_renderer_table($builtelement, $rawelement) {
$result .= "</td>\n\t</tr>";
return $result;
}
// Set the class of the enclosing <tr> to match that of the element
$result = "\t<tr";
$result .= ' id="' . $rawelement['name'] . '_container"';
// Set the class of the enclosing <tr> to match that of the element
if ($rawelement['class']) {
$result .= ' class="' . $rawelement['class'] . '"';
}
......@@ -91,9 +93,6 @@ function form_renderer_table($builtelement, $rawelement) {
$result .= "\t<tr>\n\t\t<td colspan=\"2\" class=\"errmsg\">";
$result .= hsc($rawelement['error']);
}
else {
$result .= "\t<tr style=\"display:none\" id=\"" . $rawelement['id'] . "_msg\"><td>";
}
$result .= "</td>\n\t</tr>\n";
return $result;
......@@ -109,18 +108,38 @@ function form_renderer_table_footer() {
function form_renderer_table_messages_js($id, $submitid) {
$result = <<<EOF
function {$id}_set_error(id, message) {
swapDOM($(id), TR({'id':id}, TD({'colspan':2, 'class':'errmsg'}, message)));
// Given a message and form element name, should set an error on the element
function {$id}_set_error(message, element) {
{$id}_remove_error(element);
element += '_container';
// @todo set error class on input elements...
$(element).parentNode.insertBefore(TR({'id': '{$id}_error_' + element}, TD({'colspan': 2, 'class': 'errmsg'}, message)), $(element).nextSibling);
}
function {$id}_remove_error(id) {
swapDOM($(id),TR({'id':id, 'style':'display:none;'}, TD(null)));
// Given a form element name, should remove an error associated with it
function {$id}_remove_error(element) {
element += '_container';
var elem = $('{$id}_error_' + element);
if (elem) {
removeElement(elem);
}
}
function {$id}_message(m, type) {
swapDOM($('{$submitid}_msg'), TR({'id':'{$submitid}_msg'}, TD({'colspan':2, 'class':type}, m)));
function {$id}_message(message, type) {
var elem = $('{$id}_message');
var msg = TR({'id': '{$id}_message'}, TD({'colspan': 2, 'class': type}, message));
if (elem) {
swapDOM(elem, msg);
}
else {
appendChildNodes($('{$submitid}_container').parentNode, msg);
}
}
function {$id}_remove_message() {
swapDOM($('{$submitid}_msg'), TR({'id':'{$submitid}_msg', 'style':'display:none;'}, TD({'colspan':2})));
var elem = $('{$id}_message');
if (elem) {
removeElement(elem);
}
}
EOF;
return $result;
}
......
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