Welcome Guest, Not a member yet? Register   Sign In
Forms - set_value driving me mad!
#1

[eluser]35mm[/eluser]
Creating login and register forms. The login form works fine and set_value works.

The registration form, set_value will not work and I've spent far to long trying to work out why! It will display the validation errors but not the set_value. If I enter a username and click submit, I get the validation error that no user name was entered. So it seems the username isn't even getting through to the controller. Saying that has just made me look at this in a different way - it's not set_value that isn't working. It's the whole form that isn't working! But why?

Here's the controller code (I've removed all but username validation to save space);
Code:
public function submit()
    {
      
            
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            
  $this->form_validation->set_rules('username', 'username', 'required');

  if ($this->form_validation->run() == FALSE)
  {
                    $this->config->load('config');
                    $site_name = $this->config->item('site_name');
                    $data=array('title'=>'Join ' . $site_name);
                    
                    $this->load->view('pages/register_form',$data);
  }
Then in the view I have this (relevant bits only;
Code:
echo form_open('register/submit');
    echo validation_errors();
    // user name
    $user_name = array(
              'name'        => 'username',
              'id'          => 'username',
              'maxlength'   => '25',
              'size'        => '25',
              'value'       => set_value('username'),
            );

    echo form_label('Username ', 'username') . form_input($user_name) . '<br />';
#2

[eluser]Harold Villacorte[/eluser]
I was never able to get it to work that way. It will work like this though and with less code:
Code:
&lt;?php echo form_open('register/submit') ;?&gt;

<label for="username">Username:</label>
&lt;input type="text" name="username" value="&lt;?php echo set_value('username') ;?&gt;" /&gt;

<label for="password">Password:</label>
&lt;input type="password" name="password" value="" /&gt;

&lt;?php echo form_submit('submit', 'Login') ;?&gt;

&lt;?php echo form_close() ;?&gt;
#3

[eluser]35mm[/eluser]
Ah ok. Funny thing is I was trying to echo it in the page to, but that wasn't working either. It now works thanks to you. Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB