예제 #1
0
 /**
  * Create a new temperature field object
  *
  * @param FormHandler $form The form where this field is located on
  * @param string $name The name of the field
  * @return \FormHandler\Field\Temperature
  * @author Marien den Besten
  */
 public function __construct(FormHandler $form, $name)
 {
     $this->allow_empty_text = 'Value unknown';
     $this->empty = new \FormHandler\Field\CheckBox($form, $name . '_empty');
     $this->empty->setOptions(array(1 => $this->allow_empty_text));
     $empty = $this->empty->getValue();
     $this->value = !empty($empty) ? null : $this->value;
     $this->temperature = new \FormHandler\Field\Number($form, $name . '_temperature');
     $this->temperature->setMin(-1000);
     $this->temperature->setMax(1000);
     $this->temperature->setStep(0.1);
     $this->temperature->setValidator(function ($value) {
         return is_numeric($value);
     });
     $this->unit = new \FormHandler\Field\Select($form, $name . '_unit');
     $this->unit->setOptions($this->units);
     if (empty($empty)) {
         $this->value = array($this->temperature->getValue(), $this->unit->getValue());
     }
     //Classes
     $this->temperature->setExtra('class="temperature-field"');
     $this->unit->setExtra('class="temperature-field"');
     $this->empty->setExtra('class="temperature-field"');
     parent::__construct($form, $name)->setFocusName($name . '_temperature');
     $form->_setJS('' . "var doConversion = true;\n" . "\$('#" . $name . "_empty_1').on('change',function()\n" . "{\n" . " doConversion = false;\n" . " var state = !!\$(this).prop('checked');\n" . " \$('#" . $name . "_temperature').prop('disabled',state).trigger('change');\n" . " \$('#" . $name . "_unit').prop('disabled',state).trigger('change');\n" . "});\n" . "\$('#" . $name . "_unit').on('change',function()\n" . "{\n" . "if(doConversion === true){\n" . " var val = \$(this).val(),\n" . "     temp = \$('#" . $name . "_temperature').val();\n" . " if(val == 'celsius') \$('#" . $name . "_temperature').val(Math.round(((temp - 32) / 1.8)*10)/10);\n" . " if(val == 'fahrenheit') \$('#" . $name . "_temperature').val(Math.round(((temp * 1.8) + 32)*10)/10);\n" . "}\n" . "doConversion = true;\n" . "});\n", false, false);
     return $this;
 }
예제 #2
0
 /**
  * Constructor
  *
  * Create a new file basic field
  *
  * @param object $form The form where this field is located on
  * @param string $name The name of the field
  * @return \FormHandler\Field\FileBasic
  * @author Marien den Besten
  */
 public function __construct(FormHandler $form, $name)
 {
     // call the constructor of the Field class
     parent::__construct($form, $name);
     if ($form->isPosted() && array_key_exists($name, $_FILES)) {
         $this->value = $_FILES[$name];
     }
     $this->form_object->setEncoding(FormHandler::ENCODING_MULTIPART);
     return $this;
 }
예제 #3
0
 public function __construct($form, $name)
 {
     $this->allow_empty_text = 'Value unknown';
     $this->empty = new \FormHandler\Field\CheckBox($form, $name . '_empty');
     $this->empty->setOptions(array(1 => '<em>' . $this->allow_empty_text . '</em>'));
     $empty = $this->empty->getValue();
     $this->value = !empty($empty) ? null : $this->value;
     parent::__construct($form, $name);
     $form->_setJS("\$(document).ready(function(){\n" . "\$('#" . $name . "_empty_1').on('change',function()\n" . "{\n" . " var state = !!\$(this).prop('checked');\n" . " \$('#" . $name . "').prop('disabled',state).trigger('change');\n" . "});\n" . "});");
     return $this;
 }
예제 #4
0
 /**
  * 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');
 }
예제 #5
0
 /**
  * Constructor
  *
  * Create a new SelectList
  *
  * @param FormHandler $form The form where this field is located on
  * @param string $name The name of the field
  * @param array $options The options of the field
  * @return \FormHandler\Field\SelectList
  * @author Teye Heimans
  * @author Marien den Besten
  */
 public function __construct(FormHandler $form, $name, $options = array())
 {
     $this->field_values = new \FormHandler\Field\Hidden($form, $name);
     $this->field_values->setDefaultValue(array());
     static $bSetJS = false;
     // needed javascript included yet ?
     if (!$bSetJS) {
         $bSetJS = true;
         $form->_setJS(\FormHandler\Configuration::get('fhtml_dir') . "js/listfield.js", true);
     }
     // make the fields of the SelectList
     $this->field_on = new \FormHandler\Field\Select($form, $name . '_ListOn');
     $this->field_off = new \FormHandler\Field\Select($form, $name . '_ListOff');
     $this->field_on->setMultiple(true);
     $this->field_off->setMultiple(true);
     return parent::__construct($form, $name)->setOptions($options)->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setSize(\FormHandler\Configuration::get('default_listfield_size'))->setOffTitle(\FormHandler\Language::get(29))->setOnTitle(\FormHandler\Language::get(30))->setFocusName($name . '_ListOn');
 }
예제 #6
0
 /**
  * Constructor
  *
  * create a new textarea
  *
  * @param object $form The form where this field is located on
  * @param string $name The name of the field
  * @return \FormHandler\Field\TextArea
  * @author Teye Heimans
  */
 public function __construct(FormHandler $form, $name)
 {
     // call the constructor of the Field class
     return parent::__construct($form, $name)->setJsSelectorValue('#' . $form->getFormName() . ' textarea[name="' . $name . '"]')->setValidator(function ($value, $form) use($name) {
         $max_length = $form->getField($name)->getMaxLength();
         // is a max length set ?
         if (is_null($max_length)) {
             return true;
         }
         // is there to many data submitted ?
         $length = strlen($value);
         if ($length > $max_length) {
             return sprintf(\FormHandler\Language::get(40), $max_length, $length, abs($length - $max_length));
         }
         return true;
     });
 }
