« See all FAQs for vPad - HTML5+CSS3 App Framework
I can’t get the value form using a method=”post”.. when load the page, all values and session variables disappear
I have problems figuring out how to create a form that sends the data via post to a php-file and display some response afterwards (e.g. a “Thank you for your submission” page).
Answered by guicara
the easiest way is to use AJAX and JSON . For example, in your “view” file, where you have your form:<form id="foo" action="your_script.php" ...> <input type="text" name="bar" /> ... </form>The jQuery / Ajax part (to put also in the view file):$('#foo').submit(function(){ var dataForm = $(this).serialize(); var urlForm = $(this).attr('action'); $.ajax({ type: 'POST', url: urlForm, data: dataForm, dataType: 'json', success: function(msg) { if (msg.success) alert(msg.text); else alert("Something's wrong!"); } }); return false; // for not reload the page });Finally, you just have to complete your PHP script by something like that:// For example, get a POST var: $bar = $_POST['bar']; // Do everything else (eg. add data to BDD, send email, etc...) // Display the answer $message = array( 'text' => 'Ok! Everything is allright!', 'success' => TRUE ); echo json_encode($message); exit;

