Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. public function configure()
  2. {
  3. $this->setWidgets(array(
  4. 'name' => new sfWidgetFormInput(),
  5. 'email' => new sfWidgetFormInput(),
  6. 'subject' => new sfWidgetFormInput(),
  7. 'message' => new sfWidgetFormTextarea(),
  8. //'captcha' => new sfWidgetFormAltCaptcha(),
  9. 'captcha' => new sfWidgetFormReCaptcha (array(
  10. 'public_key' => wtUtil::getConfig ('recaptcha_public_key'),
  11. )),
  12. ));
  13.  
  14. $this->widgetSchema->setLabels(array(
  15. 'name' => 'Su nombre',
  16. 'email' => 'Su e-mail',
  17. 'subject' => 'Asunto del mensaje',
  18. 'message' => 'Mensaje',
  19. 'captcha' => 'Código de verificación',
  20. ));
  21.  
  22. $required_message = array ('required' => 'Este campo es obligatorio. Rellénelo, por favor.');
  23. $length_message = array ('min_length' => 'Lo siento, debe introducir, al menos, %min_length% caracteres');
  24. $invalid_email = array ('invalid' => 'Debe introducir una dirección de correo electrónico válida.');
  25. $invalid_code = array ('captcha' => 'Código de verificación incorrecto');
  26.  
  27. $this->setValidators(array(
  28. 'name' => new sfValidatorString(array('required' => true,
  29. 'min_length' => 5,
  30. 'trim' => true), array_merge($required_message, $length_message)),
  31. 'email' => new sfValidatorEmail (array('trim' => true), array_merge($required_message, $invalid_email)),
  32. 'subject' => new sfValidatorString(array('required' => false,
  33. 'trim' => true), array_merge($required_message, $length_message)),
  34. 'message' => new sfValidatorString(array('min_length' => 10), array_merge($required_message, $length_message)),
  35. 'captcha' => new sfValidatorReCaptcha(array ('private_key' => wtUtil::getConfig ('recaptcha_private_key')),
  36. array_merge($required_message, $invalid_code)),
  37. ));
  38.  
  39.  
  40. $this->widgetSchema->setNameFormat('mailbox[%s]');
  41.  
  42. parent::configure();
  43. //unset ($this['response']);
  44. }
  45.  
  46. }
  47. public function executeMailbox (sfWebRequest $request)
  48. {
  49. $this->form = new MailBoxForm();
  50. $this->form_action = $this->getModuleName() . "/" . $this->getActionName();
  51.  
  52. if ($request->isMethod(sfRequest::POST))
  53. {
  54. $requestData = $request->getParameter ($this->form->getName());
  55. $this->form->bind($requestData);
  56. if ($this->form->isValid())
  57. {
  58. try
  59. {
  60. $message = $this->getMailer ()->compose(
  61. array ($this->form->getValue ('email') => $this->form->getValue('name') ), // from
  62. array (sfConfig::get('app_default_email') => wtUtil::getConfig ('default_email_as')),
  63. $this->form->getValue('subject'), //subject
  64. $this->form->getValue ('message') //body
  65. );
  66.  
  67. $mails = $this->getMailer()->send($message);
  68.  
  69. if ($mails)
  70. $this->getUser()->setFlash ('_notice', 'Mensaje enviado correctamente.');
  71. else
  72. $this->getUser()->setFlash ('_notice', 'No se ha enviado el mensaje.');
  73. }
  74. catch (Exception $e)
  75. {
  76. $this->getUser()->setFlash ('_notice', 'Error al enviar el mensaje');
  77. }
  78. }
  79.  
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement