[eluser]GregX999[/eluser]
I'm still confused...
When I print_r the class instead of saving it, the fields array does not contain "confirm_password". Do I need to add that field to the database for that to work?
This is a sign-up form, so the object is an empty object that I assign screen_name, email and password to and then try to save. But yes, you are correct in that I only get the "Unable to access an error message corresponding to your field name." error when the password does not validate (empty OR just not passing my validation function) - if the password validates, I don't get that error. But I don't get any error if my password validates but the confirm password does not match (it should give an error saying it doesn't match).
Here's the entire first part of my User class:
class User extends DataMapper
{
var $created_field = 'created_on';
var $validation = array(
array(
'field' => 'screen_name',
'label' => 'Screen Name',
'rules' => array('required', 'trim', 'min_length' => 2, 'max_length' => 100, 'unique')
),
array(
'field' => 'url_name',
'label' => 'URL Name',
'rules' => array('make_url_name')
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => array('valid_password', 'required', 'trim')
),
array(
'field' => 'confirm_password',
'label' => 'Confirm Password',
'rules' => array('matches' => 'password')
),
array(
'field' => 'email',
'label' => 'Email',
'rules' => array('required', 'trim', 'unique', 'valid_email')
)
);
function User($new_data='')
{
parent:
ataMapper();
if($new_data)
{
$this->set_data($new_data);
}
}
// --------------------------------------------------------------------
/**
* Set Data
*
* Sets an array of data based on $this->manual_fields
*
* @access public
* @param array[$new_Data]
* @return true
*/
function set_data($new_data)
{
if(is_array($new_data))
{
foreach($this->fields as $f)
{
if($new_data[$f])
{
$this->$f = $new_data[$f];
}
}
return true;
}
else
{
return false;
}
}
}
This is from my Users controller:
public function signup()
{
$data['page_title'] = "New Member Sign-up";
$u = new User($_POST);
if($_POST)
{
if($u->save())
{
echo '<p>You have successfully registered</p>';
exit;
}
else
{
$data['error_messages'][] = $u->error->string;
}
}
$data['form_errors'] = $u->error;
$this->view->render($data, 'member', 'signup');
}
And the entire HTML form:
<?= form_open('/signup'); ?>
<? $label_width = "6em"; ?>
<div class="field_row">
<?= form_label('Choose a Screen Name', 'screen_name'); ?>
<?= form_input(array('name' => 'screen_name', 'value' => set_value('screen_name'), 'class' => 'focus_me field' . $form_errors->screen_name ? ' error' : '')); ?>
x<?= set_value('screen_name') ?>x
</div>
<div class="field_row">
<?= form_label('Your Email Address', 'email'); ?>
<?= form_input(array('name' => 'email', 'value' => set_value('email'), 'class' => 'field' . $form_errors->email ? ' error' : '')); ?>
</div>
<div class="field_row">
<?= form_label('Choose a Password', 'password'); ?>
<?= form_password(array('name' => 'password', 'value' => set_value('password'), 'class' => 'field' . $form_errors->password ? ' error' : '')); ?>
</div>
<div class="field_row">
<?= form_label('Confirm Password', 'confirm_password'); ?>
<?= form_password(array('name' => 'confirm_password', 'value' => set_value('confirm_password'), 'class' => 'field' . $form_errors->confirm_password ? ' error' : '')); ?>
</div>
<div class="field_row">
<label class="hidden"> </label>
<?= form_submit('signup', 'Sign-Up'); ?>
</div>
<?= form_close(); ?>