Hi, I am used to validating forms using javascript functions and onSubmit, but I have reached a stage where I really need to do it using PHP instead. Is there any way of calling a PHP function to validate a form on submission ?
Announcement
Collapse
No announcement yet.
PHP form validation
Collapse
X
-
I am basically wanting to compare a textbox value and radio button values, against some database values. It would be way too messy to get the database values and store them as a big string in a hidden field to pass to some JS function so i really need a php function to do the sql and the validation...
Hope that makes a bit of sense at least
Cheers.
Comment
-
There are many ways to approach this.
Usually, the way I go about this is by having the form submit to the same page. For example, if your form is stored in something.php, the form action would be something.php
Here is a simple example, that you might help:
PHP Code:<?php
if(isset($_POST["submit"])) {
//validation code
if(strcmp($_POST["name"], "heaps21") == 0) {
//go to the next page since we validated
echo "<SCRIPT>location.href = 'something_else.php?name=$name';</SCRIPT>";
}
else {
//error comments
echo "<FONT COLOR='RED'>WRONG NAME.</FONT>";
}
?>
<FORM METHOD="POST" ACTION="something.php">
Name: <INPUT TYPE="TEXT" NAME="name">
<INPUT TYPE="submit" NAME="submit">
</FORM>
Hope that helps,
Sadiq.
Comment
Comment