No validation errors is shown online! - El Forum - 09-14-2007
[eluser]kruse[/eluser]
Hello,
This is a function to create a new user. It works perfectly fine offline on PHP5
but online on my server PHP4 it does not display validation errors on the form!
What can be wrong? I searched for hours : ) Please check the code.
Code: function do_signup()
{
///////////////////////////////////////////////////////////
//
// Get the language from the settings
//
///////////////////////////////////////////////////////////
$language = $this->config->item('site_language');
///////////////////////////////////////////////////////////
//
// Load the language files
//
///////////////////////////////////////////////////////////
$this->lang->load('signup', $language);
///////////////////////////////////////////////////////////
//
// Load the validation library
//
///////////////////////////////////////////////////////////
$this->load->library('validation');
///////////////////////////////////////////////////////////
//
// Validate the input
//
///////////////////////////////////////////////////////////
$rules['forname'] = "required|min_length[2]";
$rules['lastname'] = "required|min_length[2]";
$rules['email'] = "required|valid_email";
$rules['username'] = "required|callback_username_check";
$rules['password'] = "required|min_length[5]";
$this->validation->set_rules($rules);
///////////////////////////////////////////////////////////
//
// Set the validation items
//
///////////////////////////////////////////////////////////
$fields['forname'] = $this->lang->line('signup_forname');
$fields['lastname'] = $this->lang->line('signup_lastname');
$fields['email'] = $this->lang->line('signup_email');
$fields['username'] = $this->lang->line('signup_username');
$fields['password'] = $this->lang->line('signup_password');
$this->validation->set_fields($fields);
$this->validation->set_error_delimiters('<div class="field_error">', '</div>');
///////////////////////////////////////////////////////////
//
// Process the incoming fields
//
///////////////////////////////////////////////////////////
if ($this->validation->run() == FALSE)
{
///////////////////////////////////////////////////////////
//
// Get the language from the settings
//
///////////////////////////////////////////////////////////
$language = $this->config->item('site_language');
///////////////////////////////////////////////////////////
//
// Load the language file
//
///////////////////////////////////////////////////////////
$this->lang->load('navigation', $language);
$this->lang->load('signup', $language);
///////////////////////////////////////////////////////////
//
// Display the errors
//
///////////////////////////////////////////////////////////
$this->load->view('signup');
} else {
///////////////////////////////////////////////////////////
//
// Put the incoming date in variables
//
///////////////////////////////////////////////////////////
$pass = $_POST['password'];
$pass = dohash($pass,'md5');
$data = array(
'forname' => $_POST['forname'] ,
'lastname' => $_POST['lastname'] ,
'email' => $_POST['email'] ,
'username' => $_POST['username'] ,
'password' => $pass ,
'points' => 0 ,
'status' => 1
);
///////////////////////////////////////////////////////////
//
// Save the new post
//
///////////////////////////////////////////////////////////
$this->db->insert('profiles', $data);
///////////////////////////////////////////////////////////
//
// Redirect to previous page
//
///////////////////////////////////////////////////////////
redirect('login/form');
}
}
No validation errors is shown online! - El Forum - 09-14-2007
[eluser]kruse[/eluser]
The View:
Code: <?php $this->load->view('inc_header'); ?>
<body>
<div id="wrapper">
<div id="navigation_container">
<table cellpadding="0" cellspacing="0" id="navigation">
<tr>
<td>
<?php $this->load->view('inc_navigation'); ?>
</td>
</tr>
</table>
</div>
<div id="container">
<?php echo form_open('do_signup'); ?>
<div id="content_white">
{{info_main}}
</div>
<div id="content_pen">
<div class="input_container">
<div class="label">{{signup_forname}}</div>
<div class="input"><input type="text" class="textbox" name="forname" value="<?php if (isset($this->validation->forname)){ echo $this->validation->forname; } ?>" /></div>
<?php if (isset($this->validation->forname_error)){ echo $this->validation->forname_error; } ?>
</div>
<div class="input_container">
<div class="label">{{signup_lastname}}</div>
<div class="input"><input type="text" class="textbox" name="lastname" value="<?php if (isset($this->validation->lastname)){ echo $this->validation->lastname; } ?>" /></div>
<?php if (isset($this->validation->lastname_error)){ echo $this->validation->lastname_error; } ?>
</div>
<div class="input_container">
<div class="label">{{signup_email}}</div>
<div class="input"><input type="text" class="textbox" name="email" value="<?php if (isset($this->validation->email)){ echo $this->validation->email; } ?>" /></div>
<?php if (isset($this->validation->email_error)){ echo $this->validation->email_error; } ?>
</div>
<div class="input_container">
<div class="label">{{signup_username}}</div>
<div class="input"><input type="text" class="textbox" name="username" value="<?php if (isset($this->validation->username)){ echo $this->validation->username; } ?>" /></div>
<?php if (isset($this->validation->username_error)){ echo $this->validation->username_error; } ?>
</div>
<div class="input_container">
<div class="label">{{signup_password}}</div>
<div class="input"><input type="password" class="textbox" name="password" value="<?php if (isset($this->validation->password)){ echo $this->validation->password; } ?>" /></div>
<?php if (isset($this->validation->password_error)){ echo $this->validation->password_error; } ?>
</div>
<div class="input_container">
<div class="label"> </div>
<div class="input"><input type="submit" class="submit" value="{{signup_submit}}"></div>
</div>
<div class="clear"></div>
</div>
<?php $this->load->view('inc_footer'); ?>
</div>
</form>
</div>
</body>
</html>
No validation errors is shown online! - El Forum - 09-15-2007
[eluser]alpar[/eluser]
I don't think that this is the problem, just a tip, you don't need to check to see if the field values are checked, you can simply use echo $this->validation->fieldname,after you call the run() method, they get set with an empty string, it will make your views a bit cleaner
No validation errors is shown online! - El Forum - 09-15-2007
[eluser]kruse[/eluser]
Yeah, I tried it the "cleaner" way but the resulted in errors about empty strings or something so I had to do it this way : )
No validation errors is shown online! - El Forum - 09-15-2007
[eluser]alpar[/eluser]
I experienced that when it gives errors, there is a typo somewhere or you didn't set a field/rule for it. So that could be a potential problem
|