Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Thanked 12 Times in 12 Posts

    Exclamation Form Validation, whats the correct method?

    Hi All,

    I am wondering if someone could kindly assist me with validating a form. The reason i have posted this in the General web building forum is because there are more than one way to skin a cat as im sure you are aware and im not sure where to start

    I have been searching the internet looking for examples and yes there are many out there, but i am yet to find a 'standard' way of validating a form. They all vary the majority of them are just not up to standard!

    basically what i am looking for is the best way to validate any form i were to create. does anyone have any examples or tutorials which would work on most browsers and devices?

    appreciate any help

    here is my current form code
    <form action="add_job_process.php" method="post">
    <legend>Job Essentials</legend>
    <label><span>Title</span><input name="job_title" type="text"></label>
    <label><span>Description</span><textarea id="job_desc" name="job_desc"></textarea></label>
    <select name="job_loc" size="1">
    	<option value="full">Full Time</option>
      	<option value="part">Part Time</option>
      	<option value="seasonal">Seasonal</option>
        <option value="other">Other</option>
    <label>Job Location</label>
    <select name="job_loc" size="1">
    	<option value="1">1</option>
      	<option value="2">2</option>
      	<option value="3">3</option>
    <legend>Job Details</legend>
    <label><span>Job Requirements</span><textarea id="job_req" name="job_req"></textarea></label>
    <label><span>Job Start Date</span><input name="job_start" type="text"></label>
    <label><span>Job Hours P/W</span><input name="job_hours" type="text"></label>
    <label><span>Flexible Hours</span><input name="flex_hours" type="checkbox" value="0"></label>
    <label><span>Starting Wage </span><input name="wage" type="text"></label>
    <legend>Social Media</legend>
    <label>Tick this box if you want to promote this job to our facebook and twitter fans <b>for free</b>!</label><input name="promote" type="checkbox" value="0">
    <div class="box-hint">like box to go here</div>
    <legend>Human Verification</legend>
    <div class="box-hint">captcha to go here</div>
    <legend>Terms and Conditions</legend>
    <label>By agreeing to these terms and conditions you agree to your job advery being placed on this site for a minimum of 30 days, after the 30 day free promotion is up you will be contacted to set up payment to continue to be advertised on this site</label><input name="promote" type="checkbox" value="0">
    <input name="submit" type="submit">
    add_job_process.php is currently empty

    thanks for any help

  2. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts
    1. Use built in functions for validation where possible eg. is_numeric() for fields that must contain numbers
    2. use validation filters where possible - eg. if (filter_var($POST['email'], FILTER_VALIDATE_EMAIL)) { to validate email addresses.
    3. where neither of the above are possible then use a regular expression for the validation

    Do not move the values out of the $_POST array until after you have validated the fields so as to ensure that no invalid data will ever be found in local variables.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


Posting Permissions

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