Web Analytics Made Easy -
StatCounter PHP form validation - CodingForum


No announcement yet.

PHP form validation

  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP form validation

    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 ?

  • #2
    well, first of all what type of things are you going to be in need of validating? text boxes? textareas? radio buttons? check boxes?
    ~Designer's Toolz~


    • #3
      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


      • #4
        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:
        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">
        I didn't test this code, but that's the idea. If it doesn't work let me know..

        Hope that helps,


        • #5

          Great! I dont know y i didnt think of that - guess i've been doing so much programming recently its starting to give me mental blocks! Will try and implement something tomorrow but I totally get what you're saying there.