/** * 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(); }
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; }
$this->setWidget('body', new sfWidgetFormTextarea()); $this->setValidator('body', new sfValidatorString(array('min_length' => 12))); } } $configuration = $configuration->getApplicationConfiguration('frontend', 'test', true, null, $configuration->getEventDispatcher()); sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir')); $enhancer = new sfFormYamlEnhancerTest($configuration->getConfigCache()); // ->enhance() $t->diag('->enhance()'); $form = new CommentForm(); $form->bind(array('body' => '+1')); $enhancer->enhance($form); $t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() enhances labels'); $t->like($form['body']->render(), '/class="comment"/', '->enhance() enhances widgets'); $t->like($form['body']->renderError(), '/You haven\'t written enough/', '->enhance() enhances error messages'); $form = new CommentForm(); $form->bind(); $enhancer->enhance($form); $t->like($form['body']->renderError(), '/A base required message/', '->enhance() considers inheritance'); class SpecialCommentForm extends CommentForm { } $form = new SpecialCommentForm(); $form->bind(); $enhancer->enhance($form); $t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() applies parent config'); $form = new BaseForm(); $form->embedForm('comment', new CommentForm()); $form->bind(); $enhancer->enhance($form); $t->like($form['comment']['body']->renderLabel(), '/Please enter your comment/', '->enhance() enhances embedded forms');
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; } }
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'); }