/**
  * Validates the data contained in the given form control using the validator
  * specified by the given form control.
  *
  * @param FormControl $control
  *
  * @return boolean
  */
 public function validate($control)
 {
     if (preg_match($this->getRegexpForValidator($control->getValidator()), $control->getData())) {
         return TRUE;
     }
     return FALSE;
 }
Exemple #2
0
 /**
  * New rule or condition notification callback.
  * @param  Rule
  * @return void
  */
 public function notifyRule(Rule $rule)
 {
     if ($rule->type === Rule::VALIDATOR && is_string($rule->operation) && strcasecmp($rule->operation, ':mimeType') === 0) {
         $this->control->accept = $rule->arg;
     }
     parent::notifyRule($rule);
 }
 public function set_value($value, $manually = true)
 {
     if ($value != false) {
         $this->returned_value = $value;
     }
     return parent::set_value($value, $manually);
 }
Exemple #4
0
 public function notifyRule(Rule $rule)
 {
     if (is_string($rule->operation) && strcasecmp($rule->operation, ':float') === 0) {
         $this->addFilter(array(__CLASS__, 'filterFloat'));
     }
     parent::notifyRule($rule);
 }
Exemple #5
0
 /**
  * This control only validates if it's clicked
  * @return array If empty, no errors.  One string element describing each error
  */
 public function validate()
 {
     if (isset($_POST[$this->input_name()])) {
         return parent::validate();
     }
     return array();
 }
Exemple #6
0
 public function get(Theme $theme)
 {
     $silos = Media::dir();
     foreach ($silos as &$silo) {
         $silo->path_slug = Utils::slugify($silo->path);
     }
     $this->vars['silos'] = $silos;
     return parent::get($theme);
 }
Exemple #7
0
 /**
  * This method will be called when the component (or component's parent)
  * becomes attached to a monitored object. Do not call this method yourself.
  * @param  IComponent
  * @return void
  */
 protected function attached($form)
 {
     if ($form instanceof Form) {
         if ($form->getMethod() !== Form::POST) {
             throw new InvalidStateException('File upload requires method POST.');
         }
         $form->getElementPrototype()->enctype = 'multipart/form-data';
     }
     parent::attached($form);
 }
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     $control = FormControl::getControl();
     // skopirovany kod z SelectBox.php
     if ($this->isFirstSkipped()) {
         $items = $this->items;
         reset($items);
         $control->data['nette-empty-value'] = $this->areKeysUsed() ? key($items) : current($items);
     }
     $selected = $this->getValue();
     $this->selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
     $this->formatOptions($this->items, $control);
     return $control;
 }
 public function __construct($formName, $courseList)
 {
     parent::__construct();
     $this->setName($formName);
     $this->addHidden('id');
     $this->addHidden('recipientsCount')->withData(0);
     $this->addHidden('enqueuedmsg')->withData(translateFN('Newsletter inoltrata per l\'invio'));
     $userType = FormControl::create(FormControl::SELECT, 'userType', translateFN('Tipo Utente'))->withData(array(0 => translateFN('Scegli il tipo...'), AMA_TYPE_AUTHOR => translateFN('Autore'), AMA_TYPE_STUDENT => translateFN('Studente'), AMA_TYPE_TUTOR => translateFN('Tutor'), AMA_TYPE_SWITCHER => translateFN('Switcher'), 9999 => translateFN('Tutti')), 0)->setRequired()->setValidator(FormValidator::POSITIVE_NUMBER_VALIDATOR);
     $userPlatformStatus = FormControl::create(FormControl::SELECT, 'userPlatformStatus', translateFN('Stato Studente nella Piattaforma'))->withData(array(-1 => translateFN('Scegli lo stato...'), ADA_STATUS_PRESUBSCRIBED => translateFN('Non Confermato'), ADA_STATUS_REGISTERED => translateFN('Confermato')), -1)->setAttribute('disabled', 'true')->setValidator(FormValidator::POSITIVE_NUMBER_VALIDATOR);
     $userCourseStatus = FormControl::create(FormControl::SELECT, 'userCourseStatus', translateFN('Stato Studente nel corso selezionato'))->withData(array(-1 => translateFN('Scegli lo stato...'), ADA_SERVICE_SUBSCRIPTION_STATUS_UNDEFINED => translateFN('In visita'), ADA_SERVICE_SUBSCRIPTION_STATUS_REQUESTED => translateFN('Preiscritto'), ADA_SERVICE_SUBSCRIPTION_STATUS_ACCEPTED => translateFN('Iscritto'), ADA_SERVICE_SUBSCRIPTION_STATUS_SUSPENDED => translateFN('Rimosso'), ADA_SERVICE_SUBSCRIPTION_STATUS_COMPLETED => translateFN('Completato')), -1)->setAttribute('disabled', 'true')->setValidator(FormValidator::POSITIVE_NUMBER_VALIDATOR);
     $this->addFieldset(translateFN('Filtro') . ' ' . translateFN('Utenti'), 'userChoice')->withData(array($userType, $userPlatformStatus, $userCourseStatus));
     $courseList[0] = translateFN('Scegli il corso...');
     $courseSel = FormControl::create(FormControl::SELECT, 'idCourse', translateFN('Corso'))->withData($courseList, 0)->setAttribute('disabled', 'true')->setValidator(FormValidator::POSITIVE_NUMBER_VALIDATOR);
     $instanceSel = FormControl::create(FormControl::SELECT, 'idInstance', translateFN('Istanza Corso'))->setAttribute('disabled', 'true')->setValidator(FormValidator::POSITIVE_NUMBER_VALIDATOR);
     $this->addFieldset(translateFN('Filtro') . ' ' . translateFN('Corsi'), 'courseChoice')->withData(array($courseSel, $instanceSel));
     $this->setSubmitValue(translateFN('Invia Newsletter'));
 }
