本文整理汇总了PHP中Nette\Forms\Form::addUpload方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::addUpload方法的具体用法?PHP Form::addUpload怎么用?PHP Form::addUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Form
的用法示例。
在下文中一共展示了Form::addUpload方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupForm
protected function setupForm(Form $form)
{
$form->addText('name', 'Name')->setRequired();
$form->addTextArea('description', 'Description')->setAttribute('class', 'editor-standard');
$form->addText('price', 'Price')->setType('number')->setRequired();
$form->addUpload('image', 'Image')->addCondition(Form::FILLED)->addRule(Form::IMAGE);
$form->addText('unit', 'Unit')->setRequired();
$form->addText('vat', 'Vat Rate')->setType('number')->setRequired();
$form->addCheckbox('active', 'Active');
$form->addSubmit('submit', 'Submit');
$this->onPreSave[] = $this->saveImage;
}
示例2: array
// Step 1: Define form
$form = new Form;
$form->addText('name');
$form->addText('age');
$form->addRadioList('gender', NULL, $sex);
$form->addText('email')->setEmptyValue('@');
$form->addCheckbox('send');
$form->addText('street');
$form->addText('city');
$form->addSelect('country', NULL, $countries)->setPrompt('Select your country');
$form->addPassword('password');
$form->addPassword('password2');
$form->addUpload('avatar');
$form->addHidden('userid');
$form->addTextArea('note');
$form->addSubmit('submit');
// Step 1b: Define validation rules
$form['name']->setRequired('Enter your name');
$form['age']->setRequired('Enter your age');
$form['age']->addRule($form::INTEGER, 'Age must be numeric value');
$form['age']->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100));
// conditional rule: if is email filled, ...
$form['email']->addCondition($form::FILLED)
示例3: array
// ... then check email
// group Shipping address
$form->addGroup('Shipping address')->setOption('embedNext', TRUE);
$form->addCheckbox('send', 'Ship to address')->addCondition($form::FILLED)->toggle('sendBox');
// toggle div #sendBox
// subgroup
$form->addGroup()->setOption('container', Html::el('div')->id('sendBox'));
$form->addText('street', 'Street:');
$form->addText('city', 'City:')->addConditionOn($form['send'], $form::FILLED)->setRequired('Enter your shipping address');
$countries = array('World' => array('bu' => 'Buranda', 'qu' => 'Qumran', 'st' => 'Saint Georges Island'), '?' => 'other');
$form->addSelect('country', 'Country:', $countries)->setPrompt('Select your country')->addConditionOn($form['send'], $form::FILLED)->setRequired('Select your country');
// group Your account
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password:')->setRequired('Choose your password')->addRule($form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
$form->addPassword('password2', 'Reenter password:')->setRequired('Reenter your password')->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
$form->addUpload('avatar', 'Picture:')->addCondition($form::FILLED)->addRule($form::IMAGE, 'Uploaded file is not image');
$form->addHidden('userid');
$form->addTextArea('note', 'Comment:');
// group for buttons
$form->addGroup();
$form->addSubmit('submit', 'Send');
$form->setDefaults(array('name' => 'John Doe', 'userid' => 231));
if ($form->isSuccess()) {
echo '<h2>Form was submitted and successfully validated</h2>';
Dumper::dump($form->getValues());
exit;
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Nette Forms basic example</title>
示例4: array
$renderer->wrappers['group']['label'] = 'h3';
$renderer->wrappers['pair']['container'] = NULL;
$renderer->wrappers['controls']['container'] = 'dl';
$renderer->wrappers['control']['container'] = 'dd';
$renderer->wrappers['control']['.odd'] = 'odd';
$renderer->wrappers['label']['container'] = 'dt';
$renderer->wrappers['label']['suffix'] = ':';
$renderer->wrappers['control']['requiredsuffix'] = " •";
$form->addGroup('Personal data');
$form->addText('name', 'Your name')->setRequired('Enter your name');
$form->addRadioList('gender', 'Your gender', array('m' => Html::el('option', 'male')->style('color: #248bd3'), 'f' => Html::el('option', 'female')->style('color: #e948d4')));
$form->addSelect('country', 'Country', array('Buranda', 'Qumran', 'Saint Georges Island'));
$form->addCheckbox('send', 'Ship to address');
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password');
$form->addUpload('avatar', 'Picture');
$form->addTextArea('note', 'Comment');
$form->addGroup();
$form->addSubmit('submit', 'Send');
if ($form->isSuccess()) {
echo '<h2>Form was submitted and successfully validated</h2>';
Dumper::dump($form->getValues());
exit;
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Nette Forms custom rendering example</title>
<link rel="stylesheet" media="screen" href="assets/style.css" />
<style>
示例5:
$form->addEmail('email', 'Email:')->setEmptyValue('@');
// group Shipping address
$form->addGroup('Shipping address')->setOption('embedNext', TRUE);
$form->addCheckbox('send', 'Ship to address')->addCondition($form::FILLED)->toggle('sendBox');
// toggle div #sendBox
// subgroup
$form->addGroup()->setOption('container', Html::el('div')->id('sendBox'));
$form->addText('street', 'Street:');
$form->addText('city', 'City:')->addConditionOn($form['send'], $form::FILLED)->setRequired('Enter your shipping address');
$countries = ['World' => ['bu' => 'Buranda', 'qu' => 'Qumran', 'st' => 'Saint Georges Island'], '?' => 'other'];
$form->addSelect('country', 'Country:', $countries)->setPrompt('Select your country')->addConditionOn($form['send'], $form::FILLED)->setRequired('Select your country');
// group Your account
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password:')->setRequired('Choose your password')->addRule($form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
$form->addPassword('password2', 'Reenter password:')->setRequired('Reenter your password')->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
$form->addUpload('avatar', 'Picture:')->setRequired(FALSE)->addRule($form::IMAGE, 'Uploaded file is not image');
$form->addHidden('userid');
$form->addTextArea('note', 'Comment:');
// group for buttons
$form->addGroup();
$form->addSubmit('submit', 'Send');
$form->setDefaults(['name' => 'John Doe', 'userid' => 231]);
if ($form->isSuccess()) {
echo '<h2>Form was submitted and successfully validated</h2>';
Dumper::dump($form->getValues(), [Dumper::COLLAPSE => FALSE]);
exit;
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Nette Forms basic example</title>