public function setValidator($validator = null)
 {
     if (count($this->getValidators()) === 0 && $validator instanceof FormHandler\Validator\FunctionCallable && is_array($validator->getCallable())) {
         $callable = $validator->getCallable();
         //detect if it is an optional validator
         if ($callable[0] instanceof Validator && substr($callable[1], 0, 1) !== '_') {
             parent::setValidator(new \FormHandler\Validator\NotEmpty());
         }
     }
     return parent::setValidator(FormHandler::parseValidator($validator, $this));
 }
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
echo 'Test for multi link view mode';
echo '<hr>';
$form = new FormHandler();
Field\Text::set($form, 'Single value', 'field1')->setViewMode()->setValue('VALUE')->setViewModeLink('startofurl?value={$value}&extra=1');
Field\Select::set($form, 'Multi value', 'field2')->setViewMode()->setValue(array(1, 2))->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'))->setViewModeLink('startofurl?value={$value}&extra=1');
//process all form results, needs to be done before any output has been done
$form_html = $form->flush();
//below is code to show the form
echo 'Test for view mode links with one or multiple values set<hr>';
echo $form_html;
 /**
  * FormHandler::selectField()
  *
  * Create a selectField on the form
  *
  * @param string $title The title of the field
  * @param string $name The name of the field
  * @param array $options The options used for the field
  * @param string $validator The validator which should be used to validate the value of the field
  * @param boolean $useArrayKeyAsValue If the array key's are the values for the options in the field
  * @param boolean $multiple Should it be possible to select multiple options ? (Default: false)
  * @param int $size The size of the field (how many options are displayed)
  * @param string $extra CSS, Javascript or other which are inserted into the HTML tag
  * @return \FormHandler\Field\Select
  * @author Teye Heimans
  * @deprecated Use \FormHandler\Field\Select::set() instead
  */
 public function selectField($title, $name, $options = null, $validator = null, $useArrayKeyAsValue = null, $multiple = null, $size = null, $extra = null)
 {
     $field = \FormHandler\Field\Select::set($this, $title, $name);
     return $field->setOptions(empty($options) ? null : $options)->setValidator(self::parseValidator($validator, $field))->useArrayKeyAsValue($useArrayKeyAsValue)->setExtra($extra)->setMultiple($multiple)->setSize($size);
 }
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
$form = new FormHandler();
$status_list = array('to_be_processed' => 'To be processed', 'in_process' => 'In process', 0 => 'Finished');
foreach ($status_list as $k => $v) {
    Field\Select::set($form, $v, sha1($v))->setDefaultValue(array($k, 'in_process'))->setOptions($status_list)->setMultiple(true)->setSize(3);
}
//process all form results, needs to be done before any output has been done
$form_html = $form->flush();
//below is code to show the form
echo 'Test for selecting multiple values<hr>';
echo $form_html;
Exemplo n.º 5
0
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
$form = new FormHandler();
$status_list = array('to_be_processed' => 'To be processed', 'in_process' => 'In process', 0 => 'Finished');
foreach ($status_list as $k => $v) {
    Field\Select::set($form, $v, sha1($v))->setDefaultValue($k)->setOptions($status_list);
}
//process all form results, needs to be done before any output has been done
$form_html = $form->flush();
//below is code to show the form
echo 'Test for setting values on select field<hr>';
echo $form_html;
Exemplo n.º 6
0
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
$form = new FormHandler();
Field\Select::set($form, 'Multi value 1', 'watch1')->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'));
Field\Select::set($form, 'Multi value 2', 'watch2')->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'));
for ($i = 1; $i <= 20; $i++) {
    Field\Text::set($form, 'Field ' . $i, 'field_' . $i)->setValue('Value ' . $i)->setAppearanceCondition(array('watch1', 'watch2'), function ($value) {
        return $value['watch2'] == 2;
    });
}
//process all form results, needs to be done before any output has been done
$form_html = $form->flush();
//below is code to show the form
echo 'Test for grouping multi appearance. Setting multi value 2 on value 2 should display all fields, with one ajax request<hr>';
echo $form_html;