Thank you for you reply, Rob.
I simplified things trying to get the troubleshooting more easy. I
created
a model, and a view with only one field, first_name. I also created
an
add function in the controller which is supposed to validate input
rather
then saving data to the database. The problem remains and I get
redirected
back to the form, where a label Valid characters: letters and numbers
only, please try again is attached to the field.
The view:
?php
div class=leads form
?php echo $form-create('Lead');?
fieldset
legend?php __('Add Lead');?/legend
?php
echo $form-input('first_name'); ?
/fieldset
?php echo $form-end('Submit');
pr($this-validationErrors);
pr($session);
?
The model:
?php
class Lead extends AppModel {
var $name = 'Lead';
var $validate = array(
'first_name' = array(
'alphaNumeric' = array(
'rule' = 'alphaNumeric',
'required' = true,
'message' = 'Valid characters: letters and numbers only,
please try
again.'
)));
}
?
The add function in the controller:
function add() {
if (!empty($this-data)) {
if ($this-RequestHandler-isPost()) {
$this-Lead-create();
$this-Lead-set($this-data);
Debugger::dump($this-data['Lead']);
Debugger::dump($this-Lead-validationErrors);
Debugger::dump($this-Lead-invalidFields());
Debugger::dump($this-Lead-validate);
if ($this-Lead-validates()) {
$this-_sendMail();
$this-Session-setFlash(__('The Lead
has been saved', true));
$this-redirect(array('action'='index'));
} else {
$this-Session-setFlash(__('The Lead
could not be saved. Please,
try
again.', true));
}
}
}
}
Output from the Debugger statements in the add function:
array(
first_name = Paul
)
array()
array(
first_name = Valid characters: letters and numbers only, please
try
again.
)
array(
first_name = array()
)
Dump of the SessionHelper Object:
SessionHelper Object
(
[helpers] =
[__active] = 1
[valid] =
[error] =
[_userAgent] = 372acfb5aa1873a6a6ce218959a07d36
[path] = /
[lastError] =
[security] =
[time] = 1229549419
[sessionTime] =
[watchKeys] = Array
(
)
[id] =
[_log] =
[base] = /somepath
[webroot] = /somepath/
[here] = /somepath/leads/add
[params] = Array
(
[pass] = Array
(
)
[named] = Array
(
)
[controller] = leads
[action] = add
[plugin] =
[form] = Array
(
)
[data] = Array
(
[Lead] = Array
(
[first_name] = Paul
)
)
[url] = Array
(
[url] = leads/add
)
[isAjax] =
[models] = Array
(
[0] = Lead
)
)
[action] = add
[data] = Array
(
[Lead] = Array
(
[first_name] = Paul
)
)
[themeWeb] =
[plugin] =
[validationErrors] = Array
(
[Lead] = Array
(
[first_name] = Valid characters: letters and
numbers
only, please try again.
)
)
)
On 17 Dec, 20:03, Rob webwe...@gmail.com wrote:
Without looking at your data model, I can't say for sure, but it would
seem like you may be breaking a rule that is implied by the table.
That said, you might want to add a message to your $validate like:
'last_name' = array(
'alphaNumeric' = array(
'rule' = 'alphanumeric',
'message' = 'Only letters and numbers for last
name, please try again.'
),
)
On Dec 17, 2:56 am, Oribium viktor.richard...@gmail.com wrote:
I am taking a look at cake 1.2, and I run into problems with the
validation
of form data. I took advantage of the console application to bake some
views, a model, and a controller based on an existing MySQL-database.
I
don't yet have a deep understanding of cake, and would happily welcome
hints and pointers which direction I should go.
I am trying to post data from a form to a database. However, whatever
data
I post, I get