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));
 }
 /**
  * FormHandler::checkBox()
  *
  * Create a checkBox on the form
  *
  * @param string $title The title of the field
  * @param string $name The name of the field
  * @param array|string $value The option(s) 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 string $extra CSS, Javascript or other which are inserted into the HTML tag
  * @param string $mask if more the 1 options are given, glue the fields together with this mask
  * @return \FormHandler\Field\CheckBox
  * @author Teye Heimans
  * @deprecated Use \FormHandler\Field\CheckBox::set() instead
  */
 public function checkBox($title, $name, $value = 'on', $validator = null, $useArrayKeyAsValue = null, $extra = null, $mask = null)
 {
     $field = \FormHandler\Field\CheckBox::set($this, $title, $name);
     return $field->setValidator(self::parseValidator($validator, $field))->setOptions($value)->useArrayKeyAsValue($useArrayKeyAsValue)->setExtra($extra)->setMask($mask);
 }
 * 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();
Field\CheckBox::set($form, '', 'inherit')->setOptions(array(1 => 'Normal option', 2 => 'Force value', 3 => 'Normal option 2'))->setValue(1)->setValue(2, true, true)->setValue(3, false, true)->setDisabled(3);
Button\Submit::set($form, 'Submit');
$form->onCorrect(function () {
    return false;
});
//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 forcing values on checkboxes<hr>';
echo $form_html;
 * 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;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
$form = new FormHandler();
Field\CheckBox::set($form, '', 'inherit')->setOptions(array(1 => 'Inherit from parent, integer value'));
Field\CheckBox::set($form, '', 'inherit1')->setOptions(array(1 => 'Linked to above'));
Field\CheckBox::set($form, '', 'inherit3')->setOptions(array('1' => 'Linked to first checkbox, string value'))->setDisabled();
Field\CheckBox::set($form, 'Multi values<br>', 'inherit4')->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'))->setValue(2, true, true);
Field\Text::set($form, 'Linked to first checkbox', 'inherit2');
$link = function ($v) {
    $value = !empty($v);
    return \FormHandler\FormHandler::returnDynamic(array($value), null, null, null, 'checkbox');
};
$form->link('inherit', 'inherit1', $link);
$form->link('inherit', 'inherit3', $link);
$form->link('inherit', 'inherit4', $link);
$form->link('inherit', 'inherit2', function ($v) {
    return \FormHandler\FormHandler::returnDynamic(json_encode($v), null, null, null, 'text');
});
//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 linking checkboxes<hr>';
 * 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();
Field\CheckBox::set($form, '', 'inherit')->setOptions(array(1 => 'Normal option', 2 => 'Force value', 3 => 'Normal option 2', 4 => 'Set by default value option'))->setValue(1)->setValue(2, true, true)->setValue(3, false, true)->setDefaultValue(4);
Button\Submit::set($form, 'Submit');
$form->onCorrect(function () {
    return false;
});
//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 forcing values on checkboxes<hr>';
echo $form_html;