Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 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
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Regular Coder
    Join Date
    Feb 2004
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    I didn't test this code, but that's the idea. If it doesn't work let me know..

    Hope that helps,
    Sadiq.

  • #5
    Regular Coder
    Join Date
    Feb 2004
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ah!

    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.
    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •