Mirza Chilman
Mirza Chilman

Reputation: 429

Codeigniter: Accepting Space and Symbols for Validation with JQuery

I have a form that need to be validate, but I'm having hard time to figure out how validate using JQuery especially when JQuery change space into %20 AND not accepting any symbols such as @,$,!, take a look at screenshot below

ERROR WITH SYMBOLS enter image description here

It's says that the URI you input has disallowed characters

SPACE

And then for space input it changes the value and adding %20 enter image description here of course Firhal%20Faisal is not in data base there's only Firhan Faisal

how can i manage to solve those 2 problems that i have?below are my javascript validation form for name that seems change space input into %20, and for email it's basically the same

JAVASCRIPT

$("#nama").bind("keyup change", function(){
    var nama = $(this).val();
    $.ajax({
        url:'cekData/mahasiswa/nama_mahasiswa/'+nama,
        data:{send:true},
        success:function(data){
            if(data==1){
                $("#reportNama").text("");
                 $('button[type="submit"]').prop('disabled','');
                 $("#username").prop("disabled", '');
                 $("#password").prop("disabled", '');
                 $("#nim").prop("disabled", '');
                 $("#email").prop("disabled", '');
                 $("#telepon").prop("disabled", '');
            }else{
                $("#reportNama").text("*nama sudah ada");
                 $('button[type="submit"]').prop('disabled',true);
                 $("#username").prop("disabled", true);
                 $("#password").prop("disabled", true);
                 $("#nim").prop("disabled", true);
                 $("#email").prop("disabled", true);
                 $("#telepon").prop("disabled", true);
                }
            }
        });
    });

CONTROLLER

public function cekData($table,$field, $data){
    $match = $this->MDosen->read($table,array($field=>$data), null, null);
    if($match->num_rows() > 0){
        $report = 2;
    }else{
        $report = 1;
    }
    echo $report;
}

Upvotes: 0

Views: 83

Answers (1)

Sergey Mitroshin
Sergey Mitroshin

Reputation: 113

You should pass the value using GET or POST parameters:

JavaScript

$.ajax({
    url:'cekData/mahasiswa/nama_mahasiswa/',
    data:{send:true, value: nama},
    success:function(data){
        ...
    }
});

Controller

public function cekData($table,$field){
    $data = $this->input->get('value');
    $match = $this->MDosen->read($table,array($field=>$data), null, null);
    if($match->num_rows() > 0){
        $report = 2;
    }else{
        $report = 1;
    }
    echo $report;
}

Upvotes: 1

Related Questions