Tengo un formulario de selección dinámico hecho con script.
Cuando envío con un error, quiero que el formulario permanezca abierto y guarde los datos, pero el formulario solo se abre cuando se detecta un cambio.
Idealmente, tendría el formulario abierto con "valor predeterminado", pero lo cambiaría escuchando.
$('#productType').change(function() { if($(this).val() == 'dvd') { $('#nextStep').html('<label for="size">Size (MB) </label><input type="text" id="size" name="size" value="<?php if (!empty($_POST["size"])) { echo $_POST["size"]; } else { echo ''; }; ?>" required>'); } if($(this).val() == 'book') { $('#nextStep').html('<label for="weight">Weight (KG) </label><input type="text" id="weight" name="weight" value="<?php if (!empty($_POST["weight"])) { echo $_POST["weight"]; } else { echo ''; }; ?>" required>'); } if($(this).val() == 'furniture'){ $('#nextStep').html('<label for="height">Height (CM) </label><input type="text" id="height" name="height" value="<?php if (!empty($_POST["height"])) { echo $_POST["height"]; } else { echo ''; }; ?>" required><br><br><label for="width">Width (CM) </label><input type="text" id="width" name="width" value="<?php if (!empty($_POST["width"])) { echo $_POST["width"]; } else { echo ''; }; ?>" required><br><br><label for="lenght">Lenght (CM) </label><input type="text" id="lenght" name="lenght" value="<?php if (!empty($_POST["lenght"])) { echo $_POST["lenght"]; } else { echo ''; }; ?>" required>'); } });