1

I am trying to learn MVC with phpcodeigniter. I got a project file with all the codes and my task is just to learn from them simply by running the files using xamp. All the bits are doing fine but, whenever I try to create a new user with the form, I get a an instant message next to the RTC-ID saying "user already existing" and the submit button disappears! even though there is no data loaded in the database (tried to upload the image for this issue but I am not permitted to do so). I am trying to find out why this error is showing up. I have tried to look up where this issue is from and found this codes acting on the form and the data. These are some of the code snippets which creates the new user. I have tried to solve this issues for many days. I will be really grateful if someone could kindly help me solve the issue and I am not sure if I am posting at the right forum my apologies. Thank you!

views/rtc.php

<!--FORM STARTS HERE-->

    <form action="<?= site_url('form/rtc_insert'); ?>" method="post">   



                        <label >RTC ID:<span id="rtc_reg_id_re" style="font-size:12px;float:right;"></span></label>
                        <input type="text" name="id" id="rtc_reg_id" placeholder="RTC ID" required/>    

                        <label >Name:</label>
                        <input type="text" name="name"  placeholder="Name" required/>

                            <label >Country:</label>
                            <select name="country" >
                                <option>Select Country</option>
                                <option value="Bangladesh">New zealand</option>
                            </select><br/><br/>                                

                            <label >District:</label>
                            <input type="text" name="state" placeholder="District" required/>

                            <label >Village:</label>
                            <input type="text" name="city" placeholder="Village" required/>

                            <label >Address:</label>
                            <textarea type="text" name="address" placeholder="Address" required/></textarea>                       

                            <input type="submit" value="Save" id="rtc_reg_submit" class="button"><br/>

                       </form>

Controller/form.php

function rtc_insert()   
{

    $session_user=$this->session->userdata('logged_in');
    if($session_user['ath']=='admin')
    {
        $msg = $this->form_model->rtc_ins();
        redirect('form/rtc/You Have Successfully Created '.$msg);
    }
    else
        {
        echo ' <script type="text/javascript">
                    alert("Access Error....");
                    </script>';
            redirect('login/home');
        }

}

models/form_model.php

function rtc_ins()
{

    $session_user=$this->session->userdata('logged_in');
    $sysdat = date("Y-m-j H:i:s");      

    $data= array(
        'id'        => $this->input->post('id'),
        'name'      => $this->input->post('name'),          
        'country'   => $this->input->post('country'),
        'city'      => $this->input->post('city'),
        'state'     => $this->input->post('state'),
        'address'   => $this->input->post('address'),           
        'cre_name'  => $session_user['username'],
        'cre_date'  => $sysdat
        );

    $this->db->insert('rtc_info',$data);

    return $this->input->post('id');
    // echo "<pre>";
    // print_r($_POST);

}

models/ajax_models.php

public function rtc_reg_id($id)
{
    $query = $this->db->get_where('rtc_info',array('id' => $id));
    $query = $query->num_rows();

    if($query > 0)  
        return 1;
    else
        return 0;
}

js/ajax.js

             function rtc_reg_id(){

            var rtc_name = $('#rtc_reg_id').val();
            if(rtc_name.length > 0)
            {
                $.post(base_url()+'ajax/rtc_reg_id/'+rtc_name,function(data){

                    if(data==0){
                        $('#rtc_reg_id_re').css({'color':'green'});                     
                        $('#rtc_reg_id_re').html('Available');
                        $('#rtc_reg_submit').attr('type','submit').show(100);
                    }

                    else{
                        $('#rtc_reg_id_re').css({'color':'red'});
                        $('#rtc_reg_id_re').html('ID Already Existing'); 
                        $('#rtc_reg_submit').attr('type','').hide(100);                           
                    }
                });
            }
            else
            {
               $('#rtc_reg_id_re').empty();
               $('#rtc_reg_submit').attr('type','submit').show(100);                           
            }
         }            
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
karma
  • 137
  • 3
  • 18
  • `console.log(data);` right after the $.post line. Hit control+shift+i and go to console to see the value. – Matt Mar 05 '15 at 15:18
  • Thank you @mkaatman now the user already exists is no more there. thank you very much – karma Mar 05 '15 at 15:29
  • I think this has something to do with the browser, it works in google chrome but in firefox it still displays user already exists – karma Mar 05 '15 at 15:39
  • What does firefox return for `console.log(data);`? To troubleshoot you could also add `error_log($quary);` inside `rtc_reg_id()` and see if that query is correct. – Matt Mar 05 '15 at 15:42
  • I am getting this message from the error log Use of getPreventDefault() is deprecated. Use defaultPrevented instead – karma Mar 05 '15 at 16:17
  • Never hear of `getPreventDefault()` so this might help you out: `$('form').on('submit', function(e){e.preventDefault(); /* AJAX code goes here*/});` **[Click Here to learn more awesome things](http://stackoverflow.com/a/21617685/2191572)** – MonkeyZeus Mar 05 '15 at 18:56
  • console.log(data); After adding the code the problem of "user already exist" is no more in Chrome but it still is in firefox. Firefox console also gives out "The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol." warning, which I tried to solve by addng in header includes file, but it is not working. – karma Mar 05 '15 at 19:05

0 Answers0