SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Location
    UK
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can a PHP Form Vaildation Work along Side a Standard Form Vaildation

    Hello Everbody, My names andy and am a newby here, with some Knowledge to Web design..But not a Pro. by far not.

    I have a website am working on, that will advertise a hoilday Let...

    The contact forms are done in PHP and is Vaildated and asks for items like Name , email, address, and so on. On the same page is the jquery Datepicker and it to is Vaildated with this call to script <script src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>.

    The problem am facing is, I can not make these too Vaildation work together on the same page.

    When the PHP fields for the Name and Email are filled in, you then select the dates you want from the datepicker,, then you press Submit, and the form is Submitted if all field are Right. and thats what i want.

    But the snag is if you dont select any date from the picker and press submit,, it will send with empty fields from the picker and not pick up on the empty form.

    Both these codes work great on there own, but joint them together on one page one underneath each other and the PHP takes control and the script does not run the Vaildation for the picker. The picker does work if you do input the date, it will email all the forms. Oh and there is just one submit button.

    Can show the code

    Any ideas of how to fix this.

    thanks Andy

  2. #2
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If by standard form validation you mean browser-side (client-side, usually Javascript) validation then this can definitely co-exist with server-side PHP validation. The browser-side validation is called first (with Javascript) and then the form data is sent to be processed by PHP on the server side (assuming is is valid, generally a failed browser-side validation will halt the sending of the form to the server).

    It sounds to me as if you want to stop a form with empty fields being posted to the server - browser-side validation with Javascript would work, if you want an instant notification to the user that they must fill in the form before submitting.

    However you should never rely on Javascript validation alone, a user can simply disable Javascript and bypass it. Your PHP needs to have a way of dealing with empty form fields, and should never assume that validation will have occurred beforehand with Javascript.

    Therefore my suggestion would be for you to program your PHP script to handle empty fields in some way - redisplay the form with error messages for instance - and once that's working, add additional Javascript validation to complement the DatePicker validation.

    Hopefully I've understood what you're trying to say, posting the code you're using would be helpful!

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The validation of the form that you require has to be done on the server as that's the only place where you have control of whether it runs or not.

    Any JavaScript validation is there for the convenience of the person filling out the form. It tells them about errors straight away rather than them filling out the whole form and submitting it and then being told that they entered everything wrong (as will still happen for the small percentage who don't have JavaScript but there's nothing you can do to provide faster feedback for them).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,319
    Mentioned
    462 Post(s)
    Tagged
    8 Thread(s)
    Hi Andy16296. Welcome to the forums.

    Does the PHP part of the form check to see if the date field is empty?

  5. #5
    SitePoint Member
    Join Date
    Dec 2012
    Location
    UK
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes the Php code all works and vaildates the form field and so does the datepicker's form that all works too. the problem lie when i place them together on the page only the php would work then. what am going to do is to post my code on here if you could take a look. thanks andy

  6. #6
    SitePoint Member
    Join Date
    Dec 2012
    Location
    UK
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Alex for the reply,, I will post the code on here , if you dont mine taking a look. thanks andy


Bookmarks

Posting Permissions

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