1 <?php
2
3 /*
4 * This file is part of the Icybee package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Icybee\Modules\Forms;
13
14 use Brickrouge\Element;
15 use Brickrouge\Text;
16
17 class ContactForm extends \Brickrouge\Form
18 {
19 public function __construct(array $attributes=array())
20 {
21 parent::__construct
22 (
23 \ICanBoogie\array_merge_recursive
24 (
25 $attributes, array
26 (
27 self::RENDERER => 'Simple',
28
29 Element::CHILDREN => array
30 (
31 'gender' => new Element
32 (
33 Element::TYPE_RADIO_GROUP, array
34 (
35 self::LABEL => 'Salutation',
36 Element::OPTIONS => array('salutation.Misses', 'salutation.Mister'),
37 Element::REQUIRED => true,
38
39 'class' => 'inline-inputs'
40 )
41 ),
42
43 'firstname' => new Text
44 (
45 array
46 (
47 self::LABEL => 'Firstname',
48 Element::REQUIRED => true
49 )
50 ),
51
52 'lastname' => new Text
53 (
54 array
55 (
56 self::LABEL => 'Lastname',
57 Element::REQUIRED => true
58 )
59 ),
60
61 'company' => new Text
62 (
63 array
64 (
65 self::LABEL => 'Company'
66 )
67 ),
68
69 'email' => new Text
70 (
71 array
72 (
73 self::LABEL => 'E-mail',
74 Element::REQUIRED => true,
75 Element::VALIDATOR => array('Brickrouge\Form::validate_email')
76 )
77 ),
78
79 'message' => new Element
80 (
81 'textarea', array
82 (
83 self::LABEL => 'Your message',
84 Element::REQUIRED => true
85 )
86 )
87 )
88 )
89 ),
90
91 'div'
92 );
93 }
94
95 static public function get_defaults()
96 {
97 global $core;
98
99 $p = \Patron\Engine::PREFIX;
100
101 return array
102 (
103 'notify_destination' => $core->user->email,
104 'notify_from' => 'Contact <no-reply@' . preg_replace('#^www#', '', $_SERVER['SERVER_NAME']) .'>',
105 'notify_subject' => 'Formulaire de contact',
106 'notify_template' => <<<EOT
107 Un message a été posté depuis le formulaire de contact :
108
109 Nom : #{@gender.index('Mme', 'Mlle', 'M')} #{@lastname} #{@firstname}
110 <{$p}if test="@company">Société : #{@company}</{$p}if>
111 E-Mail : #{@email}
112
113 Message : #{@message}
114 EOT
115 );
116 }
117 }