-
-
Notifications
You must be signed in to change notification settings - Fork 576
/
JoinForm.php
executable file
·228 lines (188 loc) · 11.5 KB
/
JoinForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
/**
* @author Pierre-Henry Soria <hello@ph7cms.com>
* @copyright (c) 2012-2018, Pierre-Henry Soria. All Rights Reserved.
* @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
* @package PH7 / App / System / Module / User / Form
*/
namespace PH7;
use PFBC\Validation\CEmail;
use PH7\Framework\Geo\Ip\Geo;
use PH7\Framework\Module\Various as SysMod;
use PH7\Framework\Mvc\Model\DbConfig;
use PH7\Framework\Mvc\Router\Uri;
use PH7\Framework\Session\Session;
use PH7\Framework\Url\Header;
class JoinForm
{
public static function step1()
{
if ((new Session)->exists('mail_step1')) {
Header::redirect(Uri::get('user', 'signup', 'step2'));
}
if (isset($_POST['submit_join_user'])) {
if (\PFBC\Form::isValid($_POST['submit_join_user'])) {
(new JoinFormProcess)->step1();
}
Header::redirect();
}
$oForm = new \PFBC\Form('form_join_user');
$oForm->configure(['action' => '']);
$oForm->addElement(new \PFBC\Element\Hidden('submit_join_user', 'form_join_user'));
$oForm->addElement(new \PFBC\Element\Token('join'));
// Check if the Connect module is enabled
if (SysMod::isEnabled('connect')) {
$oForm->addElement(new \PFBC\Element\HTMLExternal('<div class="center s_tMarg"><a href="' . Uri::get('connect', 'main', 'index') . '" class="btn btn-primary"><strong>' . t('Universal Login') . '</strong></a></div>'));
}
$oForm->addElement(new \PFBC\Element\Textbox(t('Your First Name'), 'first_name', ['placeholder' => t('First Name'), 'id' => 'name_first', 'onblur' => 'CValid(this.value,this.id)', 'required' => 1, 'validation' => new \PFBC\Validation\Name]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error name_first"></span>'));
$oForm->addElement(new \PFBC\Element\Username(t('Your Nickname'), 'username', ['placeholder' => t('Nickname'), 'description' => PH7_URL_ROOT . UserCore::PROFILE_PAGE_PREFIX . '<strong><span class="your-user-name">' . t('your-user-name') . '</span><span class="username"></span></strong>', 'id' => 'username', 'required' => 1, 'validation' => new \PFBC\Validation\Username]));
$oForm->addElement(new \PFBC\Element\Email(t('Your Email'), 'mail', ['placeholder' => t('Email'), 'id' => 'email', 'onblur' => 'CValid(this.value, this.id,\'guest\')', 'required' => 1, 'validation' => new CEmail(CEmail::GUEST_MODE)]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error email"></span>'));
$oForm->addElement(new \PFBC\Element\Password(t('Your Password'), 'password', ['placeholder' => t('Password'), 'id' => 'password', 'onkeyup' => 'checkPassword(this.value)', 'onblur' => 'CValid(this.value, this.id)', 'required' => 1, 'validation' => new \PFBC\Validation\Password]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error password"></span>'));
if (DbConfig::getSetting('isCaptchaUserSignup')) {
$oForm->addElement(new \PFBC\Element\CCaptcha(t('Captcha'), 'captcha', ['placeholder' => t('Captcha'), 'id' => 'ccaptcha', 'onkeyup' => 'CValid(this.value, this.id)', 'description' => t('Enter the below code:')]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error ccaptcha"></span>'));
}
$oForm->addElement(new \PFBC\Element\Checkbox(t('Terms of Service'), 'terms', [1 => '<em>' . t('I have read and agree to the %0%.', '<a href="' . Uri::get('page', 'main', 'terms') . '" rel="nofollow" target="_blank">' . t('Terms of Service') . '</a>') . '</em>'], ['id' => 'terms', 'onblur' => 'CValid(this.checked, this.id)', 'required' => 1]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error terms-0"></span>'));
$oForm->addElement(new \PFBC\Element\Button(t('Join for free!'), 'submit', ['icon' => 'heart']));
// JavaScript Files
$oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_STATIC . PH7_JS . 'signup.js"></script><script src="' . PH7_URL_STATIC . PH7_JS . 'validate.js"></script>'));
$oForm->render();
}
public static function step2()
{
$oSession = new Session;
if (!$oSession->exists('mail_step1')) {
Header::redirect(Uri::get('user', 'signup', 'step1'));
} elseif ($oSession->exists('mail_step2')) {
Header::redirect(Uri::get('user', 'signup', 'step3'));
}
unset($oSession);
if (isset($_POST['submit_join_user2'])) {
if (\PFBC\Form::isValid($_POST['submit_join_user2'])) {
(new JoinFormProcess)->step2();
}
Header::redirect();
}
$oForm = new \PFBC\Form('form_join_user2');
$oForm->configure(['action' => '']);
$oForm->addElement(new \PFBC\Element\Hidden('submit_join_user2', 'form_join_user2'));
$oForm->addElement(new \PFBC\Element\Token('join2'));
$oForm->addElement(
new \PFBC\Element\Radio(
t('I am a'),
'sex',
[
GenderTypeUserCoreModel::FEMALE => t('Woman') . ' <i class="fa fa-venus"></i>',
GenderTypeUserCoreModel::MALE => t('Man') . ' <i class="fa fa-mars"></i>',
GenderTypeUserCoreModel::COUPLE => t('Couple') . ' <i class="fa fa-venus-mars"></i>'
],
['value' => GenderTypeUserCoreModel::FEMALE, 'required' => 1]
)
);
$oForm->addElement(
new \PFBC\Element\Checkbox(
t('Looking for a'),
'match_sex',
[
GenderTypeUserCoreModel::MALE => t('Man') . ' <i class="fa fa-mars"></i>',
GenderTypeUserCoreModel::FEMALE => t('Woman') . ' <i class="fa fa-venus"></i>',
GenderTypeUserCoreModel::COUPLE => t('Couple') . ' <i class="fa fa-venus-mars"></i>'
],
['value' => GenderTypeUserCoreModel::MALE, 'required' => 1]
)
);
self::generateBirthDateField($oForm);
$oForm->addElement(new \PFBC\Element\Select(t('Your Country'), 'country', Form::getCountryValues(), ['id' => 'str_country', 'value' => Geo::getCountryCode(), 'required' => 1]));
$oForm->addElement(new \PFBC\Element\Textbox(t('Your City'), 'city', ['id' => 'str_city', 'value' => Geo::getCity(), 'onblur' => 'CValid(this.value,this.id,2,150)', 'description' => t('Select the city where you live/where you want to meet people.'), 'validation' => new \PFBC\Validation\Str(2, 150), 'required' => 1]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error str_city"></span>'));
$oForm->addElement(new \PFBC\Element\Textbox(t('Your Postal Code'), 'zip_code', ['id' => 'str_zip_code', 'value' => Geo::getZipCode(), 'onblur' => 'CValid(this.value,this.id,2,15)', 'validation' => new \PFBC\Validation\Str(2, 15)]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error str_zip_code"></span>'));
$oForm->addElement(new \PFBC\Element\Button(t('Next'), 'submit', ['icon' => 'seek-next']));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_STATIC . PH7_JS . 'validate.js"></script><script src="' . PH7_URL_STATIC . PH7_JS . 'geo/autocompleteCity.js"></script>'));
$oForm->render();
}
public static function step3()
{
$oSession = new Session;
if (!$oSession->exists('mail_step2')) {
Header::redirect(Uri::get('user', 'signup', 'step2'));
} elseif ($oSession->exists('mail_step3')) {
Header::redirect(Uri::get('user', 'signup', 'step4'));
}
unset($oSession);
if (isset($_POST['submit_join_user3'])) {
if (\PFBC\Form::isValid($_POST['submit_join_user3'])) {
(new JoinFormProcess)->step3();
}
Header::redirect();
}
$oForm = new \PFBC\Form('form_join_user3');
$oForm->configure(['action' => '']);
$oForm->addElement(new \PFBC\Element\Hidden('submit_join_user3', 'form_join_user3'));
$oForm->addElement(new \PFBC\Element\Token('join3'));
$oForm->addElement(new \PFBC\Element\Textarea(t('About Me'), 'description', ['id' => 'str_description', 'description' => t('Describe yourself in a few words. Your description should be at least 20 characters long.'), 'onblur' => 'CValid(this.value,this.id,20,4000)', 'validation' => new \PFBC\Validation\Str(20, 4000), 'required' => 1]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error str_description"></span>'));
$oForm->addElement(new \PFBC\Element\Button(t('Next'), 'submit', ['icon' => 'seek-next']));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_STATIC . PH7_JS . 'validate.js"></script>'));
$oForm->render();
}
public static function step4()
{
$oSession = new Session;
if (!$oSession->exists('mail_step3')) {
Header::redirect(Uri::get('user', 'signup', 'step3'));
} elseif ($oSession->exists('mail_step4')) {
Header::redirect(Uri::get('user', 'signup', 'done'));
}
unset($oSession);
if (isset($_POST['submit_join_user4'])) {
if (\PFBC\Form::isValid($_POST['submit_join_user4'])) {
(new JoinFormProcess)->step4();
}
Header::redirect();
}
$aAvatarFieldOption = ['accept' => 'image/*'];
$bIsAvatarRequired = DbConfig::getSetting('requireRegistrationAvatar');
if ($bIsAvatarRequired) {
$aAvatarFieldOption += ['required' => 1];
}
$oForm = new \PFBC\Form('form_join_user4');
$oForm->configure(['action' => '']);
$oForm->addElement(new \PFBC\Element\Hidden('submit_join_user4', 'form_join_user4'));
$oForm->addElement(new \PFBC\Element\Token('join4'));
$oForm->addElement(new \PFBC\Element\File(t('Your Profile Photo'), 'avatar', $aAvatarFieldOption));
$oForm->addElement(new \PFBC\Element\Button(t('Add My Photo')));
if (!$bIsAvatarRequired) {
$oForm->addElement(
new \PFBC\Element\Button(
t('Skip'),
'submit',
['formaction' => Uri::get('user', 'signup', 'done')]
)
);
}
$oForm->render();
}
private static function generateBirthDateField(\PFBC\Form $oForm)
{
if (DbConfig::getSetting('isUserAgeRangeField')) {
$iMinAge = DbConfig::getSetting('minAgeRegistration');
$iMaxAge = DbConfig::getSetting('maxAgeRegistration');
$iDefRegistrationAge = $iMinAge + 16;
$oForm->addElement(
new \PFBC\Element\Range(
t('How Old Are You?'),
'age',
['value' => $iDefRegistrationAge, 'min' => $iMinAge, 'max' => $iMaxAge, 'required' => 1]
)
);
} else {
$oForm->addElement(new \PFBC\Element\Date(t('Your Date of Birth'), 'birth_date', ['id' => 'birth_date', 'description' => t('Please specify your date of birth using the calendar.'), 'onblur' => 'CValid(this.value, this.id)', 'validation' => new \PFBC\Validation\BirthDate, 'required' => 1]));
$oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error birth_date"></span>'));
}
}
}