21286 Posts in 5733 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 3297 Views |
-
Required Fields in CMS - has_one, has_many

24 June 2010 at 7:59am
Is there a way to have a has_one or has_many be required in the CMS? For example, I want to force a user to upload an image for a page. Additionally, is there any documentation on validating data in the CMS?
-
Re: Required Fields in CMS - has_one, has_many

24 June 2010 at 9:46am
Have you tried making it a required field when you create the CMS form field for the image in getCMSFields()?
I've never tried that with any CMS fields before so not sure how it'd work!Rich
-
Re: Required Fields in CMS - has_one, has_many

25 June 2010 at 2:02am Last edited: 25 June 2010 2:11am
when I do this
public function getCMSValidator() {
return new RequiredFields('Date', 'Time', 'Location', 'Image');
}I always get a validation error on image - even if there is one. if I remove image from the required fields everything is groovy. I also have some related dataobjects I need to check for.
also, there is documentation of public facing form validation - but what about CMS validation? that's what I'm most concerned about - even the best trained people make mistakes - I'd like to catch them.
-
Re: Required Fields in CMS - has_one, has_many

26 June 2010 at 6:04am
nothing? this is a pretty important thing for insuring content editors don't make mistakes...
-
Re: Required Fields in CMS - has_one, has_many

9 July 2010 at 2:56am
bumping this up - nobody has any ideas? is there any documentation at all on setting up data validation in the CMS?
-
Re: Required Fields in CMS - has_one, has_many

9 July 2010 at 3:10am
How about making a validator....
inside MyDataObject.php
function getCMSValidator()
{
return new MyValidator();
}calls MyValidator.php
class MyValidator extends Validator
{
function javascript()
{
return false;
}function php($data)
{
$bRet = true;//do some validation on the data
if ($data['HasOneID'] SOME VALIDATION HERE)
{
$this->validationError(
'HasOneID',
'Some message here',
"required"
);$bRet = false;
}return $bRet;
}
}Hope this helps...
Barry
-
Re: Required Fields in CMS - has_one, has_many

9 July 2010 at 3:38am
Thanks for the help, but I have a few more questions ;-)
First, when I put the class in a new file it wasn't finding it - is there an include statement I need to put in someplace? Second, when I tried it with a normal text value it worked, but when I tried with my Image it doesn't work. I tried both 'Image' and 'ImageID' - any suggestions?
Also, is there anyway to do a javascript alert?
class MyValidator extends Validator{
function javascript(){
return false;
}function php($data){
$bRet = true;//do some validation on the data
if (!$data['Image']){
$this->validationError(
'Image',
'We need an image',
"required"
);$bRet = false;
}return $bRet;
}
} -
Re: Required Fields in CMS - has_one, has_many

9 July 2010 at 4:44am
1) if your class name is the same as your file name it will auto load it. Never had problems with that.
2) if this is your dataobject...static $has_one = array('MyImage' => 'Image');
I'd expect it to be...
$data['MyImageID']
but to be sure, turn the site to dev mode, enable logging and send $data to the logger and have a look at it
| 3297 Views | ||
| Go to Top | Next > |


