Welcome Guest, Not a member yet? Register   Sign In
$.post() not working on simple request


I'm not a professional php programmer and I started using codeigniter some month ago for a personal website.

I wanted to try some ajax request and form but now I'm stuck!

I created a simple form with a jquery $.post() command but I can't find where is my mistake on that.

this is the controller (pretty simple)
function register()
        //is_logged_in placeholder
            //form submitted, process it and return response
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email|xss_clean');
            $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[16]|alpha_dash|xss_clean');
            $this->form_validation->set_rules('confirmation', 'Password Confirm', 'required|matches[password]|xss_clean');
            $this->form_validation->set_rules('birthdate', 'Data di Nascita', 'required|xss_clean');
            $data = array('email'           => $this->form_validation->set_value('email'),
                          'password'        => $this->form_validation->set_value('password'),
                          'confirmation'    => $this->form_validation->set_value('confirmation'),
                          'birthdate'       => $this->form_validation->set_value('birthdate')
            if($this->form_validation->run() == FALSE)
                $this->load->view('user/register', $data);
                $this->load->view('user/registerAnswer', $data);
            $data = array('email'           => '',
                          'password'        => '',
                          'confirmation'    => '',
                          'birthdate'       => '');
            //Print the form
            $this->layout->view('user/register', $data);
- If I use the page itself it works perfectly
- the $this->layout->view() command is just a plugin for CI I got a month ago from the wiki, it's self-explanatory Wink (notice that I call ->layout only if the form is not submitted)

here is the html part (->view('user/register')):
    $(function() {
            $( "#datepicker" ).datepicker();
            $( "#datepicker" ).datepicker( "option", "showAnim", 'bounce' );
            $.post("<?=base_url();?>user/register", $("#regform").serialize(),function(data){

<div id="formcontainer">
    <div align="center" id="formError">&lt;?php echo validation_errors(); ?&gt;</div><br />
&lt;form method="post" action="" id="regform"&gt;
<table border="0" width="100%">
        <tr><td align="right">
    <label for="email">Email:</label></td>
        <td align="left">&lt;input type="text" name="email" placeholder="Il tuo indirizzo email" value="&lt;?=$email;?&gt;" /&gt;&lt;/td>
        <tr><td align="right">
    <label for="password">Password:</label></td>
        <td align="left">&lt;input type="password" name="password" value="&lt;?=$password;?&gt;" /&gt;
<tr><td align="right">
    <label for="confirmation">Conferma Password:</label></td>
        <td align="left">&lt;input type="password" name="confirmation" value="&lt;?=$confirmation;?&gt;" /&gt;&lt;/td>
    <tr><td align="right"><label for="birthdate">Data di Nascita:</label></td>
        <td align="left">&lt;input type="text" id="datepicker" name="birthdate" value="&lt;?=$birthdate;?&gt;" /&gt;&lt;br /></td>
    <tr><td colspan="2" align="center">&lt;input type="hidden" name="go" value="1" /&gt;&lt;br />
      &lt;input type="submit" value="Registrati!" /&gt;&lt;/td>

- I correctly load jquery and jqueryui on the layout page

Where does the problem stands?

when I submit the form with the jquery code the form disappear (and it's right) but the POST values are not submitted!

$this->input->post('go') is FALSE Sad

If I try the code without the jquery string the pages are loaded correctly so there is probably a problem in my jquery lines.

how can I fix this?

ty Smile

Theme © iAndrew 2016 - Forum software by © MyBB