Example #1
0
 /**
  * Returns true if the value has not been previously submitted.
  * Return false otherwise.
  *
  * @param $value
  * @return boolean
  */
 public function isValid($value)
 {
     global $wpdb;
     $sql = "SELECT `e`.`id` FROM " . iphorm_get_form_entry_data_table_name() . " ed LEFT JOIN " . iphorm_get_form_entries_table_name() . " e ON `ed`.`entry_id` = `e`.`id`\n        WHERE `e`.`form_id` = %d\n        AND `ed`.`element_id` = %d\n        AND `ed`.`value` = '%s';";
     $result = $wpdb->get_row($wpdb->prepare($sql, $this->_element->getForm()->getId(), $this->_element->getId(), $this->_element->getValueHtml()));
     if ($result != null) {
         $this->addMessage($this->_messageTemplates['duplicate']);
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct($config = null)
 {
     if (is_array($config)) {
         $recaptchaValidator = new iPhorm_Validator_Recaptcha(array('secretKey' => get_option('iphorm_recaptcha_secret_key')));
         if (array_key_exists('recaptcha_theme', $config)) {
             $this->setRecaptchaTheme($config['recaptcha_theme']);
             unset($config['recaptcha_theme']);
         }
         if (array_key_exists('recaptcha_type', $config)) {
             $this->setRecaptchaType($config['recaptcha_type']);
             unset($config['recaptcha_type']);
         }
         if (array_key_exists('recaptcha_lang', $config)) {
             $this->setRecaptchaLang($config['recaptcha_lang']);
             unset($config['recaptcha_lang']);
         }
         if (array_key_exists('messages', $config) && is_array($config['messages'])) {
             $recaptchaValidator->setMessageTemplates($config['messages']);
             unset($config['messages']);
         }
         $config['name'] = 'g-recaptcha-response';
         parent::__construct($config);
         $this->addValidator($recaptchaValidator);
     }
 }
Example #3
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct($config = null)
 {
     if (is_array($config)) {
         if (array_key_exists('options_layout', $config)) {
             $this->setOptionsLayout($config['options_layout']);
             unset($config['options_layout']);
         }
     }
     parent::__construct($config);
 }
Example #4
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct($config = null)
 {
     parent::__construct($config);
     if (is_array($config)) {
         if (array_key_exists('content', $config)) {
             $this->setContent($config['content']);
         }
         if (array_key_exists('enable_wrapper', $config)) {
             $this->setEnableWrapper($config['enable_wrapper']);
         }
     }
 }
Example #5
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct($config = null)
 {
     parent::__construct($config);
     $validator = new iPhorm_Validator_Captcha();
     if (is_array($config)) {
         if (array_key_exists('options', $config)) {
             $this->setOptions($config['options']);
         }
         if (array_key_exists('invalid_message', $config)) {
             $validator->setMessageTemplate('not_match', $config['invalid_message']);
         }
     }
     $this->addValidator($validator);
 }
Example #6
0
 public function __construct($name, $label = '', array $options = array())
 {
     parent::__construct($name, $label);
     $this->_fileUploadValidator = new iPhorm_Validator_FileUpload(array('name' => $this->getName()));
     $this->addValidator($this->_fileUploadValidator);
     if (array_key_exists('allowedExtensions', $options)) {
         $this->setAllowedExtensions($options['allowedExtensions']);
     }
     if (array_key_exists('maximumFileSize', $options)) {
         $this->setMaxFileSize($options['maximumFileSize']);
     }
     if (array_key_exists('required', $options)) {
         $this->setRequired($options['required']);
     }
 }
Example #7
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     parent::__construct($config);
     if (array_key_exists('time_12_24', $config)) {
         $this->setTime1224($config['time_12_24']);
     }
     $this->addValidator('time', array('is24Hr' => $this->getTime1224() == '24'));
     if (array_key_exists('minute_granularity', $config)) {
         $this->setMinuteGranularity($config['minute_granularity']);
     }
     if (array_key_exists('time_format', $config)) {
         $this->setTimeFormat($config['time_format']);
     }
     if (array_key_exists('show_time_headings', $config)) {
         $this->setShowTimeHeadings($config['show_time_headings']);
     }
     if (array_key_exists('start_hour', $config)) {
         $this->setStartHour($config['start_hour']);
     }
     if (array_key_exists('end_hour', $config)) {
         $this->setEndHour($config['end_hour']);
     }
     if (array_key_exists('time_validator_message_invalid', $config)) {
         if (strlen($config['time_validator_message_invalid'])) {
             $this->getValidator('time')->setMessageTemplate('invalid', $config['time_validator_message_invalid']);
         }
     }
     if (array_key_exists('hh_string', $config)) {
         $this->setHhString($config['hh_string']);
     }
     if (array_key_exists('mm_string', $config)) {
         $this->setMmString($config['mm_string']);
     }
     if (array_key_exists('ampm_string', $config)) {
         $this->setAmpmString($config['ampm_string']);
     }
     if (array_key_exists('am_string', $config)) {
         $this->setAmString($config['am_string']);
     }
     if (array_key_exists('pm_string', $config)) {
         $this->setPmString($config['pm_string']);
     }
 }
Example #8
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct($config = null)
 {
     parent::__construct($config);
     $this->addValidator('date');
     if (is_array($config)) {
         if (array_key_exists('show_date_headings', $config)) {
             $this->setShowDateHeadings($config['show_date_headings']);
         }
         if (array_key_exists('day_heading', $config)) {
             $this->setDayHeading($config['day_heading']);
         }
         if (array_key_exists('month_heading', $config)) {
             $this->setMonthHeading($config['month_heading']);
         }
         if (array_key_exists('year_heading', $config)) {
             $this->setYearHeading($config['year_heading']);
         }
         if (array_key_exists('start_year', $config)) {
             $this->setStartYear($config['start_year']);
         }
         if (array_key_exists('end_year', $config)) {
             $this->setEndYear($config['end_year']);
         }
         if (array_key_exists('date_validator_message_invalid', $config)) {
             if (strlen($config['date_validator_message_invalid'])) {
                 $this->getValidator('date')->setMessageTemplate('invalid', $config['date_validator_message_invalid']);
             }
         }
         if (array_key_exists('date_format', $config)) {
             $this->setDateFormat($config['date_format']);
         }
         if (array_key_exists('show_datepicker', $config)) {
             $this->setShowDatepicker($config['show_datepicker']);
         }
         if (array_key_exists('months_as_numbers', $config)) {
             $this->setMonthsAsNumbers($config['months_as_numbers']);
         }
         if (array_key_exists('field_order', $config)) {
             $this->setFieldOrder($config['field_order']);
         }
     }
 }
Example #9
0
 /**
  * Add a single element to the form
  *
  * @param $element iPhorm_Element The element to add
  */
 public function addElement(iPhorm_Element $element)
 {
     $element->setForm($this);
     $this->_elements[$element->getName()] = $element;
 }
Example #10
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config)
 {
     if (array_key_exists('name', $config)) {
         $name = $config['name'];
         if (array_key_exists('allow_multiple_uploads', $config) && $config['allow_multiple_uploads']) {
             $this->setAllowMultipleUploads($config['allow_multiple_uploads']);
             $name .= '[]';
             unset($config['allow_multiple_uploads']);
         }
         $this->setName($name);
         unset($config['name']);
     }
     $this->_fileUploadValidator = new iPhorm_Validator_FileUpload(array('name' => $this->getName()));
     $this->addValidator($this->_fileUploadValidator);
     parent::__construct($config);
     if (array_key_exists('enable_swf_upload', $config)) {
         $this->setEnableSwfUpload($config['enable_swf_upload']);
     }
     if (array_key_exists('add_as_attachment', $config)) {
         $this->setAddAsAttachment($config['add_as_attachment']);
     }
     if (array_key_exists('save_to_server', $config)) {
         $this->setSaveToServer($config['save_to_server']);
     }
     if (array_key_exists('save_path', $config)) {
         $this->setSavePath($config['save_path']);
     }
     if (array_key_exists('browse_text', $config)) {
         $this->setBrowseText($config['browse_text']);
     }
     if (array_key_exists('default_text', $config)) {
         $this->setDefaultText($config['default_text']);
     }
     if (array_key_exists('upload_num_fields', $config)) {
         $this->setUploadNumFields($config['upload_num_fields']);
     }
     if (array_key_exists('upload_user_add_more', $config)) {
         $this->setUploadUserAddMore($config['upload_user_add_more']);
     }
     if (array_key_exists('upload_add_another_text', $config)) {
         $this->setUploadAddAnotherText($config['upload_add_another_text']);
     }
     if (array_key_exists('upload_allowed_extensions', $config)) {
         $allowedExtensions = array();
         if (strlen($config['upload_allowed_extensions'])) {
             $allowedExtensions = explode(',', $config['upload_allowed_extensions']);
         }
         $this->_fileUploadValidator->setAllowedExtensions($allowedExtensions);
     }
     if (array_key_exists('upload_maximum_size', $config)) {
         $this->_fileUploadValidator->setMaximumFileSize($config['upload_maximum_size'] * 1048576);
     }
     if (array_key_exists('messages', $config) && is_array($config['messages'])) {
         $this->_fileUploadValidator->setMessageTemplates($config['messages']);
     }
 }
