renaud2263 Posted July 20, 2018 Posted July 20, 2018 Bonjour à tous, Dans un module perso j'ai besoin que l'admin puisse saisir une date grâce à un datePicker Donc mon helper : array( 'type' => 'date', 'label' => 'Date de début', 'name' => 'date_debut', 'required' => true, 'col' => 4 ), A l'affichage, j'ai bien mon datePicker, OK. J'ai overridé le form.tpl dans mon module pour que la date s'affiche au format français. if ($(".datepicker").length > 0) $(".datepicker").datepicker({ prevText: '', nextText: '', dateFormat: 'dd-mm-yy' }); Parfait: ça s'affiche en français. Dans la partie type==date du form.tpl j'ai aussi mis (sans trop savoir si c'était vraiment utile) value="{$fields_value[$input.name]|date_format:'%d-%m-%Y'}" /> Mais bien sûr, lors de l'insert ou de l'update, ça ne rentre pas dans le champ date de la table qui est au format yyyy-mm-dd et j'ai toujours 0000-00-00. Comment faire ? J'ai overridé la méthode copyFromPost de la classe adminController : protected function copyFromPost(&$object, $table) { foreach ($_POST as $key => $value) { if (array_key_exists($key, $object) && $key != 'id_'.$table) { /* Do not take care of password field if empty */ if ($key == 'passwd' && Tools::getValue('id_'.$table) && empty($value)) { continue; } /* Automatically hash password in MD5 */ if ($key == 'passwd' && !empty($value)) { $value = $this->get('hashing')->hash($value, _COOKIE_KEY_); } if(strpos($key, 'date') !== false){ $value = $this->myFormatDate($value); } $object->{$key} = $value; } } return $object; } en re-formatant la date en français. Le $object->date_debut affiche bien 'yyyy-mm-dd' preuve que ma date est bien reformatée. Mais pourtant ça plante toujours à l'insert BDD... Je sèche. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now