Ecommerce Shopify WordPress Discussion

Form not submitting correctly when adding input type file

I have the following function in a wordpress function: function custom_form_display() { if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['custom_form_nonce']) && wp_verify_nonce($_POST['custom_form_nonce'], 'custom_form_send')) { //...handling form inputs and sending emails... echo '<p>Form submitted!</p>'; } else { wp_enqueue_script('jquery'); echo '<script type="text/javascript"> jQuery(document).ready(function($) { $("#num_ospiti").change(function(){ var numOspiti = $(this).val(); var ospitiHtml = ""; for(var i = 1; i <= numOspiti; i++) { ospitiHtml += "<div><strong>Ospite " + i + "</strong><br>"; ospitiHtml += "<label for=\'nome_"+i+"\'>Nome:</label>"; ospitiHtml += "<input type=\'text\' name=\'nome[]\' required><br>"; ospitiHtml += "<label for=\'cognome_"+i+"\'>Cognome:</label>"; ospitiHtml += "<input type=\'text\' name=\'cognome[]\' required><br>"; ospitiHtml += "<label for=\'sesso_"+i+"\'>Sesso:</label>"; ospitiHtml += "<select name=\'sesso[]\' required><option value=\'Maschio\'>Maschio</option><option value=\'Femmina\'>Femmina</option></select><br>"; ospitiHtml += "<label for=\'data_nascita_"+i+"\'>Data di nascita (gg/mm/aaaa):</label>"; ospitiHtml += "<input type=\'text\' name=\'data_nascita[]\' required><br>"; ospitiHtml += "<label for=\'comune_nascita_"+i+"\'>Comune di nascita:</label>"; ospitiHtml += "<input type=\'text\' name=\'comune_nascita[]\' required><br>"; ospitiHtml += "<label for=\'provincia_nascita_"+i+"\'>Provincia di nascita:</label>"; ospitiHtml += "<input type=\'text\' name=\'provincia_nascita[]\' required><br>"; ospitiHtml += "<label for=\'cittadinanza_"+i+"\'>Cittadinanza:</label>"; ospitiHtml += "<input type=\'text\' name=\'cittadinanza[]\' required><br>"; ospitiHtml += "<label for=\'tipo_documento_"+i+"\'>Tipologia di documento:</label>"; ospitiHtml += "<input type=\'text\' name=\'tipo_documento[]\' required><br>"; ospitiHtml += "<label for=\'numero_documento_"+i+"\'>N. Documento:</label>"; ospitiHtml += "<input type=\'text\' name=\'numero_documento[]\' required><br>"; ospitiHtml += "<label for=\'luogo_rilascio_"+i+"\'>Luogo/Stato di rilascio:</label>"; ospitiHtml += "<input type=\'text\' name=\'luogo_rilascio[]\' required><br>"; } $("#ospiti").html(ospitiHtml); }); }); </script>'; // Mostra il form echo '<form action="' . esc_url($_SERVER['REQUEST_URI']) . '" method="post" enctype="multipart/form-data">'; wp_nonce_field('custom_form_send', 'custom_form_nonce'); echo '<p><label for="struttura">La tua struttura:</label><br> <select name="struttura" id="struttura" required> <option value="">Seleziona una struttura...</option> <option value="Portici sul Giardino - Dimora dei Portici">Portici sul Giardino - Dimora dei Portici</option> <option value="Terrazza sulla Maiella - Dimora dei Portici">Terrazza sulla Maiella - Dimora dei Portici</option> <option value="Loft Trabocco - Dimora dei Portici">Loft Trabocco - Dimora dei Portici</option> <option value="Villa dei Trabocchi">Villa dei Trabocchi</option> <option value="Suites Montemare">Suites Montemare</option> <option value="Piccolo Loft Sabbia e Sassi">Piccolo Loft Sabbia e Sassi</option> <option value="Mare, Monti e Limoni">Mare, Monti e Limoni</option> <option value="Dimora Fonte Grande">Dimora Fonte Grande</option> </select></p>'; // Dropdown per il numero di ospiti echo '<p><label for="num_ospiti">N. di Ospiti:</label><br> <select name="num_ospiti" id="num_ospiti" required> <option value="">Seleziona il numero di ospiti...</option>'; for ($i = 1; $i <= 10; $i++) { echo "<option value='$i'>$i</option>"; } echo '</select></p>'; echo '<div id="ospiti"></div>'; echo '<p><label for="email">Email:</label><br> <input type="email" id="email" name="email" value="" required></p>'; // When I add this code for file upload the form seems not submitting correctly echo '<input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <label for="documento_">Documento (immagine):</label> <input type="file" name="documento_" required></div><br>'; echo '<p><input type="submit" value="Invia"></p>'; echo '</form>'; } } I also added file_uploads=On to php.ini When I try to submit this form the page seems to just reload and not correctly submit the form. In fact if I put var_dump($_POST); at the beginning of the function it always shows array(0) { } If I try to not include the file upload it works just fine.
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.