Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function configure()
- {
- $this->setWidgets(array(
- 'name' => new sfWidgetFormInput(),
- 'email' => new sfWidgetFormInput(),
- 'subject' => new sfWidgetFormInput(),
- 'message' => new sfWidgetFormTextarea(),
- //'captcha' => new sfWidgetFormAltCaptcha(),
- 'captcha' => new sfWidgetFormReCaptcha (array(
- 'public_key' => wtUtil::getConfig ('recaptcha_public_key'),
- )),
- ));
- $this->widgetSchema->setLabels(array(
- 'name' => 'Su nombre',
- 'email' => 'Su e-mail',
- 'subject' => 'Asunto del mensaje',
- 'message' => 'Mensaje',
- 'captcha' => 'Código de verificación',
- ));
- $required_message = array ('required' => 'Este campo es obligatorio. Rellénelo, por favor.');
- $length_message = array ('min_length' => 'Lo siento, debe introducir, al menos, %min_length% caracteres');
- $invalid_email = array ('invalid' => 'Debe introducir una dirección de correo electrónico válida.');
- $invalid_code = array ('captcha' => 'Código de verificación incorrecto');
- $this->setValidators(array(
- 'name' => new sfValidatorString(array('required' => true,
- 'min_length' => 5,
- 'trim' => true), array_merge($required_message, $length_message)),
- 'email' => new sfValidatorEmail (array('trim' => true), array_merge($required_message, $invalid_email)),
- 'subject' => new sfValidatorString(array('required' => false,
- 'trim' => true), array_merge($required_message, $length_message)),
- 'message' => new sfValidatorString(array('min_length' => 10), array_merge($required_message, $length_message)),
- 'captcha' => new sfValidatorReCaptcha(array ('private_key' => wtUtil::getConfig ('recaptcha_private_key')),
- array_merge($required_message, $invalid_code)),
- ));
- $this->widgetSchema->setNameFormat('mailbox[%s]');
- parent::configure();
- //unset ($this['response']);
- }
- }
- public function executeMailbox (sfWebRequest $request)
- {
- $this->form = new MailBoxForm();
- $this->form_action = $this->getModuleName() . "/" . $this->getActionName();
- if ($request->isMethod(sfRequest::POST))
- {
- $requestData = $request->getParameter ($this->form->getName());
- $this->form->bind($requestData);
- if ($this->form->isValid())
- {
- try
- {
- $message = $this->getMailer ()->compose(
- array ($this->form->getValue ('email') => $this->form->getValue('name') ), // from
- array (sfConfig::get('app_default_email') => wtUtil::getConfig ('default_email_as')),
- $this->form->getValue('subject'), //subject
- $this->form->getValue ('message') //body
- );
- $mails = $this->getMailer()->send($message);
- if ($mails)
- $this->getUser()->setFlash ('_notice', 'Mensaje enviado correctamente.');
- else
- $this->getUser()->setFlash ('_notice', 'No se ha enviado el mensaje.');
- }
- catch (Exception $e)
- {
- $this->getUser()->setFlash ('_notice', 'Error al enviar el mensaje');
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement