本文整理汇总了PHP中Symfony\Component\Form\Form::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::all方法的具体用法?PHP Form::all怎么用?PHP Form::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertFormToArray
private function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
{
$isRoot = null === $visitor->getRoot();
$form = new \ArrayObject();
$errors = [];
foreach ($data->getErrors() as $error) {
$errors[] = $this->getErrorMessage($error);
}
if (!empty($errors)) {
$form['errors'] = $errors;
}
$children = [];
foreach ($data->all() as $child) {
if ($child instanceof Form) {
$children[$child->getName()] = $this->convertFormToArray($visitor, $child);
}
}
if (!empty($children)) {
$form['children'] = $children;
}
if ($isRoot) {
$visitor->setRoot($form);
}
return $form;
}
示例2: removeExtraFields
/**
* Get rid on any fields that don't appear in the form
*
* @param Request $request
* @param Form $form
*/
protected function removeExtraFields(Request $request, Form $form)
{
$data = $request->request->all();
$children = $form->all();
$data = array_intersect_key($data, $children);
$request->request->replace($data);
}
示例3: getErrorMessages
protected function getErrorMessages(\Symfony\Component\Form\Form $form, $name)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
foreach ($form->all() as $child) {
$type = $child->getConfig()->getType()->getName();
if ($child->count() && $type !== 'choice') {
$childErrors = $this->getErrorMessages($child, $child->getName());
if (sizeof($childErrors)) {
$errors = array_merge($errors, $childErrors);
}
} else {
if (!$child->isValid()) {
if ($name == "responsable1" || $name == "responsable2") {
$errors[$child->getParent()->getParent()->getName() . '_' . $name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
} else {
$errors[$name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
}
}
}
}
return $errors;
}
示例4: getErrorsFromSubForm
/**
* @param Form $form The form subject to validation
* @param string $prefix The field name prefix (concatenation of parents names).
* @return array
*/
private function getErrorsFromSubForm(Form $form, $prefix)
{
$errors = array();
foreach ($form->all() as $child) {
$errors = array_merge($errors, $this->getErrorsArray($child, $prefix), $this->getErrorsFromSubForm($child, sprintf('%s[%s]', $prefix, $child->getName())));
}
return $errors;
}
示例5: groupChild
/**
* {@inheritdoc}
*/
protected function groupChild(Form $form)
{
$group_child = array();
foreach ($form->all() as $child) {
$group_child[substr($child->getName(), 0, -1)][] = $child;
}
return $group_child;
}
示例6: getGroups
/**
* @param Form $form
*
* @return array
*/
protected function getGroups($form)
{
$result = array();
$result['groups'] = $form->getConfig()->getOption('validation_groups');
$result['children'] = array();
/** @var Form $element */
foreach ($form->all() as $name => $element) {
$result['children'][$name] = $this->getGroups($element);
}
return $result;
}
示例7: getErrors
/**
* @return array
*/
protected function getErrors()
{
$errors = [];
$generalErrors = [];
foreach ($this->form->getErrors() as $error) {
$generalErrors[] = $error->getMessage();
}
if (!empty($generalErrors)) {
$errors['general'] = $generalErrors;
}
foreach ($this->form->all() as $field) {
$fieldErrors = [];
foreach ($field->getErrors() as $error) {
$fieldErrors[] = $error->getMessage();
}
if (!empty($fieldErrors)) {
$errors[$field->getName()] = $fieldErrors;
}
}
return $errors;
}
示例8: getForm
/**
* Returns instance of SymfonyForm and fills it with fields from $_fields.
* Checks whether all $_fields are already in the SymfonyForm and adds
* them if necessary.
*
* @return SymfonyForm Returns assigned form
*/
public function getForm()
{
if (!$this->_form) {
$this->_form = $this->_initialiseForm();
}
$formFields = $this->_form->all();
foreach ($this->_fields as $name => &$fieldArray) {
if (!array_key_exists($name, $formFields)) {
$this->_addFieldToSymfonyForm($fieldArray);
}
}
return $this->_form;
}
示例9: removeFields
/**
* This function remove fields available if there are not present in the $data array
* The data array might come from $request->request->all().
*
* This can be usefull if you don't want to send all fields will building an api. As missing
* fields will be threated like null values.
*
* @param array $data
* @param Form $form
*/
public static function removeFields(array $data, Form $form)
{
$diff = array_diff(array_keys($form->all()), array_keys($data));
foreach ($diff as $key) {
$form->remove($key);
}
foreach ($data as $name => $value) {
if (!is_array($value)) {
continue;
}
self::removeFields($value, $form[$name]);
}
}
示例10: getErrorMessages
/**
* @param Form $form
*
* @return array
*/
public function getErrorMessages(Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
return $errors;
}
示例11: getErrorMessages
public function getErrorMessages(BaseForm $form)
{
$errorMessages = [];
if (!$form->isValid()) {
$formData = $form->all();
foreach ($formData as $name => $item) {
if (!$item->isValid()) {
$errorMessages[] = $name . ' - ' . $item->getErrors(true);
}
}
}
return implode(PHP_EOL, $errorMessages);
}
示例12: getFormErrors
/**
* @return array
*/
public function getFormErrors()
{
$errors = array();
foreach ($this->form->getErrors() as $key => $error) {
$errors[$key] = $error->getMessage();
}
// Get errors from children
foreach ($this->form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getFormErrors($child);
}
}
return $errors;
}
示例13: getErrorMessages
protected function getErrorMessages(Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[$key] = $error->getMessage();
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$key = sprintf('%s[%s]', $form->getName(), $child->getName());
$errors[$key] = $this->getErrorMessages($child);
}
}
return $errors;
}
示例14: sanitizeInput
/**
* Method to remove unwanted parameters in the request.
*
* @param array $requestData
* @param Form $form
* @return multitype:unknown
*/
protected function sanitizeInput($requestData, Form $form)
{
$filteredInput = array();
foreach ($form->all() as $childName => $child) {
if ($child->count() > 0 && isset($requestData[$childName])) {
foreach ($child as $grandChildName => $grandChild) {
$filteredInput[$childName][$grandChildName] = $this->sanitizeInput($requestData[$childName], $grandChild);
}
}
if (isset($requestData[$childName])) {
$filteredInput[$childName] = $requestData[$childName];
}
}
return $filteredInput;
}
示例15: processFormErrorsDeeply
public static function processFormErrorsDeeply(Form $form, array &$errors)
{
$children = $form->all();
if (!empty($children)) {
foreach ($children as $childForm) {
self::processFormErrorsDeeply($childForm, $errors);
}
}
// get the errors
$formErrors = $form->getErrors();
foreach ($formErrors as $err) {
$errors[] = $err->getMessage();
}
return;
}