Category Archives: forms
symfony 1.4 embedForm 保存2次问题
When a form is embedded, the embedded model representation is saved twice: one via fromArray(), that automatically hydrates related components, and another time via saveEmbeddedForm. 使用embed会出现insert 2次的问题 configure(){ embedRelation(‘ForwardProfile’); } function addProfile(){ //embed a new form $profiles = new sfForm(); … Continue reading
symfony 关联id必须unset才会自动添加
数据库结构2个表: user ———- id name ———- book ———- id user_id(fk) name ———- bookForm.class.php的configure()设置 unset($this['user_id']); 这样embedForm后,user_id值自动添加为user的id值
添加多条记录,字段为空则不添加(bind)
目的: 用户自定义数目的记录,有内容的input则插入数据库,没内容则忽略 例子: 已经embed的字段要用unset()才不会插入数据库 /lib/…/xxForm.class.php … public function addNewTargets($number) { $targets = new sfForm(); for($i=0;$i<$number;$i++) { $target = new WeightTarget(); $target->setWeightWatcher($this->getObject()); $target_from = new WeightTargetForm($target); $targets->embedForm($i, $target_from); } $this->embedForm(‘new’, $targets); } public function bind(array $taintedValues = null, array $taintedFiles = … Continue reading
Embedded forms with symfony 1.4 and jQuery
http://tech.cibul.org/embedded-forms-with-symfony-1-4-and-jquery/ How to implement a single interface to insert multiple entries linked by one-to-many relations… I’ve been looking recently for a way to build a form that would allow the input of data (edition or adding new data) into multiple … Continue reading
symfony上传文件
symfony 1.2 利用form类,设置文件上传。 class WorldImagesForm extends BaseWorldImagesForm { public function configure() { $this->widgetSchema['file'] = new sfWidgetFormInputFile(); $this->validatorSchema['file'] = new sfValidatorFile(array( ‘required’ => false, ‘path’ => sfConfig::get(‘sf_upload_dir’).’/images/guide’, ‘max_size’ => ’5242880′, ‘mime_types’ => ‘web_images’), array( ‘max_size’ => ‘最大15Mb!’, ‘mime_types’ => ‘只支持web图片格式’ )); … Continue reading
bind()与validator表单验证
今天遇到问题,明明setOptions(‘required’,true)但提交空表单renderError却不显示错误。
Symfony Forms: Change validators at runtime
Let’s say you have to make a user form with password fields.