Checking Xoops Fields Before Submit


I made a bit of a hack. I'm sure it could be more elegant, but it checks the Xoops registration form elements before leaveing the page so if someone makes a mistake, like their passwords don't match or their username isn't long enought, etc., it does a popup right there, just like the rest of the formulize checks on the added registration fields.

This goes in the file class/xoopsform/form.php, just after these lines:
$js .= "function xoopsFormValidate_{$formname}() {
myform = window.document.$formname;\n";

Here's the code to add:

// EJ Addition of validation of Xoops form elements. Contact for more info, hosting, design, help with Xoops or any other web site needs.

$js .= "if (document.formulize.userprofile_uname && document.formulize.userprofile_uname.value.length < 4 ) {window.alert('- Username must be at least 4 characters.'); myform.userprofile_uname.focus(); return false; }\n";

$js .= "if (document.formulize.userprofile_password && document.formulize.userprofile_password.value.length < 5 ) {window.alert('- Password must be at least 5 characters.'); myform.userprofile_uname.focus(); return false; }\n";

$js .= "if (document.formulize.userprofile_password && document.formulize.userprofile_password.value != document.formulize.userprofile_vpass.value ) {window.alert('- Passwords do not match.'); myform.userprofile_password.focus(); return false; }\n";

$js .= "if (document.formulize.userprofile_email && document.formulize.userprofile_email.value.indexOf('@')<1) {window.alert('- Email does not appear to be valid.'); myform.userprofile_email.focus(); return false; }\n";

$js .= "if (document.formulize.userprofile_agree_disc && document.formulize.userprofile_agree_disc.checked == '') {window.alert('- You must agree to our disclaimer.'); myform.userprofile_agree_disc.focus(); return false; }\n";

// END EJ Addition


RE: Checking Xoops Fields Before Submit

Cool, this is a very useful addition, I am sure it will be appreciated by many.

The loss of information in the profile form is a pain in the ass, especially the way the Personal Details in the custom form are all lost. We have rejigged how that all works in 2.2, so if there is a problem, your info remains in the form when it reappears. It works in IE too, which for a short while looked like it was going to be a problem since it's junk compared to Firefox.