Is there a built-in way to use setDefaults($arr) with a Form inside a
Multiplier ?
I do this :
protectedfunctioncreateComponentProductForm(){returnnewMultiplier(function($productId){$form=newNette\Application\UI\Form;$form->addText('name','nom du produit:')->setRequired('Entrer un nom pour le produit.');$form->addText('details','description du produit:')->setRequired('Entrer une description pour le produit.');$form->addText('baseprice','prix de base:')->setRequired('Entrer un prix de base pour le produit.');$form->addHidden('productId',$productId);$form->addSubmit('send','Modifier');$form->setDefaults($this->resultSet[$productId]);// this is the tricky partreturn$form;});}publicfunctionactionList(){$products=$this->productManager->getProduct();//with no parameter = get all products$this->template->products=$products;while($product=$products->fetch()){$this->resultSet[$product["id"]]=$product;// this is the tricky part}}
publicfunctionproductFormSucceeded(Form$form,$values){$productId=$values['productId'];$this->database->table('products')->where('id',$productId)->update(['name'=>$values->name,'details'=>$values->details,'baseprice'=>$values->baseprice]);$this->flashMessage('produit "'.$values->name.'" mis à jour','success');$this->redirect('this');}
But do you think I could get the productId by any other way to validate the
form ?…