Form Validation

Hello,

I’m trying to some form validation based on the contact manager example, unfortunately without any real success.

The form (json: repForm) on the left layout makes some onValidateError.
It fires an alert but still adds entry to the database.

The same form is used to add new records via popWindow.
The window just closes even with the fields empty, althought NotEmpty validation is set.

I have been trying to do validation but no success.

Please help me out here.
omar.zip (1.53 MB)

hi

kulla10.js line 83

repDetails.attachEvent("onButtonClick",function(id){ repDetails.validate() });

line 134

repDetails.attachEvent("onButtonClick", function(name, command){ dataUpdate.sendData(); });

summary you have 2 independ events, one of them do validation, another one - sending data to server. summary you need:

repDetails.attachEvent("onButtonClick", function(name){ if (repDetails.validate()==true) dataUpdate.sendData(); });

Hello Andrei,

your solution works perfect. :smiley:

And also top response time.

I have a similar problem. I am trying to do the validation and if it passes, send the variables to a location. This one always passes validation even if I leave the fields blank. Any idea whats wrong ?

        formStructure = [
        {type:"settings",position:"label-top"},
        {type: "fieldset",name:"reqacontainer", label: "Request Administrator Access", list:[
        {type: "input", name: "login", label: "Your Login(R/O) :", maxLength:100, readonly:true, value: "<?php echo $u; ?>"},
        {type:"input", name:"email", label:"Your Email:", validate:"ValidEmail"},
        {type:"newcolumn",offset:20},
        {type:"button", name:"save", width:150,offsetTop:15, value:"SEND REQUEST"}, 
        ]}
        ];
  
            var dhxfrmUREG = new dhtmlXForm("reqa",formStructure);
            dhxfrmUREG.attachEvent("onButtonClick", function(id){
                if(dhxfrmUREG.validate())
                {
                    alert(dhxfrmUREG.validate())
                    dhtmlxAjax.post("<?php echo site_url('vmatrix/register'); ?>", encodeURI('ul='+dhxfrmUREG.getItemValue("login")+'&eml='+dhxfrmUREG.getItemValue("email")), ShowStat);
                }else
                {
                    alert("Invalid Email");
                }
            })

Thanks in advance…

do you need to skip validation if field is blank?

No for the email it should not be blank and it should be a valid email

So you mean to say it doesnt validate email if its blank? I did not understand nor does the documentation say anything ?

Yes, use

{type: “input”, … validate: “ValidEmail,NotEmpty”}
or
{type: “input”, … validate: myFunc}

function myFunc(value) {
// check value here
return true/false;
}

Thnkx Andrei,
It worked !!