4

I understand what this error means i just can't seem to understand why does it happen.

I am using Joomla 1.7 and created a component. Now everything worked and one weird day i recieved this error when trying to submit a form. This is what i have :

<form action="index.php" method="post" name="adminForm">
..some elements...
<input type="hidden" name="option" value="<?php echo $lists['option']; ?>" />
<input type="hidden" name="task" value="<?php echo $lists['task']; ?>" /> 
</form>

When $lists['task'] echos exactly what it suppoused to. Now the error is showing inside the core.js joomla file on the submitForm function, which contains :

function submitform(a) {
    if (a) document.adminForm.task.value = a;
    if (typeof document.adminForm.onsubmit == "function") document.adminForm.onsubmit();
    typeof document.adminForm.fireEvent == "function" && document.adminForm.fireEvent("submit");
    document.adminForm.submit()
}

Sorry the file is compressed, basically it's a very simple function that sets the task element to the given var and submits form. (FYI : the a var is the right var and everything is sent perfectly)

Now what i can't seem to understand is how come i get this error when it never happened before and i have created many forms like this inside the component exactly the same and it works fine.

WTK
  • 16,583
  • 6
  • 35
  • 45
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
  • Maybe it's caused by the value of `$lists['task']` that can be malformed (by user mistake or bug somewhere else in code) in such manner, that ` – WTK Aug 03 '12 at 11:57
  • That's good point but i have checked that and it is good. even if i hard code some value still same result. – eric.itzhak Aug 03 '12 at 12:13
  • Ok, so once you hardcode some value it can be reproduced every time? On different browsers? – WTK Aug 03 '12 at 12:58
  • One more thing to check - does `document.adminForm.nodeName` value is "FORM"? Maybe some code overwrites document.adminForm with other, custom object? Check also if `document.adminForm.option` (or any other field than "task") is defined. – WTK Aug 03 '12 at 13:05
  • Yes it reproduced, checked on Chrome and IE. and i have checked other form elements and they are defined. – eric.itzhak Aug 03 '12 at 13:36
  • You should use `var form = document.forms.adminForm` and `var task = form.elements.task` instead of directly accessing properties on the `document` and `form` object. – Bergi Aug 03 '12 at 22:28
  • Why? it supposed to be the exactly the same. – eric.itzhak Aug 03 '12 at 23:21
  • I don't know much about Joomla but try to add some id to task input and later on in script try to access it using `document.getElementById` - check if it's returning correct element. – WTK Aug 04 '12 at 08:50

4 Answers4

0

If an onsubmit event handler is present, that function will be called twice:

1- document.adminForm.onsubmit();

2- document.adminForm.submit(); (will also trigger onsubmit event handler).

Since I don't see that code here, I can't diagnose further. However, you may want to place a debug point (using Firebug for example) in this submitForm function as well as one in any handlers attached to the onsubmit event.

Joe Johnson
  • 1,814
  • 16
  • 20
  • 1
    That dies not answer the question though, should be a comment. – eric.itzhak Aug 08 '12 at 23:42
  • @eric.itzhak Fixing the form submission logic may have, however, solved the issue at hand. Hence, it is an answer though it may not be the best or most correct one -- I'll give you that :) – Joe Johnson Aug 10 '12 at 16:51
0

<input type="hidden" name="task" value="<?php echo $lists['task']; ?>" />

property "value" must be empty, it will assigned by joomla js

<input type="hidden" name="task" value=""/>

gladddd
  • 11
0

Well the problem was as WTK suggested, there was an HTML error. Some code broke the HTML (2 table rows there were outsite a table) which caused this error.

eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
0

in www/media/system/js/core-uncompressed.js around line 22, after

if (!form) {
    form = document.getElementById('adminForm');
}

add:

if (!form) {
    form = document.adminForm;
}