Welcome Guest, Not a member yet? Register   Sign In
Protype ajax validation problem
#1

[eluser]Michael;[/eluser]
I've been working on this for a day and a half now and I'm about to pull my hair out. I know it has to be something simple, or I would have been able to work it out by now.

Basically, I'm using ajax to validate form fields inline and am hiding the submit button until all fields that are required are filled in (and validated when required), the problem is that $this->input->post('field') will absolutely *NOT* validate if empty. In fact, rather the opposite, like so:

Code:
function required() {
    if(!preg_match('/^.$/', $this->obj->input->post('value'))) {
      print "This field is required.";
    }
  }

The above will return a "valid" response if you tab through the field and leave nothing in it, if you put '123' into the field it returns invalid. If you remove the '!' ( as in preg_match ) it weill still return a valid response if the field is empty.

I have tried everything from "empty()" and "strlen()" to the above regex and "== ''". NOTHING is working.

Now, here's the really odd thing... if I use the ajax outside of CI it works perfectly.

Code:
// validation javascript
function ValidateField(input, container, validation) {
  new Ajax.Request('validator.php', {
    parameters: {validation: validation, value: $F(input)},
      onComplete: function(AjaxResult){
        if(AjaxResult.responseText){
          $(input).setStyle({border:'1px #C00 solid'});
          $(container).update(' '+AjaxResult.responseText);
        }else{
          $(input).setStyle({border:'1px solid'});
          $(container).update('Valid');
        }
      }
    });
  }

and the html markup:

Code:
First Name: <input type="text" name="first_name" maxlength="25"
value="<?=$this->validation->first_name;?>" size="25"
onblur="ValidateField(this, 'first_name', 'required')"/>
<span id="first_name" style="color:#C00">* Required</span>

Everything else validates just fine; from email addresses and phone numbers to db checks for present data ... it's as if $this->input->post() has a "positive value" no matter what is ( or is not ) actually *IN* the field.

I am completely stuck here and this is kind of a deal breaker for my project ... and if I have to start over outside of CI I'm going to tear my hair out.


Messages In This Thread
Protype ajax validation problem - by El Forum - 08-10-2008, 03:50 PM
Protype ajax validation problem - by El Forum - 08-11-2008, 08:45 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 08:58 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 09:19 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 09:38 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 09:52 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 10:04 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 10:21 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 10:23 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 10:45 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 11:25 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 11:51 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 11:53 AM
Protype ajax validation problem - by El Forum - 08-11-2008, 12:31 PM
Protype ajax validation problem - by El Forum - 08-11-2008, 12:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB