CodeIgniter Forums
Simple Form Submit not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Simple Form Submit not working (/showthread.php?tid=13256)



Simple Form Submit not working - El Forum - 11-16-2008

[eluser]CI Newbie Guru[/eluser]
Hi,

I have a simple login form which I want to submit using post method. When I press submit button I am taken back to the page but with no POST request.

Can any one please tell me what I can do to fix it.

My code is below:

Login Form View:

<html>
<head>
<title>My Form</title>
</head>
<body>

<?php //echo validation_errors(); ?>

<?= form_open('/member/signin') ?>
<?= form_hidden('form', 'submit') ?>
<h5>Username</h5>
&lt;input type="text" name="username" value="" size="50" /&gt;

<h5>Password</h5>
&lt;input type="text" name="password" value="" size="50" /&gt;



&lt;?= form_submit(array('name' => 'submit', 'id' => 'submit', 'class' => 'det_sea_text6_li2_02_bottom'), 'Login') ?&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;



Controller:

Code:
&lt;?php
class Member extends MY_Controller {
    
    function Member()
    {
        parent::MY_Controller();
        $this->load->database();
        $this->load->helper(array('form', 'url'));    
        $this->load->library('validation');
    }

    function index()
    {
    
    }
      
    function signin()
    {
        
        $fields = array('username'                 => 'Username',
                        'password'                 => 'Password',
        );

        $rules  = array('username'                 => 'required',
                        'password'                 => 'required',
        );
        $this->validation->set_fields($fields);
        $this->validation->set_rules($rules);

        $email         = $this->input->post('username');
        $password     = $this->input->post('password');
        
        if ($this->validation->run() == FALSE)
        {            
            $this->load->view('member/signin', $this->layout);
        }
        else
        {
            $this->load->model('customer');
            
            $customer = new Customer();
            $details = array(
                            'username' => $username,
                            'password' => $password,
            );
            $customer->getDetails(false, false, $details);
            //redirect('/member/home');
            $this->load->view('formsuccess');
        }
    }    
}

MY_CONTROLLER:
Code:
&lt;?php

class MY_Controller extends Controller {

    

    function MY_Controller()
    {
        
        parent::Controller();
        
        global $object;
        
        $data = '';
        
        

        $this->layout = array();
    

        # record the request URL in case we want to use it at some point.
        # Except the ignored ones, of course.
        
        
        $this->layout['header_login'] = $this->header_login();
        
        /* Categories Drop down */
        $this->load->database();
        $this->load->model('category');
        $category = new Category();
        $category->getDetails('lang', $this->config->item('lang_selected'), false, 'result');
        $this->layout['category_list'] = $category->details;
        
    }
}

?&gt;

here is a link if you need to check

http://www.cashbids4u.com/index.php/member/signin

Thanks


Simple Form Submit not working - El Forum - 11-16-2008

[eluser]dmorin[/eluser]
"When I press submit button I am taken back to the page but with no POST request."

Not sure what you mean. The form is submitting back to your site with the post data. Your site is then redirecting the user back to the same URL, which appears to be commented out in the code you displayed above. So what do you mean with no POST request?


Simple Form Submit not working - El Forum - 11-16-2008

[eluser]JoostV[/eluser]
Did you check if you really don't have a POST? Try echoing out
Code:
echo '<pre>' . print_r($_POST, true) . '</pre>';

By the way: why do you define $email = $this->input->post('username');? You don't seem to use use it after definition.


Simple Form Submit not working - El Forum - 11-16-2008

[eluser]dmorin[/eluser]
The problem with doing
Code:
echo '<pre>' . print_r($_POST, true) . '</pre>';
is that because the page is redirecting, it will show as an empty array when in fact, it's a second pageload because the url provided does a redirect after the submit.


Simple Form Submit not working - El Forum - 11-16-2008

[eluser]Colin Williams[/eluser]
A redirect is a new HTTP request, absent of posted data. C'mon now! To maintain the $_POST data between requests, store it in the session temporarily.


Simple Form Submit not working - El Forum - 11-17-2008

[eluser]JoostV[/eluser]
Well yes, of course you need to save the login data to session before your redirect.


Simple Form Submit not working - El Forum - 11-17-2008

[eluser]CI Newbie Guru[/eluser]
Thanks everyone for your replies. What I mean by no POST data is that when page is submitted I cannot use data entered by user on the form.

I did try printing out $_POST but it is empty and I agree that it is being redirected which is causing it to loose the POST data.

I don't get why it is redirecting user back to the same page whereas I don't want it to do this and also not sure where I need to amend it to stop sending users back to the page.

Can any one please point me to the right direction to get the POST data working and stop this redirection.

Thanks


Simple Form Submit not working - El Forum - 11-17-2008

[eluser]CI Newbie Guru[/eluser]
I have find out what was causing it to redirect to same page. I have this in my .htaccess file which was causing a redirect. Removing it solved the problem.

RewriteCond $1 !^(index\.php|images|robots\.txt|buttons|css|furniture|headings|products|scripts)
RewriteRule ^(.*)$ /index.php/$1 [R]

I am just wondering now when I do put this back to get rid of 'index.php' from URL then what can I do to avoid redirection when form is submitted.

Thanks everyone for your suggestions.


Simple Form Submit not working - El Forum - 11-17-2008

[eluser]dmorin[/eluser]
See http://codeigniter.com/wiki/mod_rewrite/