예제 #7
0
 /**
  * Constructor
  *
  * Create a select field
  *
  * @param FormHandler $form The form where the field is located on
  * @param string $name The name of the form
  * @return \FormHandler\Field\Select
  * @author Teye Heimans
  * @author Marien den Besten
  */
 public function __construct(FormHandler $form, $name)
 {
     // call the constructor of the Field class
     return parent::__construct($form, $name)->setJsSelectorValue('#' . $form->getFormName() . ' select[name="' . $name . '"]')->setSize(1)->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setMultiple(false);
 }
예제 #8
0
 /**
  * Constructor
  *
  * Create a new text field
  *
  * @param FormHandler $form The form where this field is located on
  * @param string $name The name of the field
  * @return \FormHandler\Field\Text
  * @author Teye Heimans
  * @author Marien den Besten
  */
 public function __construct(FormHandler $form, $name)
 {
     // call the constructor of the Field class
     return parent::__construct($form, $name)->setSize(20)->setMaxlength(0);
 }
예제 #9
0
 /**
  * Constructor
  *
  * Create a new file field
  *
  * @param FormHandler $form The form where this field is located on
  * @param string $name The name of the field
  * @return \FormHandler\Field\File
  * @author Teye Heimans
  * @author Marien den Besten
  */
 public function __construct(FormHandler $form, $name)
 {
     static $bSetJS = false;
     // needed javascript included yet ?
     if (!$bSetJS) {
         // include the needed javascript
         $bSetJS = true;
         $form->_setJS(\FormHandler\Configuration::get('fhtml_dir') . "js/upload.js", true);
     }
     parent::__construct($form, $name);
     $form->setEncoding(FormHandler::ENCODING_MULTIPART);
     //upload fields are required by default
     $this->setRequired(true);
     $this->accept = array();
     $this->drop_zone_enabled = false;
     $this->drop_zone_language = array('drop_file' => 'Drop your file here', 'too_large' => 'Given file is too large (Given: %given%, allowed: %allowed%)');
     $this->async = !is_null(filter_input(INPUT_POST, $name . '_submit'));
     $this->button_upload = new Button($form, $name . '_button');
     $this->button_upload->setCaption('Choose File')->setExtra('style="display:none;" class="upload"');
     $this->button_edit = new \FormHandler\Button\Submit($form, $name . '_change');
     $this->button_edit->setCaption('Change file')->setExtra('class="upload"')->onClick(function (FormHandler $form) use($name) {
         $form->setValidationDisabled(true);
         $form->setIsCorrect(false);
         $form->getField($name)->updateState(\FormHandler\Field\File::STATE_EMPTY, null, null);
     });
     //read all open uploads
     $status = $this->readOpenUploads();
     //by default generate a new token
     $generated_token = $this->generateToken();
     //create field
     $this->token = new \FormHandler\Field\Hidden($form, $name . '_token');
     $this->token->setDefaultValue($generated_token);
     $this->filename = new \FormHandler\Field\Hidden($form, $name . '_filename');
     $this->filename->setDefaultValue('');
     $this->state = new \FormHandler\Field\Hidden($form, $name . '_state');
     $this->state->setDefaultValue(self::STATE_EMPTY);
     //process token
     $unsecure_token = $this->token->getValue();
     $token = $this->form_object->isPosted() && !array_key_exists($unsecure_token, $status) ? $generated_token : $unsecure_token;
     $this->token->setValue($token);
     $data = $this->readState();
     try {
         $result = $this->processUpload();
     } catch (Exception $e) {
         $result = false;
         $data = $this->updateState($e->getCode(), null, null);
     }
     if ($result !== false && is_array($result)) {
         $data = $this->updateState(self::STATE_UPLOADED, $result[0], $result[1]);
     }
     if ($this->async) {
         $ajax = array('state' => $data['state'], 'name' => $data['last_processed']);
         //there was an javascript file submit, return state
         //do not send json header because IE will behave strange
         echo json_encode($ajax);
         exit;
     }
     //incorporate max file size
     if (!$form->fieldExists('MAX_FILE_SIZE')) {
         \FormHandler\Field\Hidden::set($form, 'MAX_FILE_SIZE')->setValue($this->getMaxUploadSize(), true)->hideFromOnCorrect();
     }
     return $this;
 }
예제 #10
0
 /**
  * Constructor
  *
  * @author Marien den Besten
  * @param FormHandler $form
  * @param string $name
  * @return \FormHandler\Field\Hidden
  */
 public function __construct(FormHandler $form, $name)
 {
     return parent::__construct($form, $name)->setFocusName(null);
 }
예제 #11
0
 /**
  * Constructor
  *
  * Create a new radio field
  *
  * @param object $form The form where this field is located on
  * @param string $name The name of the field
  * @param array|string $options The options for the field
  * @return \FormHandler\Field\Radio
  * @author Teye Heimans
  * @author Marien den Besten
  */
 public function __construct(FormHandler $form, $name, $options = array())
 {
     // call the constructor of the Field class
     return parent::__construct($form, $name)->setOptions($options)->setMask(\FormHandler\Configuration::get('default_glue_mask'))->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setFocusName($name . '_1');
 }