Exemple #10
0
 /**
  * Get this control for display
  * @param Theme $theme The theme to use for rendering
  * @return string The output
  */
 public function get(Theme $theme)
 {
     $this->vars['element'] = $this->get_setting('wrap_element', 'div');
     $content = '';
     foreach ($this->value as $key => $data) {
         // Push the $key of this array item into the control's name
         $this->each(function (FormControl $control) use($key) {
             $control->add_input_array($key);
         });
         $content .= $this->get_contents($theme);
         // Pop the key of this array item out of the control's name
         $this->each(function (FormControl $control) {
             $control->pop_input_array();
         });
     }
     $this->vars['content'] = $content;
     return FormControl::get($theme);
 }
Exemple #11
0
 public function get(Theme $theme)
 {
     $this->properties['type'] = 'hidden';
     $this->properties['data-facet-config'] = json_encode($this->properties['data-facet-config']);
     $this->set_template_properties('div', array('id' => $this->get_visualizer(), 'data-target' => $this->get_id()));
     return parent::get($theme);
 }
Exemple #12
0
 /**
  * Produce HTML output for this text control.
  *
  * @param boolean $forvalidation True if this control should render error information based on validation.
  * @return string HTML that will render this control in the form
  */
 public function get(Theme $theme)
 {
     $this->vars['options'] = $this->options;
     $this->settings['internal_value'] = true;
     return parent::get($theme);
 }
Exemple #13
0
    /**
     * Render the controls.init script prior to the supplied script only if it hasn't already been rendered
     * @param string $out An existing script that depends on controls.init
     * @return string The script with the controls.init script prepended, if needed
     */
    public function controls_js($out)
    {
        if (FormControl::$controls_js == false) {
            $js = '
			<script type="text/javascript">
			if(controls==undefined){
				var controls = {
					init:function(fn){
						if(fn!=undefined){
							controls.inits.push(fn);
						}else{
							for(var i in controls.inits){
								controls.inits[i]();
							}
						}
					},
					inits:[]
				};
			}
			$(function(){
				controls.init();
			});
			</script>';
            $out = $js . $out;
            FormControl::$controls_js = true;
        }
        return $out;
    }
