Exemplo n.º 1
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new FrontendForm('own_question', '#' . FL::getAction('OwnQuestion'));
     $this->frm->addText('name')->setAttribute('placeholder', FL::getLabel('YourName'));
     $this->frm->addText('email')->setAttribute('placeholder', FL::getLabel('YourEmail'));
     $this->frm->addTextarea('message')->setAttribute('placeholder', FL::getLabel('YourQuestion'));
 }
Exemplo n.º 2
0
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // gender dropdown values
     $genderValues = array('male' => SpoonFilter::ucfirst(FL::getLabel('Male')), 'female' => SpoonFilter::ucfirst(FL::getLabel('Female')));
     // birthdate dropdown values
     $days = range(1, 31);
     $months = SpoonLocale::getMonths(FRONTEND_LANGUAGE);
     $years = range(date('Y'), 1900);
     // get settings
     $birthDate = $this->profile->getSetting('birth_date');
     $nameChanges = (int) $this->profile->getSetting('display_name_changes');
     // get day, month and year
     if ($birthDate) {
         list($birthYear, $birthMonth, $birthDay) = explode('-', $birthDate);
     } else {
         $birthDay = '';
         $birthMonth = '';
         $birthYear = '';
     }
     // create the form
     $this->frm = new FrontendForm('updateSettings', null, null, 'updateSettingsForm');
     // create & add elements
     $this->frm->addImage('avatar');
     $this->frm->addText('display_name', $this->profile->getDisplayName());
     $this->frm->addText('first_name', $this->profile->getSetting('first_name'));
     $this->frm->addText('last_name', $this->profile->getSetting('last_name'));
     $this->frm->addText('email', $this->profile->getEmail());
     $this->frm->addText('city', $this->profile->getSetting('city'));
     $this->frm->addDropdown('country', SpoonLocale::getCountries(FRONTEND_LANGUAGE), $this->profile->getSetting('country'));
     $this->frm->addDropdown('gender', $genderValues, $this->profile->getSetting('gender'));
     $this->frm->addDropdown('day', array_combine($days, $days), $birthDay);
     $this->frm->addDropdown('month', $months, $birthMonth);
     $this->frm->addDropdown('year', array_combine($years, $years), (int) $birthYear);
     // set default elements dropdowns
     $this->frm->getField('gender')->setDefaultElement('');
     $this->frm->getField('day')->setDefaultElement('');
     $this->frm->getField('month')->setDefaultElement('');
     $this->frm->getField('year')->setDefaultElement('');
     $this->frm->getField('country')->setDefaultElement('');
     // set email disabled
     $this->frm->getField('email')->setAttribute('disabled', 'disabled');
     // when user exceeded the number of name changes set field disabled
     if ($nameChanges >= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
         $this->frm->getField('display_name')->setAttribute('disabled', 'disabled');
     }
 }
Exemplo n.º 3
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // shorten the fields
         $txtName = $this->frm->getField('name');
         $txtEmail = $this->frm->getField('email');
         $ddmMethod = $this->frm->getField('method');
         $txtSuccessMessage = $this->frm->getField('success_message');
         $txtIdentifier = $this->frm->getField('identifier');
         $emailAddresses = (array) explode(',', $txtEmail->getValue());
         // validate fields
         $txtName->isFilled(BL::getError('NameIsRequired'));
         $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired'));
         if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') {
             $error = false;
             // check the addresses
             foreach ($emailAddresses as $address) {
                 $address = trim($address);
                 if (!SpoonFilter::isEmail($address)) {
                     $error = true;
                     break;
                 }
             }
             // add error
             if ($error) {
                 $txtEmail->addError(BL::getError('EmailIsInvalid'));
             }
         }
         // identifier
         if ($txtIdentifier->isFilled()) {
             // invalid characters
             if (!SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) {
                 $txtIdentifier->setError(BL::getError('InvalidIdentifier'));
             } elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue())) {
                 $txtIdentifier->setError(BL::getError('UniqueIdentifier'));
             }
         }
         if ($this->frm->isCorrect()) {
             // build array
             $values['language'] = BL::getWorkingLanguage();
             $values['user_id'] = BackendAuthentication::getUser()->getUserId();
             $values['name'] = $txtName->getValue();
             $values['method'] = $ddmMethod->getValue();
             $values['email'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : null;
             $values['success_message'] = $txtSuccessMessage->getValue(true);
             $values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier();
             $values['created_on'] = BackendModel::getUTCDate();
             $values['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $id = BackendFormBuilderModel::insert($values);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values));
             // set frontend locale
             FL::setLocale(BL::getWorkingLanguage());
             // create submit button
             $field['form_id'] = $id;
             $field['type'] = 'submit';
             $field['settings'] = serialize(array('values' => SpoonFilter::ucfirst(FL::getLabel('Send'))));
             BackendFormBuilderModel::insertField($field);
             // everything is saved, so redirect to the editform
             $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id . '&report=added&var=' . urlencode($values['name']) . '#tabFields');
         }
     }
 }