#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    30
    Rep Power
    2

    .js validation works for email but not submission to database.


    Hi:

    i have site contact form that validates required fields w/ .js And php.
    if browser has javascript turned on, the req'd info error message will show next to the field boxes ..

    if javascript is turned off, then
    user will see the same thing but coming from php instead...

    the submit goes to database and personal email.
    email received shows complete field boxes info.. as expected..

    the database will show incomplete submissions that the .js was sposed to stop..
    example:: like name is filled but missing email and such..

    how can this be so?...
    must be something simple//

    i didnt try to disable the .js validation to see what happens..
    i would rather fix it and keep it

    here is code if someone can look at it..
    http://jsbin.com/ixupuk/1/edit

    thanx
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by Amkaos
    Hi:

    i have site contact form that validates required fields w/ .js And php.
    if browser has javascript turned on, the req'd info error message will show next to the field boxes ..

    if javascript is turned off, then
    user will see the same thing but coming from php instead...

    the submit goes to database and personal email.
    email received shows complete field boxes info.. as expected..

    the database will show incomplete submissions that the .js was sposed to stop..
    example:: like name is filled but missing email and such..

    how can this be so?...
    must be something simple//

    i didnt try to disable the .js validation to see what happens..
    i would rather fix it and keep it

    here is code if someone can look at it..
    http://jsbin.com/ixupuk/1/edit

    thanx
    this is the behaviour :

    form submission possibilities:
    fill in name only == js blocks submission

    fill in valid email only == js blocks submission

    fill in bad email format == js doesnt block submission

    fill in name + email wrong format == js blocks submission

    fill in name + email correct format == js blocks submission
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,296
    Rep Power
    7170
    Everything you validate in JavaScript has to also be validated in PHP. You can't rely on JavaScript alone to block a submission, because the client can selectively ignore any JavaScript validation they want.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,910
    Rep Power
    1045
    @ E-Oreo:

    Originally Posted by Amkaos
    if javascript is turned off, then
    user will see the same thing but coming from php instead...
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    Since two people have responded without addressing the question (although it's always good to remind people to always do server-side validation), I'll attempt to answer it.

    It looks to me like the problem is because of the isValid flag being set to true in the else-blocks. Simply remove those statements from your code.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by Kravvitz
    Since two people have responded without addressing the question (although it's always good to remind people to always do server-side validation), I'll attempt to answer it.

    It looks to me like the problem is because of the isValid flag being set to true in the else-blocks. Simply remove those statements from your code.
    i will try that... also, i have php validation.. i would be happy to post it if someone cares to see it..thank you very much

    edit: i commented out those two statements; didnt help.
    i also added php code to the orig link:

    http://jsbin.com/ixupuk/3/edit
    to reconsider, i would rather have the php working fully

    i dont understand why the validation works fine to block email but not to the database.
    thanx
  12. #7
  13. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,296
    Rep Power
    7170
    The part that confuses me is this:
    the database will show incomplete submissions that the .js was sposed to stop..
    To me, this statement means that the server-side validation is not working. The database should not contain incomplete submissions if server-side validation is implemented, and JavaScript should not be responsible by itself for stopping incomplete submissions.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by E-Oreo
    The part that confuses me is this:


    To me, this statement means that the server-side validation is not working. The database should not contain incomplete submissions if server-side validation is implemented, and JavaScript should not be responsible by itself for stopping incomplete submissions.
    HI:
    thanx for the reply. i discovered minutes ago that the validations, both js and php, seem to be working fine.. real problem is this: when the form loads into browser, it auto-submits empty fields to the database. if i fill in some fields then refresh page, form sends filled in filled and remaining empty fields to database.. im sorry i misdiagnosed the real problem.. i am looking for solution to re-defined problem...im sorry i wasted your time about this thank you.

IMN logo majestic logo threadwatch logo seochat tools logo