开发者

Symfony set hidden value after submit

I have a form with 2 input fields email and password(hidden) . I'm trying to generate a random value as below but failed to bind password(hidden) value after submit.

$password = substr(md5(rand(100000, 999999)), 0, 6);

$this->form->bind($request->setParameter('password',$password));

Form has the setNameformat with:

$this->widgetSchema->开发者_运维问答;setNameFormat('user[%s]');


If a doctrine (or propel) form, I would do this by setting the values on the object before passing to the form constructor, and completely removing the widget from the form.

eg:

$o = new DoctrineOrPropelObject;
$o->setPassword($myrandomstring);
$f = new DoctrineOrPropelObjectForm($o);

Then display/save the form as usual - the password value will be passed right through the form process to the database when saved.


if you use this:

$this->widgetSchema->setNameFormat('user[%s]');

then your form input fields can be retrieved in single variable:

$request->getParameter('user');

and the value that you want to assign need to be set with something like:

$request->setParameter('user[password]', $password);

Reference can be found here.

Regards.


You can override the save method of your form and add $this->values[$field] = $value;

Something like this:

public function save($con = null) 
{
        $this->values['owner_id'] = $this->values['owners_ids'][2];` 
        return parent::save($con); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