Welcome Guest, Not a member yet? Register   Sign In
$this->input->post() always returning FALSE
#1

[eluser]karimmaassen[/eluser]
I'm developing a site with a signup form. The problem is that on my localhost (MAMP), everything works fine. But on the public server, every post() is returning FALSE.

This is what the code looks like:
Code:
<fieldset>
<legend>Signup</legend>&lt;?php

echo form_open('signup');

            echo form_input('username', set_value('username', $this->input->post('username')));
            echo form_input('email_address', set_value('email_address', $this->input->post('email_address')));
            echo form_password('password', set_value('password', $this->input->post('password')));
            echo form_submit('submit', 'Create Acccount');

echo form_close(); ?&gt;
</fieldset>



Code:
class Signup extends CI_Controller {
    
    function index()
    {    
        if ($this->input->post())
        {
            $this->load->view('signup_success');
        }
        else
        {
            $this->load->view('signup_fail');
        }
    }

}

Does anyone know what the problem could be?
#2

[eluser]InsiteFX[/eluser]
Did you setup your validation rules? Also you need to use the Form_Validation Library!

InsiteFX
#3

[eluser]karimmaassen[/eluser]
I did. I left them out of the example to simplify. But yes, I did.
#4

[eluser]InsiteFX[/eluser]
Well it has to go through this in you Signup
Code:
if ($this->form_validation->run() == FALSE)
{
    $this->load->view('signup_fail');
}
else
{
    $this->load->view('signup_success');
}

InsiteFX
#5

[eluser]Armchair Samurai[/eluser]
You need to specify a parameter for post() (i.e. $this->input->post('username')), otherwise you'll need to check $_POST.
#6

[eluser]karimmaassen[/eluser]
@InsiteFX:

To specify my code a little bit more, this is what I'm doing right now:

Code:
if ($this->input->post())
{
    $this->load->library('form_validation');

    $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[3]|max_length[32]');
    $this->form_validation->set_rules('email_address', 'Email address', 'trim|required|valid_email');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[3]');
                
    if($this->form_validation->run() == FALSE)
    {
        echo 'Posted, but not validated';    
    }
    else
    {
        echo 'Posted and validated';
    }
}
else
{
    echo 'Not posted';
}

The thing is, I'm only seeing 'Not posted'.

@Armchair Samurai:

I'm fairly sure checking for $this->input->post() is correct. But I also tried $_POST. It doesn't work neither.
#7

[eluser]InsiteFX[/eluser]
As Armchair Samurai mentioned above your passing a value to your input!
Code:
if ($this->input->post('WHAT_VALUE?'))

InsiteFX
#8

[eluser]karimmaassen[/eluser]
[quote author="InsiteFX" date="1305471432"]As Armchair Samurai mentioned above your passing a value to your input!
Code:
if ($this->input->post('WHAT_VALUE?'))

InsiteFX[/quote]

Nope, it doesn't make a difference. I’m fairly sure checking for $this->input->post() is correct. But I also tried $_POST and I tried checking for hidden input, but that doesn't work neither.
#9

[eluser]osci[/eluser]
as of user guide $this->input->post() returns all POST items or false if $_POST is not set.
I guess it would be ok to use it like this (although i don't see the reason returning a whole array to check if a form is submitted)

@Kriem
You might be having other issues.

Nevertheless I too suggest to use ie the name of your submit button to check if a form is posted like this
Code:
$this->input->post('submit')

and when you post code pls post in code tags
Code:
[ code ][/ code ]
without the spaces
#10

[eluser]karimmaassen[/eluser]
Could this be a trailing slash problem? The form redirects to the correct url, but all post data is lost. I don't know why this works on my localhost, but fails on the public server.




Theme © iAndrew 2016 - Forum software by © MyBB