在Symfony Form类中获取提交字段的值


In Symfony Form class get the value of submitted fields

在symfony中,我将如何在表单类中获得$_REQUEST的值。我正在获得action.class.php和模板中所有表单字段的值。在提交表单并验证时,我需要获得一些表单字段的值。请帮帮我!

如果你想要一个表单的值,在它被绑定和验证等:

$value = $myForm->getValue("field_name");

如果你想在传递给表单之前:

public function executeMyAction(sfWebRequest $request)
{
  $myForm = new MyForm();
  $allFormValues = $request->getParameter($myForm->getName());
  $value = $allFormValues["field_name"];
  // usual form stuff follows eg:
  $myForm->bind($allFormValues);
  // ...
}

如果您想要它,例如在您的表单的验证模式的postvalidator方法:

public function myPostValidate($validator, $values)
{
  $myValue = $values["field_name"];
  // ...
  return $values;
}

还有什么,请扩展你的问题,并提供更多的细节,你想做什么:-)

如何使用这个?:

sfContext::getInstance()->getUser()->getAttribute('your_widget_field_name');