I am newbie baker. I was following the quickwall tutorial from the
book "CakePHP Application Development". I got stuck at the Form
Validation part. The situation is, when the validation conditions are
met, the data is successfully added to the database but if there is
any input error, what I get is a blank page. The Input form or the
error massage is not showing. Please have a look at the code and guide
me. Any help is really apreciated.
Thank You
Model Question
<?php
class Question extends AppModel
{
var $name = 'Question';
var $hasMany = array(
'Answer' => array(
'className' => 'Answer'
)
);
var $validate = array(
'question' => array(
'rule' => array('minLength','1'),
'required' => true,
'allowEmpty' => false,
'message' => 'Question cannot be empty.'
),
'questioner' => array(
'rule' => array('minLenght','1'),
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter your name.'
)
);
}
?>
Form part of the View
<?php echo $form->error('Question.question', null, array('class' =>
'message')); ?>
<?php echo $form->error('Question.questioner', null, array('class' =>
'message')); ?>
<?php echo $form->create('Question', array('action' => 'home'));?>
<fieldset>
<label for="QuestionQuestion" class="questionlabel">
<span>Your Question</span></label>
<?php echo $form->text('question', array('class' => 'fullwidth')); ?
><span class="big">?</span>
<label for="QuestionQuestioner" class="questionerlabel"><span>Your
Name</span></label>
<?php echo $form->text('questioner', array('class' => 'halfwidth')); ?
>
<?php echo $form->submit('Post Your Question', array('div' => false,
'class' => 'submitbutton')); ?>
</fieldset>
<?php echo $form->end(); ?>
Controller "Home" Action
function home()
{
if(!empty($this->data)){
$this->Question->create();
if($this->Question->save($this->data)){
$this->Session->setFlash('Your Question has been
Saved');
$this->redirect(array('action' => 'home'),null,true);
}else{
$this->setFlash('The question couldnot be save, Please
try again.');
}
}
$this->Question->recursive = 1;
$questions = $this->Question->find('all');
$this->set('questions',$questions);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---