The form is duplicating in a page. I cant upload the picture though:(
I dont remember having any loop for that. I badly need help. This is my
view_register.php
<body>
<h1>IMAGE HERE</h1>
<div id="body">
<br/>
<p class="body">
<!--trial-->
<?php
echo form_open('start');
$firstname = array(
'name' => 'firstname',
'value' => set_value('firstname')
);
$lastname = array(
'name' => 'lastname',
'value' => set_value('lastname')
);
$email = array(
'name' => 'email',
'value' => set_value('email')
);
$dateofbirth = array(
'name' => 'dateofbirth',
'value' => set_value('dateofbirth')
);
$gender = array(
'name' => 'gender',
'value' => set_value('gender'),
'style' => 'margin:10px'
);
$username = array(
'name' => 'username',
'value' => set_value('username')
);
$password = array(
'name' => 'password',
'value' => ''
);
$confpass = array(
'name' => 'confpass',
'value' => ''
);
?>
<!--trial ends here-->
<strong>User Information: </strong>
<div align="right"><font color="red">*</font>Denotes Required Field</div>
<div align="left">
First Name<font color="red">*</font>:
<?php echo form_input($firstname)?>
<br/>
Last Name<font color="red">*</font>:
<?php echo form_input($lastname)?>
<br/>
Email Address<font color="red">*</font>:
<?php echo form_input($email)?>
<br/>
Date Of Birth:
<?php echo form_input($dateofbirth)?>
<br/>
Gender:
<?php
echo form_radio($gender, 'Male');
echo "Male";
echo form_radio($gender, 'Female');
echo "Female";
?>
<br/>
<strong>Account Information:</strong><br/>
Username<font color="red">*</font>:
<?php echo form_input($username)?><br/>
Password<font color="red">*</font>:
<?php echo form_password($password)?><br/>
Password Confirmation<font color="red">*</font>:
<?php echo form_password($confpass)?><br/>
<?php
echo validation_errors();?>
<?php echo form_submit(array('name'=>'register'), 'Register');?>
<?php echo form_reset(array('name'=>'reset'), 'Reset')?>
</div>
</body>
This is my user.php. I’m not really sure with the codes. these are mostly form tutorials i’ve seen..
class User extends CI_Controller {
private $view_data = array();
function _construct()
{
parent::_construct();
$this->view_data['base_url']=base_url();
}
function index()
{
$this->register();
}
function register()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|max_length[100]|min_length[1]|xss_clean');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|max_length[100]|min_length[1]|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|max_length[100]|xss_clean|valid_email');
$this->form_validation->set_rules('dateofbirth', 'Date of Birth', 'trim|max_length[100]|min_length[1]|xss_clean');
$this->form_validation->set_rules('gender', 'Gender', 'trim|max_length[6]|min_length[6]|xss_clean');
$this->form_validation->set_rules('username', 'User Name', 'trim|required|alpha_numeric|callback_username_not_exists|max_length[100]|min_length[6]|xss_clean');
if ($this->form_validation->run() == FALSE)
{
//not run
$this->load->view('view_register', $this->view_data);
}
else
{
//good
$firstname=$this->input->post('firstname');
$lastname=$this->input->post('lastname');
$email=$this->input->post('email');
$dateofbirth=$this->input->post('dateofbirth');
$gender=$this->input->post('gender');
$username=$this->input->post('username');
$password=$this->input->post('password');
$this->User_model->register_user($firstname, $lastname, $email, $dateofbirth, $gender, $username, $password);
}
$this->load->view('view_register', $this->view_data);
}
Then after that I am stuck. After clicking Register, It says Page404 Not Found, there’s not even a validation.
First. Find new tutorials, there is a lot of code in there that makes zero sense. I strongly suggest this series: http://net.tutsplus.com/sessions/codeigniter-from-scratch/
Next. You’re getting a page not found because your form action leads no where. In the line:
You’re trying to call a function in your controller called ‘start’ yet there is no function in your controller called start. The function is called register.
Next. You’re running the form validation before even seeing if there is any post data and you’re actually running it before there CAN be any post data.
You’re getting the form twice probably because you’re loading the same view into the page twice, once when the form validation fails, which it obviously will the first time you load then again when you’re calling your user model.
Quite honestly the only answer here is to nuke what you’ve done, reinstall CI and follow the tutorial series I gave you above. The tutorials you’re following are giving you very bad practices and you need to just forget what they’ve taught you. Follow the Nettuts tutorial one step at a time and make sure you’re understanding what it’s telling you before moving on. Don’t just copy and paste and cross your fingers.