1
satrebil
formcheckbox.php validation not working in XOOPS 2.5.0
  • 2011/3/2 9:37

  • satrebil

  • Just popping in

  • Posts: 15

  • Since: 2009/5/3 2


Required field validation works well when there is more of a checkbox available to select, but when there is only one available checkbox validation does not work.
This error also results if more fields to further validate the checkbox, validation is not performed, since the javascript checkbox is not correct.

To solve the problem in checkbox validation with a single option, you must modify the file formcheckbox.php located in the / root / class / xoopsform directory.

We must replace the line 241 (in the XOOPS version 2.5.0) that contains:
return NWLINE "var hasChecked = false; var checkBox = myform.elements['{$eltname}'];" "for ( var i = 0; i < checkBox.length; i++ ) { if (checkBox[i].checked == true) { hasChecked = true; break; } }" "if (!hasChecked) { window.alert("{$eltmsg}"); checkBox[0].focus(); return false; }";

by
return NWLINE "var hasChecked = false; var checkBox = myform.elements['{$eltname}']; if (checkBox.length) {for (var i = 0; i < checkBox.length; i++) {if (checkBox[i].checked == true) {hasChecked = true; break;}}}else{if (checkBox.checked == true) {hasChecked = true;}}if (!hasChecked) {window.alert("{$eltmsg}");if (checkBox.length) {checkBox[0].focus();}else{checkBox.focus();}return false;}";


This is because if there is only one option the element is not an array.
We must first check if the length is not null to determinate if there is only one or more options in the checkbox.

Reported in tracker

Satrebil
(Excuse me for my english)

2
trabis
Re: formcheckbox.php validation not working in XOOPS 2.5.0
  • 2011/3/5 21:02

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I'm not able to reproduce it, I'm using this script to test it:
include 'mainfile.php';
include 
'header.php';
xoops_load('xoopsformloader');
$form = new XoopsThemeForm('Form''form''testform.php');
$checkbox = new XoopsFormCheckBox('Check Caption''check');
$checkbox->addOption(0'Yes');
$checkbox->addOption(1'No');
$checkbox->addOption(2'Maybe');
$form->addElement($checkboxtrue);

$checkbox4 = new XoopsFormCheckBox('Check Caption2''check2');
$checkbox4->addOption(0'Yes');
$form->addElement($checkbox4true);


$checkbox2 = new XoopsFormSelect('Select Caption2''select2'null3);
$checkbox2->addOption(0'Yes');
$checkbox2->addOption(1'No');
$checkbox2->addOption(2'Maybe');
$form->addElement($checkbox2true);

$checkbox3 = new XoopsFormSelect('Select Caption3''select3');
$checkbox3->addOption(0'Yes');
$checkbox3->addOption(1'No');
$checkbox3->addOption(2'Maybe');
$form->addElement($checkbox3true);

$form->addElement(new XoopsFormDhtmlTextArea('Text'"text"), true);

$editor = new XoopsFormEditor('Text2''text2', array('editor' => 'DhtmlTextarea'));
$form->addElement($editortrue);

$editor2 = new XoopsFormEditor('Text3''DhtmlTextarea', array('name' => 'text3'));
$form->addElement($editor2true);

$button = new XoopsFormButton('Submit''submit''Submit button''submit');
$form->addElement($button);

$form->display();

include 
'footer.php';
?>


Is it browser related? What code are you using?

3
satrebil
Re: formcheckbox.php validation not working in XOOPS 2.5.0
  • 2011/3/11 18:04

  • satrebil

  • Just popping in

  • Posts: 15

  • Since: 2009/5/3 2


Hi Trabis,

Test conditions:

System features:
Versión de Xoops    XOOPS 2.5.0
Versión de PHP    5.2.11
Versión de mySQL    5.1.38
-log
API del Servidor    cgi
-fcgi
OS    Linux
safe_mode    Off
register_globals    Off
magic_quotes_gpc    Off
allow_url_fopen    Off
fsockopen    On
post_max_size    60M
max_input_time    120
output_buffering    4096
max_execution_time    120
memory_limit    128M
file_uploads    On
upload_max_filesize    60M


Code used:
include 'mainfile.php'
include 
'header.php'
xoops_load('xoopsformloader'); 
$form = new XoopsThemeForm('Form''form''testform.php'); 
$checkbox = new XoopsFormCheckBox('Check Caption multi option''checkmulti'); 
$checkbox->addOption(0'Yes'); 
$checkbox->addOption(1'No'); 
$checkbox->addOption(2'Maybe'); 
$form->addElement($checkboxtrue); 

$checkbox2 = new XoopsFormCheckBox('Check Caption only 1 option''checkonlyone'); 
$checkbox2->addOption(0'Yes'); 
$form->addElement($checkbox2true); 

$select = new XoopsFormSelect('Select Caption multi option''select'null3); 
$select->addOption(0'Yes'); 
$select->addOption(1'No'); 
$select->addOption(2'Maybe'); 
$form->addElement($selecttrue); 

$select2 = new XoopsFormSelect('Select Caption only 1 option''select2'null3); 
$select2->addOption(0'Yes'); 
$form->addElement($select2true); 

$form->addElement(new XoopsFormDhtmlTextArea('Text'"text"), true); 

$editor = new XoopsFormEditor('Text2''text2', array('editor' => 'DhtmlTextarea'));
$form->addElement($editortrue); 

$editor2 = new XoopsFormEditor('Text3''DhtmlTextarea', array('name' => 'text3'));
$form->addElement($editor2true); 

$button = new XoopsFormButton('Submit''submit''Submit button''submit'); 
$form->addElement($button); 

$form->display(); 

include 
'footer.php'
?>


Test results:
With the original code operation of XOOPS 2.5.0 the operation code in different browsers (IE, Firefox and Chrome) is as follows:
Pressing Submit without filling any field displays the validation error of the first checkbox (multiple) and position the cursor in the field with error (works fine).
Selecting an option in the first checkbox and pressing submit without filling anything else, shows validation error in the second checkbox, but send or reset the form.

With the modified code in XOOPS 2.5.0 is the correct operation in both checkbox and with different browsers (IE, Firefox and Chrome).

Thanks

Satrebil

4
satrebil
Re: formcheckbox.php validation not working in XOOPS 2.5.1a
  • 2011/9/8 7:56

  • satrebil

  • Just popping in

  • Posts: 15

  • Since: 2009/5/3 2


Hello,

The same problem is still playing the xoops version 2.5.1a

The problem occurs when there is a checkbox form with only one option and that is required.

This option is used for example to validate the privacy policy in a contact form (to comply with European legislation on data protection).

The solution is the same as proposed above for XOOPS 2.5.0.

It would be interesting in the future version 2.5.2 was resolved.

Reported in tracker

Thanks

Satrebil
(Excuse me for my english)

5
trabis
Re: formcheckbox.php validation not working in XOOPS 2.5.1a
  • 2011/9/8 11:33

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Hi satrebil, thank you very much for the patch!

I have confirmed the bug, applied the patch and it is working perfectly now!

It has been committed on SVN and waiting your review.

Login

Who's Online

462 user(s) are online (348 user(s) are browsing Support Forums)


Members: 0


Guests: 462


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits