Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * contact actions.
- *
- * @package peanut
- * @subpackage contact
- * @author Your name here
- * @version SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
- */
- class contactActions extends sfActions
- {
- /**
- * Executes index action
- *
- * @param sfRequest $request A request object
- */
- public function executeIndex(sfWebRequest $request)
- {
- $this->form = new DocumentForm();
- if ($request->isMethod('post')) {
- $this->form->bind($request->getParameter('contact'), $request->getFiles('contact'));
- if ($this->form->isValid()) {
- $file1 = $this->form->getValue('file1');
- $filename = $this->form->getValue('society').'-'.$file1->getOriginalName();
- $extension = $file1->getExtension($file1->getOriginalExtension());
- $file1->save(sfConfig::get('sf_upload_dir').'/utiles/'.$filename.$extension);
- $this->redirect('contact/thankyou.html');
- }
- }
- }
- public function executeThankyou()
- {
- }
- public function execute404()
- {
- }
- }
- <?php
- class DocumentForm extends sfForm
- {
- public function configure() {
- $this->setWidgets(array(
- 'lastname' => new sfWidgetFormInput(),
- 'firstname' => new sfWidgetFormInput(),
- 'society' => new sfWidgetFormInput(),
- 'fonction' => new sfWidgetFormInput(),
- 'email' => new sfWidgetFormInput(),
- 'message' => new sfWidgetFormTextarea(),
- 'file1' => new sfWidgetFormInputFile(),
- 'file2' => new sfWidgetFormInputFile(),
- 'file3' => new sfWidgetFormInputFile(),
- 'file4' => new sfWidgetFormInputFile(),
- 'file5' => new sfWidgetFormInputFile(),
- ));
- $this->widgetSchema->setNameFormat('contact[%s]');
- $this->widgetSchema->setLabels(array(
- 'lastname' => 'Nom',
- 'firstname' => 'Prénom',
- 'society' => 'Société',
- 'fonction' => 'Fonction',
- 'email' => 'Adresse mail',
- 'message' => 'Votre message',
- 'file1' => 'Fichiers',
- ));
- $this->setValidators(array(
- 'lastname' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Nom" est obligatoire.')),
- 'firstname' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Prénom" est obligatoire.')),
- 'society' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Société" est obligatoire.')),
- 'fonction' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Fonction" est obligatoire.')),
- 'file1' => new sfValidatorFile(array('required' => true), array('required' => 'Les champs "Fichiers" sont obligatoires.')),
- 'file2' => new sfValidatorFile(),
- 'file3' => new sfValidatorFile(),
- 'file4' => new sfValidatorFile(),
- 'file5' => new sfValidatorFile(),
- 'email' => new sfValidatorEmail(array('required' => true), array('required' => 'Le champ "email" est obligatoire.', 'invalid' => 'L\'adresse mail "%value%" est invalide.')),
- 'message' => new sfValidatorString(array('min_length' => 4), array('required' => 'Le champ "message" est obligatoire.', 'min_length' => 'Le message est trop court. Il faut moins %min_length% caractères.')),
- ));
- $this->validatorSchema->setOption('allow_extra_fields', true);
- $this->validatorSchema->setOption('filter_extra_fields', false);
- }
- }
Add Comment
Please, Sign In to add comment