本文整理汇总了PHP中sfForm::getFormFieldSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP sfForm::getFormFieldSchema方法的具体用法?PHP sfForm::getFormFieldSchema怎么用?PHP sfForm::getFormFieldSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfForm
的用法示例。
在下文中一共展示了sfForm::getFormFieldSchema方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processForm
protected function processForm(sfWebRequest $request, sfForm $form, $celulaId = null)
{
$asistencia = $request->getParameter('reunion')['asistencias'];
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
$fields = $form->getFormFieldSchema()->getValue();
if ($form->isValid()) {
$reunion = $form->save();
foreach ($reunion->getAsistencias() as $borrable) {
$borrable->delete();
}
$asistencias = explode(',', $asistencia);
foreach ($asistencias as $key => $asistencia) {
if ($asistencia > 0) {
$source = new Asistencia();
$source->setReunionId($reunion->getId());
$source->setMiembroCelulaId($asistencia);
$source->save();
}
}
$this->getUser()->setFlash('notice', "Reunión guardada exitosamente", true);
if (isset($celulaId)) {
$this->redirect('celulas/show?id=' . $celulaId);
} else {
$this->forward('celulas', 'index');
}
}
$this->getUser()->setFlash('error', "Error!!! " . $form->getErrorSchema(), true);
if (isset($celulaId)) {
$this->redirect('celulas/show?id=' . $celulaId);
} else {
$this->forward('celulas', 'index');
}
}
示例2: sfWidgetFormSchemaFormatterList
$w = $f->getWidgetSchema();
$w->addFormFormatter('custom', new sfWidgetFormSchemaFormatterList($w));
$t->is($f->renderUsing('custom'), fix_linebreaks($output), 'renderUsing() renders a custom form formatter');
try {
$f->renderUsing('nonexistant');
$t->fail('renderUsing() throws an exception if formatter name does not exist');
} catch (InvalidArgumentException $e) {
$t->pass('renderUsing() throws an exception if formatter name does not exist');
}
// renderHiddenFields()
$t->diag('->renderHiddenFields()');
$f = new sfForm();
$f->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText(), 'is_admin' => new sfWidgetFormInputHidden()));
$output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="is_admin" id="is_admin" />';
$t->is($f->renderHiddenFields(), $output, 'renderHiddenFields() renders all hidden fields, no visible fields');
$t->is(count($f->getFormFieldSchema()), 3, 'renderHiddenFields() does not modify the form fields');
$author = new sfForm();
$author->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText()));
$company = new sfForm();
$company->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText()));
$author->embedForm('company', $company);
$output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="company[id]" id="company_id" />';
$t->is($author->renderHiddenFields(), $output, 'renderHiddenFields() renders hidden fields from embedded forms');
$output = '<input type="hidden" name="id" id="id" />';
$t->is($author->renderHiddenFields(false), $output, 'renderHiddenFields() does not render hidden fields from embedded forms if the first parameter is "false"');
// ->embedForm()
$t->diag('->embedForm()');
$author = new FormTest(array('first_name' => 'Fabien'));
$author->setWidgetSchema($author_widget_schema = new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInputText())));
$author->setValidatorSchema($author_validator_schema = new sfValidatorSchema(array('first_name' => new sfValidatorString(array('min_length' => 2)))));
$company = new FormTest();
示例3: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$fieldSc = $form->getFormFieldSchema();
$widget = $fieldSc->getWidget();
$params = array();
foreach ($widget->getFields() as $key => $object) {
if ($key == "sf_guard_group_permission_list") {
continue;
}
$data = $request->getParameter($key);
$data_dec = json_decode($data);
$params[$key] = is_array($data_dec) ? $data_dec : $data;
}
$form->bind($params);
if ($form->isValid()) {
try {
$group = $form->save();
} catch (Exception $e) {
$response = array('success' => false, 'error' => 'Could not perform operation', 'agent' => sfConfig::get('config_acronym'), 'info' => 'Could not perform operation');
return $response;
}
return array('success' => true, 'object' => $group->toArray());
} else {
$errors = array();
foreach ($form->getFormattedErrors() as $error) {
$errors[] = $error;
}
$error_msg = implode($errors);
$info = implode('<br>', $errors);
$response = array('success' => false, 'error' => $error_msg, 'agent' => sfConfig::get('config_acronym'), 'info' => $info);
return $response;
}
}
示例4: js_form_fields
function js_form_fields(sfForm $form)
{
$fieldSc = $form->getFormFieldSchema();
$loginFormItems = '';
$widget = $fieldSc->getWidget();
$validatorSchema = $form->getValidatorSchema();
foreach ($widget->getFields() as $key => $object) {
// echo($key);
$label = $fieldSc->offsetGet($key)->renderLabelName();
$type = $object->getOption('type');
if ($type == 'text') {
$type = 'textfield';
}
$name = $widget->generateName($key);
$allowBlank = 'true';
$extraItem = '';
if ($validatorSchema[$key] instanceof sfValidatorCSRFToken) {
$csrfToken = $form->getDefault($key);
$extraItem = ",value:'" . $csrfToken . "'";
}
if (isset($validatorSchema[$key]) and $validatorSchema[$key]->getOption('required') == true) {
$allowBlank = 'false';
}
$loginFormItems[] = "{id:'" . $key . "',fieldLabel: '" . $label . "',name: '" . $name . "',inputType:'" . $type . "',allowBlank:" . $allowBlank . $extraItem . "}\n\t\t";
}
// die();
$loginFormItems = implode(",", $loginFormItems);
// echo($loginFormItems);
// echo("<script>alert('oi');</script>");
return $loginFormItems;
}