Ne pas utiliser de input type=“submit”, ça provoque des bugs sur je-sais-plus-quel vieux navigateur. Preuve ?
Solution : ajouter une deuxième checkbox cachée avec une value 0 et l'option checked sans conditions, au-dessus de celle visible. Seule la dernière checkbox checked sera prise en compte par le formulaire.
<input style="display: none;" type="checkbox" class="input-txt" name="MENU_EN_COURS" value="0" checked/> <input type="checkbox" class="input-txt" name="MENU_EN_COURS" value="1" {if isset($k_options.MENU_EN_COURS) && $k_options.MENU_EN_COURS == 1}checked{/if}>
Penser à rajouter cet attribut au <form>
enctype="multipart/form-data"
Exemple de code d'upload pour Prestahop :
// Image upload handling if (isset($_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['name']) && !empty($_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['name']) && !empty($_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['tmp_name'])) { // Check for maximum filesize before everything else // if( $_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['size'] > self::MAX_UPLOAD_FILESIZE ) // { // $this->errors[] = Tools::displayError( sprintf('The file is too large. You must upload a file of %u Mo maximum.', (self::MAX_UPLOAD_FILESIZE / 1024 / 1024) ) ); // return false; // } $extension = pathinfo( $_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['name'], PATHINFO_EXTENSION ); $filename = 'boesnerchassis_home.' . $extension; $filename = str_replace(' ', '-', $filename); $filename = strtolower($filename); $filename = filter_var($filename, FILTER_SANITIZE_STRING); $_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['name'] = $filename; $upload_result = move_uploaded_file($_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/img/' . $_FILES['BLOCKCOUPDECOEUR_1_IMAGE']['name']); if( $upload_result == true ) { Configuration::updateValue('BLOCKCOUPDECOEUR_1_IMAGE', _PS_BASE_URL_ . __PS_BASE_URI__ . 'img/' . $filename); } else { // TODO error message } }
$('.keyTimes').on('submit', function(e) { e.preventDefault(); console.log('Nope lol'); console.log(e); });
Also to get the value of the first select in the form (first [0]) : e.target[0].options[e.target[0].options.selectedIndex].value