コード例 #1
0
ファイル: CheckBox.php プロジェクト: FormHandler/FormHandler
 /**
  * CheckBox::CheckBox()
  *
  * Constructor: Create a new checkbox object
  *
  * @param FormHandler $form The form where this field is located on
  * @param string $name The name of the field
  * @param mixed array|string $options - The options for the field
  * @return \FormHandler\Field\CheckBox
  * @author Teye Heimans
  */
 public function __construct(FormHandler $form, $name, $options = array())
 {
     $this->setDefaultValue(array());
     $this->value = array();
     $this->value_forced = array();
     $this->value_default = array();
     $nameClean = str_replace('[]', '', $name);
     //when no checkboxes are selected no data is posted
     if ($form->isPosted() && !isset($_POST[$nameClean])) {
         $this->value_post = array();
     }
     // call the constructor of the Field class
     return parent::__construct($form, $nameClean)->setJsSelectorValue('#' . $form->getFormName() . ' input[name="' . $nameClean . '\\[\\]"]')->setOptions($options)->setMask(\FormHandler\Configuration::get('default_glue_mask'))->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setFocusName($nameClean . '_1');
 }
コード例 #2
0
ファイル: Field.php プロジェクト: FormHandler/FormHandler
 /**
  * Field::Field()
  *
  * Public abstract constructor: Create a new field
  *
  * @param FormHandler $form The form where the field is located on
  * @param string $name The name of the field
  * @return static
  * @author Teye Heimans
  * @author Marien den Besten
  */
 public function __construct($form, $name)
 {
     // save the form and nome of the field
     $this->form_object = $form;
     $this->name = $name;
     $this->setFocusName($name)->setJsSelectorValue('#' . $form->getFormName() . ' input[name="' . $name . '"]')->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setRequired(\FormHandler\Configuration::get('require_fields') == 1);
     // check if there are spaces in the fieldname
     if (strpos($name, ' ') !== false) {
         trigger_error('Warning: There are spaces in the field name "' . $name . '"!', E_USER_WARNING);
     }
     //get the value of the field
     if ($form->isPosted() && isset($_POST[$name]) && (is_string($_POST[$name]) || is_array($_POST[$name]))) {
         $this->value_post = $_POST[$name];
     }
     return $this;
 }