Questo funziona perfettamente! ;)
Questo può essere fatto usando Ajax e con quello che chiamo: "un elemento mirror modulo". Invece di inviare un modulo con un elemento esterno, è possibile creare un modulo falso. Il modulo precedente non è necessario.
<!-- This will do the trick -->
<div >
<input id="mirror_element" type="text" name="your_input_name">
<input type="button" value="Send Form">
</div>
Il codice ajax sarebbe come:
<script>
ajax_form_mirror("#mirror_element", "your_file.php", "#your_element_response", "POST");
function ajax_form_mirror(form, file, element, method) {
$(document).ready(function() {
// Ajax
$(form).change(function() { // catch the forms submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: method, // GET or POST
url: file, // the file to call
success: function (response) { // on success..
$(element).html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
});
}
</script>
Questo è molto utile se si desidera inviare alcuni dati all'interno di un altro modulo senza inviare il modulo principale.
Questo codice probabilmente può essere adattato / ottimizzato in base alle necessità. Funziona perfettamente !! ;) Funziona anche se vuoi una casella di opzione di selezione come questa:
<div>
<select id="mirror_element" name="your_input_name">
<option id="1" value="1">A</option>
<option id="2" value="2">B</option>
<option id="3" value="3">C</option>
<option id="4" value="4">D</option>
</select>
</div>
Spero che abbia aiutato qualcuno come me ha aiutato me. ;)