Example #11
0
 /**
  * Add a single element to the form
  *
  * @param $element iPhorm_Element The element to add
  */
 public function addElement(iPhorm_Element $element)
 {
     $this->_elements[$element->getName()] = $element;
     if ($element instanceof iPhorm_Element_Date && $element->getShowDatepicker()) {
         $this->_hasDatepickerElement = true;
     }
     if ($element->getLogic() && count($element->getLogicRules())) {
         $this->_hasConditionalLogic = true;
         $this->_conditionalLogicElementIds[] = $element->getId();
         foreach ($element->getLogicRules() as $rule) {
             $this->_conditionalLogicDependentElementIds[] = (int) $rule['element_id'];
         }
     }
 }
Example #12
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct($config = null)
 {
     parent::__construct($config);
     $honeypotValidator = new iPhorm_Validator_Honeypot();
     $this->addValidator($honeypotValidator);
 }
Example #13
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct($config = null)
 {
     if (is_array($config)) {
         if (array_key_exists('admin_title', $config)) {
             $this->setAdminTitle($config['admin_title']);
             unset($config['admin_title']);
         }
         if (array_key_exists('show_name_in_email', $config)) {
             $this->setShowNameInEmail($config['show_name_in_email']);
             unset($config['show_name_in_email']);
         }
         if (array_key_exists('title', $config)) {
             $this->setTitle($config['title']);
             unset($config['title']);
         }
         if (array_key_exists('number_of_columns', $config)) {
             $this->setNumberOfColumns($config['number_of_columns']);
             unset($config['number_of_columns']);
         }
         if (array_key_exists('column_alignment', $config)) {
             $this->setColumnAlignment($config['column_alignment']);
             unset($config['column_alignment']);
         }
         if (array_key_exists('group_style', $config)) {
             $this->setGroupStyle($config['group_style']);
             unset($config['group_style']);
         }
         if (array_key_exists('border_colour', $config)) {
             $this->setBorderColour($config['border_colour']);
             unset($config['border_colour']);
         }
         if (array_key_exists('background_colour', $config)) {
             $this->setBackgroundColour($config['background_colour']);
             unset($config['background_colour']);
         }
     }
     parent::__construct($config);
 }
Example #14
0
$form->addElement($name);
// Add the element to the form
/* EMAIL */
$email = new iPhorm_Element('email');
$email->addFilter('trim');
$email->addValidators(array('required', 'email'));
$form->addElement($email);
/* PHONE */
$phone = new iPhorm_Element('phone');
$phone->addFilter('trim');
$form->addElement($phone);
/* MESSAGE (TEXTAREA) */
$message = new iPhorm_Element('message');
$message->addFilter('trim');
$message->addValidator('required');
$form->addElement($message);
/* -----------------
 * CAPTCHA 
  ------------------- */
$captcha = new iPhorm_Element('type_the_word');
// Create the type_the_word (captcha) element - type_the_word must be the same as the name attribute of your form element in the HTML
$captcha->addFilter('trim');
// Add the Trim filter to the element
$captcha->addValidator('required');
// Add the Required validator to the element
$captcha->addValidator('identical', array('token' => 'light'));
// Add Identical validator value must match the word light
$captcha->setSkipRender(true);
// Success handlers should not render the element
$form->addElement($captcha);
// Add the element to the form