__construct() public method

Instantiate the form element object
public __construct ( string $type, string $name, string $value = null, string | array $marked = null, string $indent = null ) : Element
$type string
$name string
$value string
$marked string | array
$indent string
return Element
Example #1
0
 /**
  * Constructor
  *
  * Instantiate the CSRF form element object.
  *
  * @param  string $name
  * @param  string $value
  * @param  int    $expire
  * @param  string $indent
  * @return \Pop\Form\Element\Csrf
  */
 public function __construct($name, $value = null, $expire = 300, $indent = null)
 {
     // Start a session.
     if (session_id() == '') {
         session_start();
     }
     // If token does not exist, create one
     if (!isset($_SESSION['pop_csrf'])) {
         $this->token = array('value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time());
         $_SESSION['pop_csrf'] = serialize($this->token);
         // Else, retrieve existing token
     } else {
         $this->token = unserialize($_SESSION['pop_csrf']);
         // Check to see if the token has expired
         if ($this->token['expire'] > 0) {
             if ($this->token['expire'] + $this->token['start'] < time()) {
                 $this->token = array('value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time());
                 $_SESSION['pop_csrf'] = serialize($this->token);
             }
         }
     }
     parent::__construct('hidden', $name, $this->token['value'], null, $indent);
     $this->setRequired(true);
     $this->setValidator();
 }
Example #2
0
 /**
  * Constructor
  *
  * Instantiate the captcha form element object.
  *
  * @param  string $name
  * @param  string $value
  * @param  int    $expire
  * @param  string $captcha
  * @param  string $indent
  * @return \Pop\Form\Element\Captcha
  */
 public function __construct($name, $value = null, $expire = 300, $captcha = null, $indent = null)
 {
     // Start a session.
     if (session_id() == '') {
         session_start();
     }
     // If token does not exist, create one
     if (!isset($_SESSION['pop_captcha'])) {
         if (null === $captcha) {
             $captcha = $this->generateEquation();
         } else {
             if (stripos($captcha, '<img') === false) {
                 $captcha = strtoupper($captcha);
             }
         }
         $this->token = array('captcha' => $captcha, 'value' => null, 'expire' => (int) $expire, 'start' => time());
         $_SESSION['pop_captcha'] = serialize($this->token);
         // Else, retrieve existing token
     } else {
         $this->token = unserialize($_SESSION['pop_captcha']);
         // Check to see if the token has expired
         if ($this->token['expire'] > 0) {
             if ($this->token['expire'] + $this->token['start'] < time()) {
                 if (null === $captcha) {
                     $captcha = $this->generateEquation();
                 } else {
                     if (stripos($captcha, '<img') === false) {
                         $captcha = strtoupper($captcha);
                     }
                 }
                 $this->token = array('captcha' => $captcha, 'value' => null, 'expire' => (int) $expire, 'start' => time());
                 $_SESSION['pop_captcha'] = serialize($this->token);
             }
         }
     }
     parent::__construct('text', $name, strtoupper($value), null, $indent);
     $this->setRequired(true);
     $this->setValidator();
 }
Example #3
0
 /**
  * Constructor
  *
  * Instantiate the select form element object.
  *
  * @param  string $name
  * @param  string|array $value
  * @param  string|array $marked
  * @param  string $indent
  * @param  string $data
  * @return \Pop\Form\Element\Select
  */
 public function __construct($name, $value = null, $marked = null, $indent = null, $data = null)
 {
     $val = null;
     $lang = new \Pop\I18n\I18n();
     // If the value flag is YEAR-based, calculate the year range for the select drop-down menu.
     if (is_string($value) && strpos($value, 'YEAR') !== false) {
         $years = array('----' => '----');
         $yearAry = explode('_', $value);
         // YEAR_1111_2222 (from year 1111 to 2222)
         if (isset($yearAry[1]) && isset($yearAry[2])) {
             if ($yearAry[1] < $yearAry[2]) {
                 for ($i = $yearAry[1]; $i <= $yearAry[2]; $i++) {
                     $years[$i] = $i;
                 }
             } else {
                 for ($i = $yearAry[1]; $i >= $yearAry[2]; $i--) {
                     $years[$i] = $i;
                 }
             }
             // YEAR_1111
             // If 1111 is less than today's year, then 1111 to present year,
             // else from present year to 1111
         } else {
             if (isset($yearAry[1])) {
                 $year = date('Y');
                 if ($year < $yearAry[1]) {
                     for ($i = $year; $i <= $yearAry[1]; $i++) {
                         $years[$i] = $i;
                     }
                 } else {
                     for ($i = $year; $i >= $yearAry[1]; $i--) {
                         $years[$i] = $i;
                     }
                 }
                 // YEAR, from present year to 10+ years
             } else {
                 $year = date('Y');
                 for ($i = $year; $i <= $year + 10; $i++) {
                     $years[$i] = $i;
                 }
             }
         }
         $val = $years;
         // Else, if the value flag is one of the pre-defined array values, set the value of the select drop-down menu to it.
     } else {
         switch ($value) {
             // Months, numeric short values.
             case Select::MONTHS_SHORT:
                 $val = array('--' => '--', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12');
                 break;
                 // Months, long name values.
             // Months, long name values.
             case Select::MONTHS_LONG:
                 $val = array('--' => '------', '01' => $lang->__('January'), '02' => $lang->__('February'), '03' => $lang->__('March'), '04' => $lang->__('April'), '05' => $lang->__('May'), '06' => $lang->__('June'), '07' => $lang->__('July'), '08' => $lang->__('August'), '09' => $lang->__('September'), '10' => $lang->__('October'), '11' => $lang->__('November'), '12' => $lang->__('December'));
                 break;
                 // Days of Month, numeric short values.
             // Days of Month, numeric short values.
             case Select::DAYS_OF_MONTH:
                 $val = array('--' => '--', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31');
                 break;
                 // Days of Week, long name values.
             // Days of Week, long name values.
             case Select::DAYS_OF_WEEK:
                 $sun = $lang->__('Sunday');
                 $mon = $lang->__('Monday');
                 $tue = $lang->__('Tuesday');
                 $wed = $lang->__('Wednesday');
                 $thu = $lang->__('Thursday');
                 $fri = $lang->__('Friday');
                 $sat = $lang->__('Saturday');
                 $val = array('--' => '------', $sun => $sun, $mon => $mon, $tue => $tue, $wed => $wed, $thu => $thu, $fri => $fri, $sat => $sat);
                 break;
                 // Hours, 12-hour values.
             // Hours, 12-hour values.
             case Select::HOURS_12:
                 $val = array('--' => '--', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12');
                 break;
                 // Military Hours, 24-hour values.
             // Military Hours, 24-hour values.
             case Select::HOURS_24:
                 $val = array('--' => '--', '00' => '00', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23');
                 break;
                 // Minutes, incremental by 1 minute.
             // Minutes, incremental by 1 minute.
             case Select::MINUTES:
                 $val = array('--' => '--', '00' => '00', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31', '32' => '32', '33' => '33', '34' => '34', '35' => '35', '36' => '36', '37' => '37', '38' => '38', '39' => '39', '40' => '40', '41' => '41', '42' => '42', '43' => '43', '44' => '44', '45' => '45', '46' => '46', '47' => '47', '48' => '48', '49' => '49', '50' => '50', '51' => '51', '52' => '52', '53' => '53', '54' => '54', '55' => '55', '56' => '56', '57' => '57', '58' => '58', '59' => '59');
                 break;
                 // Minutes, incremental by 5 minutes.
             // Minutes, incremental by 5 minutes.
             case Select::MINUTES_5:
                 $val = array('--' => '--', '00' => '00', '05' => '05', '10' => '10', '15' => '15', '20' => '20', '25' => '25', '30' => '30', '35' => '35', '40' => '40', '45' => '45', '50' => '50', '55' => '55');
                 break;
                 // Minutes, incremental by 10 minutes.
             // Minutes, incremental by 10 minutes.
             case Select::MINUTES_10:
                 $val = array('--' => '--', '00' => '00', '10' => '10', '20' => '20', '30' => '30', '40' => '40', '50' => '50');
                 break;
                 // Minutes, incremental by 15 minutes.
             // Minutes, incremental by 15 minutes.
             case Select::MINUTES_15:
                 $val = array('--' => '--', '00' => '00', '15' => '15', '30' => '30', '45' => '45');
                 break;
                 // US States, short name values.
             // US States, short name values.
             case Select::US_STATES_SHORT:
                 $val = array('--' => '--', 'AK' => 'AK', 'AL' => 'AL', 'AR' => 'AR', 'AZ' => 'AZ', 'CA' => 'CA', 'CO' => 'CO', 'CT' => 'CT', 'DC' => 'DC', 'DE' => 'DE', 'FL' => 'FL', 'GA' => 'GA', 'HI' => 'HI', 'IA' => 'IA', 'ID' => 'ID', 'IL' => 'IL', 'IN' => 'IN', 'KS' => 'KS', 'KY' => 'KY', 'LA' => 'LA', 'MA' => 'MA', 'MD' => 'MD', 'ME' => 'ME', 'MI' => 'MI', 'MN' => 'MN', 'MO' => 'MO', 'MS' => 'MS', 'MT' => 'MT', 'NC' => 'NC', 'ND' => 'ND', 'NE' => 'NE', 'NH' => 'NH', 'NJ' => 'NJ', 'NM' => 'NM', 'NV' => 'NV', 'NY' => 'NY', 'OH' => 'OH', 'OK' => 'OK', 'OR' => 'OR', 'PA' => 'PA', 'RI' => 'RI', 'SC' => 'SC', 'SD' => 'SD', 'TN' => 'TN', 'TX' => 'TX', 'UT' => 'UT', 'VA' => 'VA', 'VT' => 'VT', 'WA' => 'WA', 'WI' => 'WI', 'WV' => 'WV', 'WY' => 'WY');
                 break;
                 // US States, long name values.
             // US States, long name values.
             case Select::US_STATES_LONG:
                 $val = array('--' => '------', 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DC' => 'District of Columbia', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming');
                 break;
                 // Else, set the custom array of values passed.
             // Else, set the custom array of values passed.
             default:
                 // If it's an array, just set it.
                 if (is_array($value)) {
                     $val = $value;
                     // Else, check for the values in the XML options file.
                 } else {
                     $xmlFile = file_exists($data) ? $data : __DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'options.xml';
                     $val = self::parseXml($xmlFile, $value);
                 }
         }
     }
     $this->value = $val;
     $this->setMarked($marked);
     parent::__construct('select', $name, $val, $marked, $indent);
 }
Example #4
0
 /**
  * Constructor
  *
  * Instantiate the radio form element object.
  *
  * @param  string $name
  * @param  string|array $value
  * @param  string|array $marked
  * @param  string $indent
  * @return \Pop\Form\Element\Radio
  */
 public function __construct($name, $value = null, $marked = null, $indent = null)
 {
     $this->value = $value;
     $this->setMarked($marked);
     parent::__construct('radio', $name, $value, $marked, $indent);
 }
Example #5
0
 /**
  * Constructor
  *
  * Instantiate the textarea form element object.
  *
  * @param  string $name
  * @param  string $value
  * @param  string|array $marked
  * @param  string $indent
  * @return \Pop\Form\Element\Textarea
  */
 public function __construct($name, $value = null, $marked = null, $indent = null)
 {
     parent::__construct('textarea', $name, $value, $marked, $indent);
 }