Forms 表单窗口小部件值
我使用表单小部件进行用户注册,其中包含销售或客户单选按钮 若勾选了“客户”按钮,则意味着我必须插入注册表,并且还要插入一个表。因此,我希望在执行$form->save;之前使用表单提交的值;。 如何做到这一点。请帮助我 我的单选按钮字段名是executive\u checkForms 表单窗口小部件值,forms,doctrine,widget,symfony-1.4,Forms,Doctrine,Widget,Symfony 1.4,我使用表单小部件进行用户注册,其中包含销售或客户单选按钮 若勾选了“客户”按钮,则意味着我必须插入注册表,并且还要插入一个表。因此,我希望在执行$form->save;之前使用表单提交的值;。 如何做到这一点。请帮助我 我的单选按钮字段名是executive\u check protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParamete
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()),$request->getFiles($form->getName()));
if ($form->isValid())
{
//i have to check the form user type radio button value here
$form->save();
}
else
{
echo "Error";
}
}
请帮助我……。在我看来,您应该覆盖表单上的save方法,并且不要更改任何操作 例如:
class BookForm extends BaseBookForm {
public function save($con = null) {
if($this->getValue('isCustomer')) {
// do your additional save
}
return parent::save();
}
}
如果要从表单中访问post变量,则必须覆盖注册表中的save函数,并且可以使用名称$this->value访问一个数组中的所有post变量。请尝试下面的方法
public function save($con = null){
// This will list out whole array of the posted variables.
echo "<pre>";
print_r($this->values);
// to use your field variable with named "executive_check" you can get value by below syntax
if($this->values['executive_check'] == 'radiobuttonValue'){
// your logic if sales or customer radio button is selected.
}
// will call parent form save function to save all data
parent::save($con);
}
文档建议重写doSave而不是save。我同意您的看法,即使可以在save函数中使用它。我还建议您在保存注册后进行额外的保存,否则,如果此操作失败,则如果初始保存不正确,则可能会导致数据损坏/无用,或者导致其他表项冗余