本文整理汇总了PHP中CommentForm::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP CommentForm::isValid方法的具体用法?PHP CommentForm::isValid怎么用?PHP CommentForm::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommentForm
的用法示例。
在下文中一共展示了CommentForm::isValid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeDoAdd
/**
* executeDo_add_new_comment
*
* @access public
* @return void
*/
public function executeDoAdd(sfWebRequest $request)
{
// Pull associated model
$record_id = $request->getParameter('record_id');
$model = $request->getParameter('model');
$this->record = Doctrine::getTable($model)->find($record_id);
$commentForm = new CommentForm();
$commentForm->bind($request->getParameter('comment'));
// return bound form with errors if form is invalid
if (!$commentForm->isValid()) {
return $this->renderPartial('csComments/add_comment', array('commentForm' => $commentForm));
}
// save the object
/* SHOULD USE IMBEDDED FORMS
Used this hack instead. Need to fix
-B.Shaffer
*/
$commentVals = $commentForm->getValues();
$commenter = new Commenter();
$commenter->fromArray($commentVals['Commenter']);
$commenter->save();
$comment = new Comment();
$comment['body'] = $commentVals['body'];
$comment['Commenter'] = $commenter;
$comment->save();
$this->comment = $comment;
// Pass parent comment id if comment is nested
$parent_id = $this->getRequestParameter('comment_id');
$this->record->addComment($this->comment, $parent_id);
$this->record->save();
}
示例2: executeFormWidget
public function executeFormWidget(dmWebRequest $request)
{
$form = new CommentForm();
if ($request->isMethod('post')) {
$captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'));
$form->bind(array_merge($request->getParameter($form->getName()), array('captcha' => $captcha)));
if ($form->isValid()) {
$form->save();
$this->getUser()->setFlash('form_saved', true);
$this->redirectBack();
}
}
$this->forms['Comment'] = $form;
}
示例3: executeComment
public function executeComment(sfWebRequest $request)
{
$comment = new Comment();
$comment->setTicketId($request->getParameter('id'));
$form = new CommentForm($comment);
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$this->getUser()->setFlash('message', array('success', 'Отлично!', 'Комментарий добавлен.'));
$comment = $form->save();
$this->redirect('@tickets-show?id=' . $comment->getTicketId());
} else {
//$this->redirect('@tickets-show?id=' . $request->getParameter('id'));
$this->form = $form;
}
}
示例4: executeUpdate
public function executeUpdate($request)
{
$object = $this->getRequestParameter('object');
$user = User::getByApiKey($request->getParameter('login_id'), $request->getParameter('api_key'));
if (!$user) {
$output = '<rsp stat="fail"><err code="2" msg="login_id and api_key do not match" /></rsp>';
} elseif ($object == 'application') {
$form = new ApplicationForm();
$form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url')));
if ($form->isValid()) {
$application = Application::update($form->getValues(), $user);
if ($application) {
$output = '<rsp stat="ok">' . $application->getXML() . '</rsp>';
} else {
$output = '<rsp stat="fail"><err code="4" msg="Unable to update application." /></rsp>';
}
} else {
$output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
}
} elseif ($object == 'comment') {
$form = new CommentForm();
$application_id = $module_id = $theme_id = null;
if ($request->getParameter('application_id')) {
$application_id = $request->getParameter('application_id');
}
if ($request->getParameter('module_id')) {
$module_id = $request->getParameter('module_id');
}
if ($request->getParameter('theme_id')) {
$theme_id = $request->getParameter('theme_id');
}
$form->bind(array('comment' => $request->getParameter('comment'), 'application_id' => $application_id, 'module_id' => $module_id, 'theme_id' => $theme_id));
if ($form->isValid()) {
$comment = Comment::update($form->getValues(), $user);
$output = '<rsp stat="ok">' . $comment->getXML() . '</rsp>';
} else {
$output = '<rsp stat="fail"><err code="3" msg="' . $form->getErrorSchema() . '" /></rsp>';
}
} elseif ($object == 'module') {
$form = new ModuleForm();
$form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url'), 'application_id' => $request->getParameter('application_id')));
if ($form->isValid()) {
$module = Madule::update($form->getValues(), $user);
if ($module) {
$output = '<rsp stat="ok">' . $module->getXML() . '</rsp>';
} else {
$output = '<rsp stat="fail"><err code="4" msg="Unable to update module." /></rsp>';
}
} else {
$output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
}
} elseif ($object == 'theme') {
$form = new ThemeForm();
$form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description')), $request->getFiles());
if ($form->isValid()) {
$theme = Theme::update($form->getValues(), $user);
if ($theme) {
$output = '<rsp stat="ok">' . $theme->getXML() . '</rsp>';
} else {
$output = '<rsp stat="fail"><err code="5" msg="Unable to update theme." /></rsp>';
}
} else {
$output = '<rsp stat="fail"><err code="5" msg="' . $form->getErrorSchema() . '" /></rsp>';
}
} elseif ($object == 'theme_group') {
$output = '<rsp stat="fail"><err code="6" msg="This object is not supported for update" /></rsp>';
} elseif ($object == 'user') {
$form = new UserForm();
$form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'password' => $request->getParameter('password'), 'password2' => $request->getParameter('password'), 'email' => $request->getParameter('email'), 'role' => null));
if ($form->isValid()) {
$update_user = User::update($form->getValues(), $user);
if ($update_user) {
$output = '<rsp stat="ok">' . $update_user->getXML() . '</rsp>';
} else {
$output = '<rsp stat="fail"><err code="7" msg="Unable to update user." /></rsp>';
}
} else {
$output = '<rsp stat="fail"><err code="7" msg="' . $form->getErrorSchema() . '" /></rsp>';
}
}
$this->output = $output;
$this->setTemplate('index');
}