On submitting a form does the ensuing function have to be javascript or can it also be a .php function?
For example if i have a <form method= "POST" onSubmit="phpfunction(this);"
and then later: <?php function phpfunction(){some function} ?>
- Should I be able to run the php function when the form is submitted?
- is it OK that the form is not within "<?php ?>"
- what should go inside the parenthesis when defining the phpfunction?
PHP runs on the server, JavaScript runs on the browser after the PHP script is long since done and has sent its output to the browser. If you want onsubmit() to run a PHP function without/before actually submitting the form to the server, you'll need to use an AJAX implementation where a JavaScript XMLHttpRequest object calls a PHP file on the server, receives the response from the server and processes it accordingly.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Hey nog, do you know a good resource for stepping into ajax?
Nothing special comes to mind. I think I started with the w3schools.com tutorial, and then just Googled things to fill in the blanks, so to speak. I have a sort of proof on concept page with all the source code you could take a look at, too: http://www.charles-reace.com/test/ajax/
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks