flashmessengerヘルパープラグインを使用して、簡単な連絡先ページを作成しようとしています。
私は以下のように実装しましたが、私の問題は、ページに表示されるフラッシュメッセージを取得するためにフォームを 2 回送信する必要があることです。
ここで私が間違っていること..
- 最初の送信時にメッセージを表示しますか?
- 送信後にフォームを非表示にするにはどうすればよいですか?
私のコントローラーで
// Add content to this method:
public function contactAction()
{
$form = new ContactForm();
$form->get('submit')->setValue('Submit');
$request = $this->getRequest();
if ($request->isPost()) {
$contact = new Contact();
$form->setInputFilter($contact->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$data=$form->getData();
//var_dump($data);
$mail = new Mail\Message();
$mail->setBody($data['comment'])
->setFrom($data['email'], $data['name'])
->addTo(IEMAIL, COMPANY )
->addReplyTo($data['email'], $data['name'])
->setSubject($data['subject']);
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
$this->flashMessenger()->addMessage('Thanks you for the submission ');
}
else{
$this->flashMessenger()->addMessage('Opps somethinge went wrong ..!');
}
}
/**/
return new ViewModel(array(
'customMessage' => 'Welcome to the sales',
'form' => $form
));
}
私の見解では、コーディングは次のとおりです
<?php
$title = 'Contact Us';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<?php echo $this->customMessage ?>
<?php
if ($this->flashMessenger()->hasMessages()):
echo $this->flashMessenger()->render('success', array('alert', 'alert-danger'));
// In any of your .phtml files:
$flash = $this->flashMessenger();
$flash->setMessageOpenFormat('<div%s>
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
×
</button>
<ul><li>')
->setMessageSeparatorString('</li><li>')
->setMessageCloseString('</li></ul></div>');
echo $flash->render('error', array('alert', 'alert-dismissable', 'alert-danger'));
echo $flash->render('info', array('alert', 'alert-dismissable', 'alert-info'));
echo $flash->render('default', array('alert', 'alert-dismissable', 'alert-warning'));
echo $flash->render('success', array('alert', 'alert-dismissable', 'alert-success'));
?>
<? endif ?>
<?php
$form->setAttribute('action', $this->url('contact', array('action' => 'submit')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('name'));
echo $this->formRow($form->get('email'));
echo $this->formRow($form->get('subject'));
echo $this->formRow($form->get('comment'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();