I baked Model, Controller, and Views for my Organization table. It is
basically a standard User table, and my functions are virtually
unchanged from baking.

Then I added validation to various fields and added error messages for
the validations in my add.ctp and edit.ctp files.

Now when I edit an Organization (see HTML [1]), if I enter proper
values for all the fields, the edit goes thru fine. When I leave out a
required field or do something that fails validation, Cake brings me
back to the form showing "Edit Organization" but the HTML [2] shows
that I'm actually adding an Organization. I have included HTML below,
as well as the edit() function [3].

So when I make a change to the field and submit, instead of going in
as an edit, it calls add which fails due to duplicate indexes (the
userid field).

Any ideas??
Wayne

[1]
<div class="organization">
<form id="OrganizationEditForm" method="post"
action="/cake/organizations/edit/20"><fieldset
style="display:none"><input type="hidden" name="data[__Token][key]"
value="e388b4d13f9e4c1d5cdf1d63612e1e5aa62db978"
id="OrganizationEditFormToken936739629" /></fieldset>   <fieldset>
<legend>Edit Organization</legend>

[2]
<div id="flashMessage" class="message">The Organization could not be
saved. Please try again.</div><div class="organization">
<form id="OrganizationAddForm" method="post"
action="/cake/organizations/add/"><fieldset
style="display:none"><input type="hidden" name="data[__Token][key]"
value="e2d7ac5c821aca68b05079b1e65746aaf773ad11"
id="OrganizationAddFormToken1675815126" /></fieldset>   <fieldset>
<legend>Edit Organization</legend>

[3]
function edit($id = null) {
        $this->log(__FILE__ . ':' . __METHOD__ . ": init.", LOG_DEBUG);
        if (!$id && empty($this->data)) {
                $this->Session->setFlash('Invalid Organization');
                $this->redirect(array('action'=>'index'), null, true);
        }
        if (!empty($this->data)) {
                $this->cleanUpFields();
                if ($this->Organization->save($this->data)) {
                        $this->Session->setFlash('The Organization has been 
updated.');
                        $this->redirect(array('action'=>'index'), null, true);
                } else {
                        $this->Session->setFlash('The Organization could not be 
saved.
Please try again.');
                }
        }
        if (empty($this->data)) {
                $this->data = $this->Organization->read(null, $id);
        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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