Welcome Guest, Not a member yet? Register   Sign In
Simple Form Submit not working
#1

[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
#2

[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?
#3

[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.
#4

[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.
#5

[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.
#6

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

[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
#8

[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.
#9

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




Theme © iAndrew 2016 - Forum software by © MyBB