[eluser]Unknown[/eluser]
This code doesn't seem to work. When I submit my form, and validation is successful, it just still goes back to the form. It appears $this->form_validation->run() is returning false even though no errors are showing in the validation. Also, I removed the is_unique attribute to see if that was causing problems and it behaved the same.
What am I doing wrong?
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MyAccount extends CI_Controller {
/**
* Index controller for myaccount
* Created from welcome.php
*/
public function signup()
{
$data['title'] = 'Register';
$this->load->database();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->form_validation->run() == FALSE)
{
//create the form
$this->load->helper('form');
$data['form_signup'] = form_open('myaccount/signup');
$data['form_signup'] .= form_label('Please enter a username for sign-in purposes:'.form_input('username', set_value('username')), '');
$data['form_signup'] .= form_error('username');
$data['form_signup'] .= form_label('Password:'.form_password('password', set_value('password')), '');
$data['form_signup'] .= form_error('password');
$data['form_signup'] .= form_label('Confirm password:'.form_password('passconf', set_value('passconf')), '');
$data['form_signup'] .= form_error('passconf');
$data['form_signup'] .= form_submit('signup', 'Sign Up!');
$data['form_signup'] .= form_close();
$this->load->view('myaccount/signup',$data);
} else {
//insert the data into the db
//if successful, show success page
$this->load->view('myaccount/signup_success',$data);
}
}
}
/* End of file myaccount.php */
/* Location: ./application/controllers/myaccount.php */
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Form validation configuration
* Created from help docs
*/
$config = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'required|min_length[4]|max_length[30]|alpha_dash|is_unique[users.username]'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required|min_length[6]|max_length[32]'
),
array(
'field' => 'passconf',
'label' => 'PasswordConfirmation',
'rules' => 'required|matches[password]'
)
);
/* End of file form_validation.php */
/* Location: ./application/config/form_validation.php */
[/code]
views/myaccount/signup.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
Sign up for an account.
<?php echo $form_signup; ?>