Exemple #14
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->value = $this->translate($this->caption);
     return $control;
 }
	/**
	 * Return the HTML construction of the control, after changing the encoding of the parent form to allow for file uploads.
	 *
	 * @param boolean $forvalidation True if the control should output validation information with the control.
	 */
	public function get( $forvalidation = true )
	{
		$form = $this->get_form();
		$form->properties['enctype'] = 'multipart/form-data';

		return parent::get( $forvalidation );
	}
 /**
  * @author giorgio 29/mag/2013
  * 
  * added extra parameter to constructor to allow editing of student confirmed registration
  * 
  */
 public function __construct($languages = array(), $allowEditProfile = false, $allowEditConfirm = false, $action = null)
 {
     parent::__construct();
     $this->addHidden('id_utente')->withData(0);
     /*
      *  @author:Sara  20/05/2014
      *  Workaround to remove the Google-Chrome autocomplete functionality.
      */
     $j = 'return remove_false_element()';
     $this->setOnSubmit($j);
     $false_username = FormControl::create(FormControl::INPUT_TEXT, 'false_username', '');
     $false_password = FormControl::create(FormControl::INPUT_PASSWORD, 'false_password', '');
     $false_elements_fieldset = FormControl::create(FormControl::FIELDSET, 'false_elements_fieldset', '');
     $false_elements_fieldset->setHidden();
     $false_elements_fieldset->withData(array($false_username, $false_password));
     $this->addControl($false_elements_fieldset);
     $this->addPasswordInput('password', translateFN('Password'));
     //->setValidator(FormValidator::PASSWORD_VALIDATOR);
     $this->addPasswordInput('passwordcheck', translateFN('Conferma la password'));
     /**
      * If the swithcer does not use this form to edit her own
      * profile, the avatar upload must be disabled
      */
     if ($_SESSION['sess_userObj']->getType() != AMA_TYPE_SWITCHER || !$allowEditConfirm) {
         $this->addFileInput('avatarfile', translateFN('Seleziona un file immagine per il tuo avatar'));
         $this->addTextInput('avatar', NULL);
     }
     if ($action != null) {
         $this->setAction($action);
     }
     /// $this->addTextInput('telefono', translateFN('Telefono'));
     $telefono = FormControl::create(FormControl::INPUT_TEXT, 'telefono', translateFN('Telefono'));
     $cap = FormControl::create(FormControl::INPUT_TEXT, 'cap', translateFN('cap'));
     $citta = FormControl::create(FormControl::INPUT_TEXT, 'citta', translateFN('Città'));
     $indirizzo = FormControl::create(FormControl::INPUT_TEXT, 'indirizzo', translateFN('Indirizzo'));
     $provincia = FormControl::create(FormControl::INPUT_TEXT, 'provincia', translateFN('Provincia'));
     $countries = countriesList::getCountriesList($_SESSION['sess_user_language']);
     $nazione = FormControl::create(FormControl::SELECT, 'nazione', translateFN('Nazione'));
     $nazione->withData($countries);
     $this->addFieldset(translateFN('Dati residenza'), 'residenza')->withData(array($indirizzo, $cap, $citta, $provincia, $nazione, $telefono));
     //        $this->addTextInput('indirizzo', translateFN('Indirizzo'));
     //        $this->addTextInput('citta', translateFN('Città'));
     //        $this->addTextInput('provincia', translateFN('Provincia'));
     /*
            $countries = countriesList::getCountriesList($_SESSION['sess_user_language']);
            $this->addSelect(
                'nazione',
                 translateFN('Nazione'),
                 $countries,
            'IT');
     * 
     */
     $this->addTextInput('codice_fiscale', translateFN('Cod. Fiscale'));
     /**
      * @author giorgio 29/mag/2013
      * 
      * added select field to allow editing of user confirmed registration status
      */
     if ($allowEditConfirm) {
         $this->addSelect('stato', translateFN('Confermato'), array(ADA_STATUS_PRESUBSCRIBED => translateFN('No'), ADA_STATUS_REGISTERED => translateFN('Si')), 0);
     }
     //->setValidator(FormValidator::PASSWORD_VALIDATOR);
     if ($allowEditProfile) {
         $this->addTextarea('profilo', translateFN('Il tuo profilo utente'));
     }
     $layoutsAr = array('' => translateFN('seleziona un layout'));
     $layoutObj = new UILayout();
     $avalaibleLayoutAr = $layoutObj->getAvailableLayouts();
     $layouts = array_merge($layoutsAr, $avalaibleLayoutAr);
     $this->addSelect('layout', translateFN('Layout'), $layouts, 0);
     if (is_array($languages) && count($languages) > 0) {
         $languagesAr[0] = translateFN('seleziona una lingua');
         $languages = array_replace($languagesAr, $languages);
         //            $languages = array_merge($languagesAr,$languages);
         $this->addSelect('lingua', translateFN('Lingua'), $languages, 0);
     }
 }
 /**
  * Render this control
  * Ensures that this control has an id property
  * @param Theme $theme The theme used to render the control
  * @return string The HTML output of the control
  */
 public function get(Theme $theme)
 {
     $this->get_id(true);
     $this->set_settings(array('html_value' => json_encode($this->value)));
     return parent::get($theme);
 }
