Guest User

Untitled

a guest
Jul 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * contact actions.
  5. *
  6. * @package peanut
  7. * @subpackage contact
  8. * @author Your name here
  9. * @version SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
  10. */
  11. class contactActions extends sfActions
  12. {
  13. /**
  14. * Executes index action
  15. *
  16. * @param sfRequest $request A request object
  17. */
  18.  
  19. public function executeIndex(sfWebRequest $request)
  20. {
  21. $this->form = new DocumentForm();
  22.  
  23. if ($request->isMethod('post')) {
  24. $this->form->bind($request->getParameter('contact'), $request->getFiles('contact'));
  25. if ($this->form->isValid()) {
  26.  
  27. $file1 = $this->form->getValue('file1');
  28. $filename = $this->form->getValue('society').'-'.$file1->getOriginalName();
  29. $extension = $file1->getExtension($file1->getOriginalExtension());
  30. $file1->save(sfConfig::get('sf_upload_dir').'/utiles/'.$filename.$extension);
  31.  
  32.  
  33. $this->redirect('contact/thankyou.html');
  34. }
  35. }
  36. }
  37.  
  38.  
  39. public function executeThankyou()
  40. {
  41. }
  42.  
  43. public function execute404()
  44. {
  45.  
  46. }
  47.  
  48. }
  49.  
  50.  
  51. <?php
  52.  
  53. class DocumentForm extends sfForm
  54. {
  55.  
  56. public function configure() {
  57. $this->setWidgets(array(
  58. 'lastname' => new sfWidgetFormInput(),
  59. 'firstname' => new sfWidgetFormInput(),
  60. 'society' => new sfWidgetFormInput(),
  61. 'fonction' => new sfWidgetFormInput(),
  62. 'email' => new sfWidgetFormInput(),
  63. 'message' => new sfWidgetFormTextarea(),
  64. 'file1' => new sfWidgetFormInputFile(),
  65. 'file2' => new sfWidgetFormInputFile(),
  66. 'file3' => new sfWidgetFormInputFile(),
  67. 'file4' => new sfWidgetFormInputFile(),
  68. 'file5' => new sfWidgetFormInputFile(),
  69. ));
  70.  
  71. $this->widgetSchema->setNameFormat('contact[%s]');
  72.  
  73. $this->widgetSchema->setLabels(array(
  74. 'lastname' => 'Nom',
  75. 'firstname' => 'Prénom',
  76. 'society' => 'Société',
  77. 'fonction' => 'Fonction',
  78. 'email' => 'Adresse mail',
  79. 'message' => 'Votre message',
  80. 'file1' => 'Fichiers',
  81. ));
  82.  
  83. $this->setValidators(array(
  84. 'lastname' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Nom" est obligatoire.')),
  85. 'firstname' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Prénom" est obligatoire.')),
  86. 'society' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Société" est obligatoire.')),
  87. 'fonction' => new sfValidatorString(array('required' => true), array('required' => 'Le champ "Fonction" est obligatoire.')),
  88. 'file1' => new sfValidatorFile(array('required' => true), array('required' => 'Les champs "Fichiers" sont obligatoires.')),
  89. 'file2' => new sfValidatorFile(),
  90. 'file3' => new sfValidatorFile(),
  91. 'file4' => new sfValidatorFile(),
  92. 'file5' => new sfValidatorFile(),
  93. 'email' => new sfValidatorEmail(array('required' => true), array('required' => 'Le champ "email" est obligatoire.', 'invalid' => 'L\'adresse mail "%value%" est invalide.')),
  94. '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.')),
  95. ));
  96.  
  97. $this->validatorSchema->setOption('allow_extra_fields', true);
  98. $this->validatorSchema->setOption('filter_extra_fields', false);
  99.  
  100. }
  101. }
Add Comment
Please, Sign In to add comment