Re: how to display validation error messages

2009-01-28 Thread Miles J

Or: 
http://www.milesj.me/blog/read/10/displaying-form-errors-as-a-list-in-cakephp
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: how to display validation error messages

2009-01-28 Thread brian

FormHelper will display the error. But it seems to depend upon how you
define your input. Sometimes, you need to explicitly set the error
element. I still haven't figured it out. Whenever I run into this, I
just add the following wherever I need it:

$form->error(FIELD_NAME);

Where FIELD_NAME, in this case, would be 'district'.


On Thu, Jan 29, 2009 at 1:04 AM, forrestgump  wrote:
>
> Hey guys,
>  Needed help with this one...seems as though it was never answered
> anywhere in the group so i think it will help a lot of people-
>
> I have a validation criteria in my Model defined as below:
> class District extends AppModel
> {
>
>  var $validate = array(
>'district' => array(
>'rule' => 'alphaNumeric',
>'message' => 'Error: Empty District Field',
>'allowEmpty' => false
>)
>
>   );
>
> }
>
> Now when the user inputs an empty district field, the save does not
> take place as expected. what I would like to do is to somehow print
> the 'message' --- 'Error: Empty District Field', that i supplied in
> the array above. I was expecting Cake to do it automatically but it
> seems iam wrong. Will appreciate any help given.
>
> Thanx again,
> Forrestgump
> >
>

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



how to display validation error messages

2009-01-28 Thread forrestgump

Hey guys,
  Needed help with this one...seems as though it was never answered
anywhere in the group so i think it will help a lot of people-

I have a validation criteria in my Model defined as below:
class District extends AppModel
{

  var $validate = array(
'district' => array(
'rule' => 'alphaNumeric',
'message' => 'Error: Empty District Field',
'allowEmpty' => false
)

   );

}

Now when the user inputs an empty district field, the save does not
take place as expected. what I would like to do is to somehow print
the 'message' --- 'Error: Empty District Field', that i supplied in
the array above. I was expecting Cake to do it automatically but it
seems iam wrong. Will appreciate any help given.

Thanx again,
Forrestgump
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Multiple inserts of the same model, how to display validation error messages?

2007-07-25 Thread oleonav

I have a form which gives the ability to add 3 records of the same
model in one go.

--
create('Content');?>
//First record
input('Content.use',array('type' =>
'hidden','value'=>'yes'));
echo $form->input('Content.title',array('error' => array(
'VALID_NOT_EMPTY'=>'Title is empty' )));
echo $form->input('Content.content');
?>

//record 2
input('Content_1.use',array('type' =>
'checkbox','value'=>'yes'));
echo $form->input('Content_1.title',array('error' => array(
'VALID_NOT_EMPTY'=>'Title is empty' )));
echo $form->input('Content_1.content');
?>

//record 3
input('Content_2.use',array('type' =>
'checkbox','value'=>'yes'));
echo $form->input('Content_2.title',array('error' => array(
'VALID_NOT_EMPTY'=>'Title is empty' )));
echo $form->input('Content_2.content');
?>
end('Submit');?>
etc...
--

When available the data the folowing $this->data array is available:


Array
(
[Content] => Array
(
[use] => yes
[title] => Some text
[content] => fdddf dfdf
)

[Content_1] => Array
(
[use] => yes
[title] => Some text for record 2
[content] => dsds
)

[Content_2] => Array
(
[use] => yes
[title] =>
[content] => ds
)
)


In the add controller action I use the folowing code to do validation
on a record if the key 'use' is set to yes. If 'use' is not set then
no validation is required and the record will not be added to the db.


function add(){
if (!empty($this->data)) {
$this->cleanUpFields();

//check first record of model 'Content'
$this->Content->create();
$this->Content->data = $this->data;

//if record one validates then check the rest of them
if($this->Content->validates() == true){
foreach($this->data as $key => $val){
if($key != 'Content' && $val['use'] == 'yes'){
$this->Content->create();
//fed data of record 2 or 3 to the model
$this->Content->data = $val;
if($this->Content->validates() == true){
echo $key . ' is OK';
}
else{
echo $key . ' has errors';

}

}
}
echo 'OK';

//record saving code to be added...

}

else{
echo 'ERROR';
}

}
}

---
Validation of all records will happen. The echo statements are pure
for debugging purposes.

When validation fails on one of the records with the status 'use' =
'yes', the form will be presented again, complete with all the values
in it. Ok

My problem is; How do I get the error messages in the view for records
2 & 3??? The error messages for record 1, where fields are named after
the model, behave like expected, with error messages in place.

Thanks,


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---