Exemple #18
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue);
 }
Exemple #19
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     return parent::getControl()->checked($this->value);
 }
Exemple #20
0
 /**
  * Generates label's HTML element.
  * @return void
  */
 public function getLabel()
 {
     $label = parent::getLabel();
     $label->for = NULL;
     return $label;
 }
Exemple #21
0
 /**
  * @param  string  label
  */
 public function __construct($label)
 {
     $this->monitor('Nette\\Forms\\Form');
     parent::__construct($label);
     $this->control->type = 'file';
 }
Exemple #22
0
 /**
  * Generates label's HTML element.
  * @param  string
  * @return void
  */
 public function getLabel($caption = NULL)
 {
     $label = parent::getLabel($caption);
     $label->for = NULL;
     return $label;
 }
Exemple #23
0
 public function __construct($value, $name = null)
 {
     parent::__construct($name);
     $this->value($value);
 }
Exemple #24
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $selected = $this->getValue();
     $selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
     $option = Html::el('option');
     foreach ($this->items as $key => $value) {
         if (!is_array($value)) {
             $value = array($key => $value);
             $dest = $control;
         } else {
             $dest = $control->create('optgroup')->label($key);
         }
         foreach ($value as $key2 => $value2) {
             if ($value2 instanceof Html) {
                 $dest->add((string) $value2->selected(isset($selected[$key2])));
             } elseif ($this->useKeys) {
                 $dest->add((string) $option->value($key2)->selected(isset($selected[$key2]))->setText($this->translate($value2)));
             } else {
                 $dest->add((string) $option->selected(isset($selected[$value2]))->setText($this->translate($value2)));
             }
         }
     }
     return $control;
 }
 /**
  * Component factory.
  * @see Nette/ComponentContainer#createComponent()
  */
 protected function createComponentForm($name)
 {
     // NOTE: signal-submit on form disregard component's state
     //		because form is created directly by Presenter in signal handling phase
     //		and this principle is used to detect submit signal
     if (!$this->wasRendered) {
         $this->receivedSignal = 'submit';
     }
     $form = new AppForm($this, $name);
     $form->setTranslator($this->getTranslator());
     FormControl::$idMask = 'frm-datagrid-' . $this->getUniqueId() . '-%s-%s';
     $form->onSubmit[] = array($this, 'formSubmitHandler');
     $form->addSubmit('resetSubmit', 'Reset state');
     $form->addSubmit('filterSubmit', 'Apply filters');
     $form->addSelect('operations', 'Selected:', $this->operations);
     $form->addSubmit('operationSubmit', 'Send')->onClick = $this->onOperationSubmit;
     // page input
     $form->addText('page', 'Page', 1);
     $form['page']->setDefaultValue($this->page);
     $form->addSubmit('pageSubmit', 'Change page');
     // items per page selector
     $form->addSelect('items', 'Items per page', array_combine($this->displayedItems, $this->displayedItems));
     $form['items']->setDefaultValue($this->itemsPerPage);
     $form->addSubmit('itemsSubmit', 'Change');
     // generate filters FormControls
     if ($this->hasFilters()) {
         $defaults = array();
         $sub = $form->addContainer('filters');
         foreach ($this->getFilters() as $filter) {
             $sub->addComponent($filter->getFormControl(), $filter->getName());
             // NOTE: must be setted after is FormControl conntected to the form
             $defaults[$filter->getName()] = $filter->value;
         }
         $sub->setDefaults($defaults);
     }
     // checker
     if ($this->hasOperations()) {
         $sub = $form->addContainer('checker');
         if ($this->isSignalReceiver('submit')) {
             // NOTE: important!
             $ds = clone $this->dataSource;
             $this->filterItems();
         }
         foreach ($this->getRows() as $row) {
             $sub->addCheckbox($row[$this->keyName], $row[$this->keyName]);
         }
         if (isset($ds)) {
             $this->dataSource = $ds;
         }
     }
     $renderer = $form->getRenderer();
     $renderer->wrappers['controls']['container'] = NULL;
     $renderer->wrappers['label']['container'] = NULL;
     $renderer->wrappers['control']['container'] = NULL;
     $form->setRenderer($renderer);
     return;
 }
