I have been creating a basic CRUD app for an "employees" database.

>From my "index" page, I click on an employees name and it takes me to
the "edit" screen.

That would take me to www.exampledomain.com/employees/edit/22  (where
the employees unique id in the db is "22")

One of the database fields is "email", and it has an "email"
validation setup in the Employee model.

If I try to change the email to a purposely invalid email, I do get
the notification about invalid email string, and my url location is
still www.exampledomain.com/employees/edit/22

Now when I correct the invalid email, and re-submit the form, my url
switches to www.exampledomain.com/employees/edit , i get a message
that the employee has been updated, however it actually ADDS a new
employee, as if the id got lost/disconnected.

Here is the relevant code:

=================================================
models/employee.php:

class Employee extends AppModel
{
    var $name = 'Employee';
        var $validate = array(
                'first_name' => array(
                        'rule' => array('minLength', 1)
                ),
                'last_name' => array(
                        'rule' => array('minLength', 1)
                ),
                'email' => array(
                        'rule' => array('email', true),
                        'message' => 'Please supply a valid email address.'
                )
        );
}

=================================================
controllers/employees_controller.php:

function edit($id = null) {
                $this->Employee->id = $id;
                if (empty($this->data)) {
                        $this->data = $this->Employee->read();
                } else {
                        if ($this->Employee->save($this->data['Employee'])) {
                                $this->flash('The employee has been 
updated.','/employees');
                        }
                }
        }

=================================================
views/employees/edit.ctp:

echo $form->create('Employee', array('action' => 'edit'));
echo $form->input('first_name');
echo $form->input('last_name');
echo $form->input('title');
echo $form->input('email');
echo $form->input('cell');
echo $form->input('extension');
echo $form->end('Edit Employee');


=================================================
System Specs:
- cake_1.2.0.6311-beta
- Mac OSX
- PHP Version 5.2.5
- MySQL client version: 5.0.41
- Apache 1.3.41

Thanks in advance!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to