Welcome Guest, Not a member yet? Register   Sign In
Question with small test script
#1

[eluser]Solarpitch[/eluser]
Hey guy's,

I'm still new to CI so just playing around with different functions at the moment. One thing I'm trying to understand is a login script. I've set up this test script to help me understand. Here I'm basically calling the index page of the application which will load the login form. I have the form submitting to the same page..

Code:
<?php echo form_open('index'); ?>

But when I load the index page it still seems to preform the function as if it was submitted and prints my error "Invalid Name". So when I got direct to the url it will always print this message even if the user has not tried to log in.

If someone could take a look and point me in the right direction, that would be great.

Code:
<?php

function index()
    {
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        
        $username = $this->input->post('username');
        
        if(isset($username))
        {
        if($username == "gerard")
        {
            $data['msg'] = "This is a valid name!";
        }
        else
        {
            $data['msg'] = "Invalid name!";
        }
        
    }

        $data['form'] = "login_form/form";
        $this->load->view('template/login', $data);
    }
    

?>

login_form/form.php...
Code:
<?php echo $msg;?>
#2

[eluser]therealmaloy[/eluser]
solarpitch

please be reminded that the post variables can only be propagated properly once you have properly posted data/information from your submitted form.

let's try to see the complete form submission view code you have.

the statement below will never get any value, not unless, you have posted/inputted the value for username text input control before submission:


$username = $this->input->post('username');
#3

[eluser]anggie[/eluser]
Hmm...I tried to understand your explanation and here some suggestion for you..
you should change your code to
Code:
if($username=='')  // not isset
That because the input class will return FALSE if there is no data inside $_POST, so it never be 'not set yet' condition.
#4

[eluser]Solarpitch[/eluser]
Hi,

Here's the complete submission view.

Code:
<?php echo validation_errors(); ?>
<?php echo form_open('index'); ?>
    <table width='420' border='0' cellspacing='2' cellpadding='0' style='font-family:Arial; font-size:12px; font-weight:bold; color:#5A7B00; '>
  <tr>
    <td>Account Username:</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&lt;input type='text' name='username' style='width:450px; font-size:23px; color:#999999; ' value="&lt;?php echo set_value('username'); ?&gt;"&gt;&lt;/td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Password:</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&lt;input type='password' name='password' style='width:450px; font-size:23px; color:#999999; '&gt;&lt;/td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>
    &lt;input type='hidden' name='process' value='' /&gt;
    &lt;input type='hidden' name='ip' value=''&gt;
    &lt;input type='image' src='designs/login_bt.jpg' alt='login ' name='process' value='execute'&gt;&lt;/td>
    <td>&nbsp;</td>
  </tr>
</table>
&lt;/form&gt;
&lt;?php echo $msg;?&gt;

See... the form above will submit to the index function in my controller, so why cant I use that function to get the variables being posted and then later... pass to my model? Do I need to create a seperate function called process or something to handle the submission... can I not handle the submission with the same index function?
#5

[eluser]Solarpitch[/eluser]
Quote:the statement below will never get any value, not unless, you have posted/inputted the value for username text input control before submission:

$username = $this->input->post(‘username’);

I should mention that $username is being passed a value as I'm able to print it to screen after a submission
#6

[eluser]Henry Weismann[/eluser]
[quote author="Solarpitch" date="1229976144"]
Quote:the statement below will never get any value, not unless, you have posted/inputted the value for username text input control before submission:

$username = $this->input->post(‘username’);

I should mention that $username is being passed a value as I'm able to print it to screen after a submission[/quote]

I think anggie is correct. It will receive a value of an empty string or false I forget which one. Either way isset will return true for both cases. It is not the same as the actual post array where you would use isset on a post array item.
#7

[eluser]Henry Weismann[/eluser]
If it is passed a value what value does it have when you print it? You should learn the data validation class and it will save you tons of time and headaches.




Theme © iAndrew 2016 - Forum software by © MyBB