I searched for a simple script which validates a html-form and if everything is alright submit the form to a php script ... i didn't really find something so here is a simple one of mine
1st - create your form with the js-validation
- <form action="server.php" <brbr=""> onsubmit="return k_checkForm(this);"
- method="post">
- Name: <input type="text" name="name">
- Number: <input type="text" name="phone">
- <input type="submit">
- </form>
2nd - put a validation js somewhere in the html file (preferable in the head section)
- <script language="JavaScript" type="text/javascript">
- function k_checkForm(form) {
- var name=form.name.value;
- var phone_number = form.phone.value;
- if (name == "") {
- alert ("Please enter your name ...");
- return false;
- }
- if (phone_number == "") {
- alert("Please enter your phone number ...");
- return false;
- }
- return true;
- }
- </script>
3nd - php-script (server.php) here you can access the variables like this
- echo $_POST["name"];
- echo $_POST["phone"];
0 Responses to HTML Form validation with js & php processing
Something to say?