/** * Adds a single dropdown. * * @param string $name Name of the element. * @param array $values Values for the dropdown. * @param string $selected The selected elements. * @param bool $multipleSelection Is it possible to select multiple items? * @param string $class Class(es) that will be applied on the element. * @param string $classError Class(es) that will be applied on the element when an error occurs. * * @return \SpoonFormDropdown */ public function addDropdown($name, array $values = null, $selected = null, $multipleSelection = false, $class = null, $classError = null) { $name = (string) $name; $values = (array) $values; $multipleSelection = (bool) $multipleSelection; $class = $class !== null ? (string) $class : 'form-control fork-form-select'; $classError = $classError !== null ? (string) $classError : 'error'; // special classes for multiple if ($multipleSelection) { $class .= ' fork-form-select-multiple'; } // create and return a dropdown return parent::addDropdown($name, $values, $selected, $multipleSelection, $class, $classError); }
public function testMain() { $frm = new SpoonForm('name', 'action'); $frm->addButton('submit', 'submit'); $frm->addCheckbox('agree', true); $frm->addDate('date', time(), 'd/m/Y'); $frm->addDropdown('author', array(1 => 'Davy', 'Tijs', 'Dave'), 1); $frm->addFile('pdf'); $frm->addImage('image'); $frm->addHidden('cant_see_me', 'whoop-tie-doo'); $frm->addMultiCheckbox('hobbies', array(array('label' => 'Swimming', 'value' => 'swimming'))); $frm->addPassword('top_sekret', 'stars-and-stripes'); $frm->addRadiobutton('gender', array(array('label' => 'Male', 'value' => 'male'))); $frm->addTextarea('message', 'big piece of text'); $frm->addText('email', '*****@*****.**'); $frm->addText('now', date('H:i')); }
//create new SpoonForm $frm = new SpoonForm('newProfile'); //create forms elements $frm->addTexts('file', 'case', 'name', 'ic', 'placeofbirth', 'education', 'language', 'race', 'faith', 'maritalstatus', 'nationality', 'profession', 'epf', 'banker', 'contactno', 'email', 'platesno', 'assets', 'eye', 'hair', 'skin', 'dna'); for ($i = 1; $i < 6; $i++) { $frm->addText('company' . $i)->setAttribute("placeholder", "公司名字 company name"); $frm->addText('registerno' . $i)->setAttribute("placeholder", "注册号码 registration number"); $frm->addText('companyno' . $i)->setAttribute("placeholder", "公司号码 Company number"); $frm->addText('companyemail' . $i)->setAttribute("placeholder", "公司电邮 Company email"); $frm->addTextarea('shareholder' . $i)->setAttribute("placeholder", "公司股东 Shareholder"); $frm->addTextarea('registeraddr' . $i)->setAttribute("placeholder", "注册地址 Registered Address"); $frm->addTextarea('businessaddr' . $i)->setAttribute("placeholder", "营业地址Business Address"); } $frm->addTextareas('address', 'family', 'remarks', 'casereport'); $frm->addImage('photo'); $frm->addDropdown('gender', array('' => '', 'male' => 'Male', 'female' => 'Female')); $frm->addText('height')->setAttribute('placeholder', 'digits only'); $frm->addText('weight')->setAttribute('placeholder', 'digits only'); $frm->addDropdown('blood', array('' => '', 'O+' => 'O+', 'A+' => 'A+', 'B+' => 'B+', 'AB+' => 'AB+', 'O-' => 'O-', 'A-' => 'A-', 'B-' => 'B-', 'AB-' => 'AB-')); $frm->addButton('submit', 'Submit'); //if form submitted if ($frm->isSubmitted()) { $frm->getField('name')->isFilled('Please Fill in Client\'s Name.'); if ($frm->getField('email')->isFilled()) { $frm->getField('email')->isEmail('Please provide a valid email address.'); } for ($i = 1; $i < 6; $i++) { if ($frm->getField('companyemail' . $i)->isFilled()) { $frm->getField('companyemail' . $i)->isEmail('Please provide a valid email address.'); } }
/** * Adds a single dropdown. * * @return SpoonFormDropdown * @param string $name Name of the element. * @param array[optional] $values Values for the dropdown. * @param string[optional] $selected The selected elements. * @param bool[optional] $multipleSelection Is it possible to select multiple items? * @param string[optional] $class Class(es) that will be applied on the element. * @param string[optional] $classError Class(es) that will be applied on the element when an error occurs. */ public function addDropdown($name, array $values = null, $selected = null, $multipleSelection = false, $class = null, $classError = null) { // redefine $name = (string) $name; $values = (array) $values; $selected = $selected !== null ? $selected : null; $multipleSelection = (bool) $multipleSelection; $class = $class !== null ? (string) $class : 'select'; $classError = $classError !== null ? (string) $classError : 'selectError'; // special classes for multiple if ($multipleSelection) { $class .= ' selectMultiple'; $classError .= ' selectMultipleError'; } // create and return a dropdown return parent::addDropdown($name, $values, $selected, $multipleSelection, $class, $classError); }