本文整理汇总了PHP中Form::addField方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::addField方法的具体用法?PHP Form::addField怎么用?PHP Form::addField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Form
的用法示例。
在下文中一共展示了Form::addField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action
/**
* The action that displays the entry insert form .
*
* @param PDO $pdo The PDO object.
* @return Opt_View
*/
function action($pdo, $config)
{
$view = new Opt_View('add.tpl');
$view->title = 'Add new entry';
$form = new Form($view);
$form->setAction('index.php?action=add');
$form->addField('author', 'required,min_len=3,max_len=30', 'The length must be between 3 and 30 characters.');
$form->addField('email', 'required,email,min_len=3,max_len=100', 'The value must be a valid mail with maximum 100 characters long.');
$form->addField('website', 'url,min_len=3,max_len=100', 'The value must be a valid URL with maximum 100 characters long.');
$form->addField('body', 'required,min_len=3', 'The body must be at least 3 characters long.');
if ($form->validate()) {
$values = $form->getValues();
$stmt = $pdo->prepare('INSERT INTO `entries` (`author`, `email`, `date`, `website`, `body`)
VALUES(:author, :email, :date, :website, :body)');
$stmt->bindValue(':author', $values['author'], PDO::PARAM_STR);
$stmt->bindValue(':email', $values['email'], PDO::PARAM_STR);
$stmt->bindValue(':date', time(), PDO::PARAM_INT);
$stmt->bindValue(':website', $values['website'], PDO::PARAM_STR);
$stmt->bindValue(':body', $values['body'], PDO::PARAM_STR);
$stmt->execute();
$view->setTemplate('message.tpl');
$view->message = 'The entry has been successfully added!';
$view->redirect = 'index.php?action=list';
} else {
// The form is an object, so we need to inform OPT about it.
$view->form = $form;
$view->setFormat('form', 'Objective');
}
return $view;
}
示例2: getForm
public function getForm($type, $action, $request, $isPost = false, $errors = array())
{
$form = new Form('form-post-' . $type, 'form-post-' . $type, $action, 'POST', 'form-horizontal', $errors, $isPost);
$form->addField('author', Lang::_('Author'), 'text', $this->_getfieldvalue('author', $type, $request), true, '', @$errors['author']);
$form->addField('title', Lang::_('Title'), 'text', $this->_getfieldvalue('title', $type, $request), true, '', @$errors['title']);
$form->addField('content', Lang::_('Content'), 'text', $this->_getfieldvalue('content', $type, $request), true, '', @$errors['content']);
$form->addField('date', Lang::_('Date'), 'date', $this->_getfieldvalue('date', $type, $request), false, '', @$errors['date']);
return $form;
}
示例3: getForm
public function getForm($type, $action, $request, $isPost = false, $errors = array())
{
$form = new Form($id = 'form-picture', $name = 'form-picture', $action, 'POST', 'form-horizontal', $isPost);
$form->addField('id', Lang::_('Picture Id'), 'text', $this->_getfieldvalue('id', $type, $request), true, '', @$errors['id']);
$form->addField('quarter_id', Lang::_('Quarter id'), 'text', $this->_getfieldvalue('quarter_id', $type, $request), false, '', @$errors['quarter_id']);
$form->addField('src', Lang::_('Src'), 'file', $this->_getfieldvalue('src', $type, $request), false, '', @$errors['src']);
$form->addField('info_id', Lang::_('Info id'), 'text', $this->_getfieldvalue('info_id', $type, $request), true, '', @$errors['info_id']);
$form->addField('user_id', Lang::_('User id'), 'text', $this->_getfieldvalue('user_id', $type, $request), true, '', @$errors['user_id']);
return $form->render();
}
示例4: view
/**
* Loads our index/default welcome/dashboard screen
*/
public function view()
{
$form = new Form('config');
// add all config variables to our form
$sql = sprintf('SELECT * FROM config');
$model = model()->open('config');
$records = $model->results();
if ($records) {
foreach ($records as $record) {
$value = $record['current_value'] == '' ? $record['default_value'] : $record['current_value'];
$form->addField($record['config_key'], $value, $value);
}
}
// process the form if submitted
if ($form->isSubmitted()) {
foreach (app()->params->getRawSource('post') as $field => $value) {
$model->update(array('current_value' => $value), $field, 'config_key');
}
sml()->say('Website settings have been updated successfully.');
router()->redirect('view');
}
$data['form'] = $form;
$model = model()->open('pages');
$model->where('page_is_live', 1);
$data['pages'] = $model->results();
// $data['mods'] = app()->moduleControls();
$data['themes'] = $this->listThemes();
$data['live'] = settings()->getConfig('active_theme');
template()->addCss('style.css');
template()->addJs('admin/jquery.qtip.js');
template()->addJs('view.js');
template()->display($data);
}
示例5: getForm
function getForm($action)
{
$form = new Form('site_globals', $action);
foreach ($this as $key => $value) {
$form->addField(['name' => $key, 'label' => $key, 'type' => 'text', 'value' => $value]);
}
return $form;
}
示例6: importField
/**
* Import one field from model into form.
*
* @param string $field
* @param string $field_name
*
* @return void|Form_Field
*/
public function importField($field, $field_name = null)
{
$field = $this->model->hasElement($field);
if (!$field) {
return;
}
/** @type Field $field */
if (!$field->editable()) {
return;
}
if ($field_name === null) {
$field_name = $this->_unique($this->owner->elements, $field->short_name);
}
$field_type = $this->getFieldType($field);
$field_caption = $field->caption();
$this->field_associations[$field_name] = $field;
if ($field->listData() || $field instanceof Field_Reference) {
if ($field_type == 'Line') {
$field_type = 'DropDown';
}
}
$form_field = $this->owner->addField($field_type, $field_name, $field_caption);
$form_field->set($field->get());
$field_placeholder = $field->placeholder() ?: $field->emptyText() ?: null;
if ($field_placeholder) {
$form_field->setAttr('placeholder', $field_placeholder);
}
if ($field->hint()) {
$form_field->setFieldHint($field->hint());
}
if ($field->listData()) {
/** @type Form_Field_ValueList $form_field */
$a = $field->listData();
$form_field->setValueList($a);
}
if ($msg = $field->mandatory()) {
$form_field->validateNotNULL($msg);
}
if ($field instanceof Field_Reference || $field_type == 'reference') {
$form_field->setModel($field->getModel());
}
if ($field->theModel) {
$form_field->setModel($field->theModel);
}
if ($form_field instanceof Form_Field_ValueList && !$field->mandatory()) {
/** @type string $text */
$text = $field->emptyText();
$form_field->setEmptyText($text);
}
if ($field->onField()) {
call_user_func($field->onField(), $form_field);
}
return $form_field;
}
示例7: edit
/**
* Displays and processes the add/edit user form
* @access public
* @param integer $id
*/
public function edit($id = false)
{
$result = false;
$form = new Form('users', $id, array('groups'));
$form->addField('password_confirm');
// process the form if submitted
if ($form->isSubmitted()) {
$result = $form->save($id);
}
template()->set(array('form' => $form));
return $result;
}
示例8: getForm
public function getForm($type, $action, $request, $isPost = false, $errors = array())
{
$form = new Form($id = 'form-comment', $name = 'form-comment', $action, 'POST', 'form-horizontal', $isPost);
$form->addField('id', Lang::_('Id'), 'text', $this->_getfieldvalue('id', $type, $request), true, '', @$errors['id']);
$form->addField('user_id', Lang::_('User Id'), 'text', $this->_getfieldvalue('user_id', $type, $request), true, '', @$errors['user_id']);
$form->addField('quarter_id', Lang::_('Quarter Id'), 'text', $this->_getfieldvalue('quarter_id', $type, $request), false, '', @$errors['quarter_id']);
$form->addField('info_id', Lang::_('Info Id'), 'text', $this->_getfieldvalue('info_id', $type, $request), false, '', @$errors['info_id']);
$form->addField('content', Lang::_('Content'), 'text-area', $this->_getfieldvalue('content', $type, $request), true, '', @$errors['content']);
$form->addField('photo_id', Lang::_('Photo Id'), 'file', $this->_getfieldvalue('photo_id', $type, $request), false);
return $form->render();
}
示例9: edit
/**
* @abstract Edits an event recprd
* @param integer $id
* @access public
*/
public function edit($id = false)
{
$form = new Form('courses', $id);
// grab existing groups settings
$model = model()->open('course_groups_link');
$model->where('course_id', $id);
$group_records = $model->results();
$groups = array();
if ($group_records) {
foreach ($group_records as $course_record) {
$groups[] = $course_record['group_id'];
}
}
$form->addField('groups', $groups, $groups);
// proces the form if submitted
if ($form->isSubmitted()) {
// validation
if (!$form->isFilled('title')) {
$form->addError('title', 'You must enter a course title.');
}
// if we have no errors, process sql
if (!$form->error()) {
if ($res_id = $form->save($id)) {
$id = $id ? $id : $res_id;
// update course groups
$model->delete('course_groups_link', $id, 'course_id');
$groups = $form->cv('groups');
foreach ($groups as $group) {
$sql = sprintf('INSERT INTO course_groups_link (course_id, group_id) VALUES ("%s", "%s")', $id, $group);
$model->query($sql);
}
// if successful insert, redirect to the list
sml()->say('The course has successfully been saved.');
router()->redirect('view');
}
}
}
$data['form'] = $form;
template()->addView(template()->getTemplateDir() . DS . 'header.tpl.php');
template()->addView(template()->getModuleTemplateDir() . DS . 'edit.tpl.php');
template()->addView(template()->getTemplateDir() . DS . 'footer.tpl.php');
template()->display($data);
}
示例10: createFromConfig
public static function createFromConfig($config, $data = [], $errors = [])
{
$form = new Form($data, $errors);
if (isset($config['fields'])) {
if (isset($config['defaults']) && isset($config['defaults']['fields'])) {
$field_defaults = $config['defaults']['fields'] + self::$fieldsDefaults;
} else {
$field_defaults = self::$fieldsDefaults;
}
foreach ($config['fields'] as $key => $fc) {
if (!isset($fc['name'])) {
trigger_error('Skipping index "' . $key . '". No name attibute.', E_USER_WARNING);
continue;
}
extract(self::parseDynamicValues(array_replace_recursive($field_defaults, $fc)));
if (!isset($data[$name]) && !is_null($default)) {
$data[$name] = $default;
}
if ($required) {
$attributes["required"] = "required";
}
$field = $form->addField($type, $name, $label, $choices, $group, $attributes, $container_attributes, $html);
}
$form->setData($data);
if (isset($config['layout'])) {
$form->setGroupLayout($config['layout']);
}
if (isset($config['groups'])) {
foreach ($config['groups'] as $groupname => $groupconfig) {
$groupconfig = array_replace_recursive(self::$groupsDefaults, $groupconfig);
$form->defineGroup($groupname, $groupconfig['label'], $groupconfig['attributes']);
}
}
}
return $form;
}
示例11: getQueryResults
getQueryResults($sql);
$headers = 'From: No Reply <signup@' . $_SERVER['HTTP_HOST'] . '>' . CRLF;
$subject = 'Your account signup at ' . $_SERVER['HTTP_HOST'];
$content = 'Thank you for your request for any account.' . CR . CR;
$content .= 'To validate your signup please follow the link below' . CR;
$content .= 'http://' . $_SERVER['HTTP_HOST'] . $config->get('web', 'root') . '/signup/at8/?v=' . md5($member['camra_number']) . CR;
$content .= CR . CR . 'Thank you.';
mail($member['email'], $subject, $content, $headers);
header('Location: ' . $config->get('web', 'root') . '/signup/thankyou/');
exit;
} else {
$form->submiterrormsg .= '<p class="error">Username/CAMRA Number is already registered.</p><p> Please choose another one or check with your system administrator.</p>';
}
}
$form->addFieldsetOpen('Signup');
$form->addField('firstname', 'text', $member['firstname']);
$form->addLabel('Firstname');
$form->addFieldValidation('required');
$form->addField('lastname', 'text', $member['lastname']);
$form->addLabel('Lastname');
$form->addFieldValidation('required');
$form->addField('email', 'text', $member['email']);
$form->addLabel('Email Address');
$form->addFieldValidation('required email');
$form->addField('camra_number', 'text', $member['camra_number']);
if ($config->get('web', 'signupNonCamra')) {
$form->addLabel('CAMRA Membership Number/Username');
$form->addFieldValidation('required');
} else {
$form->addLabel('CAMRA Membership Number');
$form->addFieldValidation('required numeric');
示例12: getForm
public function getForm($type, $action, $request, $isPost = false, $errors = array())
{
$form = new Form($id = 'form-contact', $name = 'form-contact', $action, 'POST', 'form-horizontal', $isPost);
$form->addField('lastname', Lang::_('Lastname'), 'text', $this->_getfieldvalue('lastname', $type, $request), true, '', @$errors['lastname']);
$form->addField('firstname', Lang::_('Firstname'), 'text', $this->_getfieldvalue('firstname', $type, $request), true, '', @$errors['firstname']);
$form->addField('email', Lang::_('Email'), 'email', $this->_getfieldvalue('email', $type, $request), true, '', @$errors['email']);
$form->addField('message', Lang::_('Message'), 'textarea', $this->_getfieldvalue('message', $type, $request), true, '', @$errors['message']);
$form->addField('cgu', Lang::_('Accept the terms of service'), 'checkbox', $this->_getfieldvalue('cgu', $type, $request), true, '', @$errors['cgu']);
return $form->render();
}
示例13: array
}
}
/*
if ($app["type"] == "Lunch" || $app["type"] == "Note" || $app["type"] == "Meeting") {
$db_data["app_status"] = 'Cancelled';
db_query($db_data,"UPDATE","appointment","app_id",$app["id"]);
header("Location:calendar.php?branch=".$app["branch"]."&y=$y&m=$m&d=$d");
exit;
}
*/
$formData1 = array('notes' => array('type' => 'textarea', 'label' => 'Reason for Cancelling', 'value' => '', 'attributes' => array('class' => 'noteInput')));
$form = new Form();
$form->addForm("app_form", "POST", $PHP_SELF);
$form->addHtml("<div id=\"standard_form\">\n");
$form->addField("hidden", "action", "", "update");
$form->addField("hidden", "app_id", "", $app_id);
$form->addField("hidden", "searchLink", "", urlencode($return));
$form->addHtml("<fieldset>\n");
$form->addHtml('<div class="block-header">Cancel ' . $app["type"] . '</div>');
$form->addHtml('<p class="appInfo">Please remember to inform all vendors/landlords and/or viewers that this appointment has been cancelled</p>');
$form->addData($formData1, $_POST);
$form->addHtml(renderNotes('appointment_cancel', $app_id, array('label' => 'Cancellation Notes')));
$buttons = $form->makeField("submit", $formName, "", "Save Changes", array('class' => 'submit'));
$form->addHtml($form->addDiv($buttons));
$form->addHtml("</fieldset>\n");
$form->addHtml('</div>');
if (!$_POST["action"]) {
/*
if ($_GET["searchLink"]) {
$searchLink = str_replace("%3F","?",replaceQueryStringArray($_GET["searchLink"],array('app_id'))).'&jumpto='.$hour;
示例14: while
$numRows = $q->numRows();
if ($numRows !== 0) {
while ($row = $q->fetchRow()) {
foreach ($row as $key => $val) {
${$key} = $val;
}
}
}
$formData1 = array('cli_salemin' => array('type' => 'select_price', 'value' => $cli_salemin, 'label' => 'Minimum Price', 'group' => 'Price Range', 'required' => 2, 'options' => array('scope' => 'sales', 'default' => 'Minimum'), 'attributes' => array('style' => 'width:120px')), 'cli_salemax' => array('type' => 'select_price', 'value' => $cli_salemax, 'label' => 'Maximum Price', 'group' => 'Price Range', 'last_in_group' => 1, 'required' => 2, 'options' => array('scope' => 'sales', 'default' => 'Maximum'), 'attributes' => array('style' => 'width:120px')), 'cli_salebed' => array('type' => 'select_number', 'value' => $cli_salebed, 'label' => 'Minimum Beds', 'required' => 2), 'cli_saleemail' => array('type' => 'radio', 'value' => $cli_saleemail, 'label' => 'Email Updates', 'required' => 2, 'options' => db_enum("client", "cli_saleemail", "array")));
$ptype_sale = ptype("sale", explode("|", $cli_saleptype));
$formData2 = array('cli_letmin' => array('type' => 'select_price', 'value' => $cli_letmin, 'label' => 'Minimum Price', 'group' => 'Price Range', 'required' => 2, 'options' => array('scope' => 'lettings', 'default' => 'Minimum'), 'attributes' => array('style' => 'width:120px')), 'cli_letmax' => array('type' => 'select_price', 'value' => $cli_letmax, 'label' => 'Maximum Price', 'group' => 'Price Range', 'last_in_group' => 1, 'required' => 2, 'options' => array('scope' => 'lettings', 'default' => 'Maximum'), 'attributes' => array('style' => 'width:120px')), 'cli_letbed' => array('type' => 'select_number', 'value' => $cli_letbed, 'label' => 'Minimum Beds', 'required' => 2), 'cli_letemail' => array('type' => 'radio', 'value' => $cli_letemail, 'label' => 'Email Updates', 'required' => 2, 'options' => db_enum("client", "cli_letemail", "array")));
$ptype_let = ptype("let", explode("|", $cli_letptype));
$form = new Form();
$form->addHtml("<div id=\"standard_form\">\n");
$form->addForm("", "get");
$form->addField("hidden", "stage", "", "requirements");
$form->addField("hidden", "action", "", "update");
$form->addField("hidden", "cli_id", "", $cli_id);
$form->addField("hidden", "app_id", "", $_GET["app_id"]);
$form->addField("hidden", "searchLink", "", $searchLink);
$form->addHtml("<fieldset>\n");
$form->addLegend('Sales Requirements');
$form->addHtml($form->addLabel('cli_saleptype', 'Houses', $ptype_sale['house'], 'javascript:checkAll(document.forms[0], \'sale1\');'));
$form->addHtml($form->addLabel('cli_saleptype', 'Apartments', $ptype_sale['apartment'], 'javascript:checkAll(document.forms[0], \'sale2\');'));
$form->addHtml($form->addLabel('cli_saleptype', 'Others', $ptype_sale['other'], 'javascript:checkAll(document.forms[0], \'sale3\');'));
$form->addData($formData1, $_GET);
$form->addHtml($form->addDiv($form->makeField("submit", "submit", "", "Save Changes", array('class' => 'submit'))));
$form->addHtml("</fieldset>\n");
$form->addHtml("<fieldset>\n");
$form->addLegend('Lettings Requirements');
$form->addHtml($form->addLabel('cli_letptype', 'Houses', $ptype_let['house'], 'javascript:checkAll(document.forms[0], \'sale1\');'));
示例15: elseif
} elseif ('deleteUser' == $form->submittedaction) {
getQueryResults('DELETE FROM user WHERE id=' . $request->get('post', 'member_id'));
header('Location: ' . $config->get('web', 'root') . '/admin/?msg=User+deleted');
exit;
}
} else {
if (!is_null($member_id) && '' != $member_id && 'new' != $member_id) {
$member = reset(getQueryResults('SELECT * FROM ' . $config->get('database', 'tablePrefix') . 'user WHERE id=' . $member_id));
} elseif ('new' == $member_id) {
$member = array('id' => 'new', 'firstname' => $request->get('post', 'firstname') ? $request->get('post', 'firstname') : '', 'lastname' => $request->get('post', 'lastname') ? $request->get('post', 'lastname') : '', 'type' => 'reviewer', 'camra_number' => $request->get('post', 'camra_number') ? $request->get('post', 'camra_number') : '', 'postcode' => $request->get('post', 'postcode') ? $request->get('post', 'postcode') : '', 'email' => $request->get('post', 'email') ? $request->get('post', 'email') : '', 'active' => $request->get('post', 'active') != 1 ? 0 : 1);
} else {
$members = getQueryResults('SELECT id, CONCAT(lastname, \', \', firstname) as name FROM `' . $config->get('database', 'tablePrefix') . 'user` ORDER BY `lastname`,`firstname`;');
}
}
if (isset($members)) {
$form->addField('member_id', 'select');
$form->addLabel('Select Member');
$form->addOptions(array('new' => 'Add New Member'));
$form->addOptions($members, 'id', 'name');
$form->addField('selectMember', 'submit', 'Select Member');
$form->addInputClass('btnSubmit');
} else {
$form->addField('member_id', 'hidden', $member['id']);
$form->addField('firstname', 'text', $member['firstname']);
$form->addLabel('Firstname');
$form->addFieldValidation('required');
$form->addField('lastname', 'text', $member['lastname']);
$form->addLabel('Lastname');
$form->addFieldValidation('required');
$form->addField('email', 'text', $member['email']);
$form->addLabel('Email Address');