Exemple #26
0
 /**
  * Called upon construct.  Sets default control properties
  */
 public function __construct($name, $storage = 'null:null', array $properties = array(), array $settings = array())
 {
     $this->properties['type'] = 'text';
     parent::__construct($name, $storage, $properties, $settings);
 }
Exemple #27
0
 public function notifyRule(Rule $rule)
 {
     if ($rule->type === Rule::VALIDATOR && strcasecmp($rule->operation, ':float') === 0) {
         $this->addFilter(array(__CLASS__, 'filterFloat'));
     }
     parent::notifyRule($rule);
 }
Exemple #28
0
 /**
  * A validation function that returns an error if the value passed is not within a specified range
  *
  * @param string $value A value to test if it is empty
  * @param FormControl $control The control that defines the value
  * @param FormContainer $container The container that holds the control
  * @param float $min The minimum value, inclusive
  * @param float $max The maximum value, inclusive
  * @param string $warning An optional error message
  * @return array An empty array if the value is value, or an array with strings describing the errors
  */
 public static function validate_range($value, $control, $container, $min, $max, $warning = null)
 {
     if ($value < $min) {
         if ($warning == null) {
             $warning = _t('The value entered for %s is lesser than the minimum of %d.', array($control->get_label(), $min));
         }
         return array($warning);
     } elseif ($value > $max) {
         if ($warning == null) {
             $warning = _t('The value entered for %s is greater than the maximum of %d.', array($control->get_label(), $max));
         }
         return array($warning);
     } else {
         return array();
     }
 }
Exemple #29
0
 /**
  * Set the value of this control
  * @param mixed $value The value to set
  * @param bool $manually True if this value is set internally rather than being POSTed in the form
  * @return FormControl $this
  */
 public function set_value($value, $manually = true)
 {
     $this->node->value = $value;
     return parent::set_value($value, $manually);
 }
Exemple #30
0
 /**
  * Apply this label to a control
  * @param FormControl $for The control that this label is for
  * @return FormControlLabel $this
  */
 public function set_for($for)
 {
     $this->properties['for'] = $for->get_id();
     return $this;
 }