The right way of doing this

Discussion in 'HTML' started by mccreeryd@yahoo.com, Sep 23, 2008.

  1. Guest

    I want to use java script to validate the entry into a form and a php
    script to do the posting. Each works fine on their own but how do I
    combine them so that when the java returns true the php script is
    called but otherwise its not.

    <form method="post" name="CForm" onsubmit="return VCForm();"
    action="feedback.php">

    Any direction would be appreciated

    ADJMC
     
    , Sep 23, 2008
    #1
    1. Advertising

  2. writes:

    > I want to use java script to validate the entry into a form and a php
    > script to do the posting.


    Don't forget to re-validate the data in your PHP script. There's
    nothing wrong with doing so with JavaScript, avoiding the round-trip
    as a convenience to the user. But, not everyone has JS enabled, and a
    malicious user might save your form locally and edit it, or even use
    something other than a browser to submit it.

    Bottom line is, there's no way to guarantee that the JS will run, so
    it's not safe to write your PHP assuming that it has.

    > Each works fine on their own but how do I
    > combine them so that when the java


    JavaScript. Java is a different language entirely.

    > returns true the php script is
    > called but otherwise its not.


    You're on the right track - when an onsubmit handler returns true, the
    form is submitted. When it returns false, the form submission is
    cancelled. If the form isn't getting submitted, you need to debug your
    onsubmit handler to see why it's returning false.

    sherm--

    --
    My blog: http://shermspace.blogspot.com
    Cocoa programming in Perl: http://camelbones.sourceforge.net
     
    Sherm Pendley, Sep 23, 2008
    #2
    1. Advertising

  3. Neredbojias Guest

    On 23 Sep 2008, wrote:

    > I want to use java script to validate the entry into a form and a php
    > script to do the posting. Each works fine on their own but how do I
    > combine them so that when the java returns true the php script is
    > called but otherwise its not.
    >
    > <form method="post" name="CForm" onsubmit="return VCForm();"
    > action="feedback.php">


    There're several ways of doing that, but as Jim Moe queried, what happens
    without j/s? Well in general, no j/s means no submission.

    Anyway, one way is to id the form, leave the action blank (or better yet a
    url to some kind of an info page), and "fill in" the action with the
    results of the j/s verification script. Other ways include using
    "onclick" with "return false", etc., but again: no j/s, no washee.

    --
    Neredbojias
    http://www.neredbojias.org/
    Great Sights and Sounds
     
    Neredbojias, Sep 23, 2008
    #3
  4. Guest

    Thanks guys for the response,

    I was hoping that my form header had somthing obvious wrong with it
    but obviously not. I'll try to explain better.

    The php script is very safe it check that the fields entered satisfy
    certain criteria. If the java script dosnt run the PHP will basically
    dump the form contents and not popultate the database. I'm a bit of a
    programming dinosaur so I'm happy with the php.

    So if java script isnt enable then the user will still be able to
    submit but if they dont put meaning full data into the form it will be
    binned.

    The java script does some pre checking to assist the user with entry
    so it more of a usabaility function.

    My problem is that when the java script returns a failure (return
    false;) it still goes ahead and runs the php, whithout allowing the
    user to correct the mistake. If I remove the "action="feedback.php"
    then the form stays present and seems to do what I want it to,
    (obviously, except actually doing the posting to the php part).

    So basically if the VCform dosnt return true then dont do the PHP
    part.

    I hope this give a better idea

    Dave Mc

    ADJMC

    On Sep 23, 6:59 pm, Jim Moe <> wrote:
    > On 09/23/08 10:38 am, wrote:> I want to use java script to validate the entry into a form and a php
    > > script to do the posting. Each works fine on their own but how do I
    > > combine them so that when the java returns true the php script is
    > > called but otherwise its not.

    >
    > > <form method="post" name="CForm"  onsubmit="return VCForm();"
    > > action="feedback.php">

    >
    >   What happens when JS is disabled? Or a naughty person submits a forged page?
    >   Where's the URL?
    >
    > --
    > jmm (hyphen) list (at) sohnen-moe (dot) com
    > (Remove .AXSPAMGN for email)
     
    , Sep 23, 2008
    #4
  5. cwdjrxyz Guest

    On Sep 23, 12:38 pm, wrote:
    > I want to use java script to validate the entry into a form and a php
    > script to do the posting. Each works fine on their own but how do I
    > combine them so that when the java returns true the php script is
    > called but otherwise its not.
    >
    > <form method="post" name="CForm"  onsubmit="return VCForm();"
    > action="feedback.php">
    >


    There likely are many ways you could do this. I am inclined to use all
    php when possible. See my demo page at http://www.cwdjr.net/calendar2/numbercheck.php
    and the text file at http://www.cwdjr.net/calendar2/numbercheck.txt .
    I want the user to select a year between 1 and 60000 inclusive and
    nothing else. When the date is submitted, several tests are made using
    php to make certain that only a number in the range selected is put in
    the form. If anything else is used, the browser gets a notice and can
    try again. There are all sorts of other test that one can uses for
    text etc, when needed.
     
    cwdjrxyz, Sep 24, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AC
    Replies:
    1
    Views:
    324
    Chris Jackson
    Feb 20, 2004
  2. LOU

    Am I doing testing right?

    LOU, Feb 3, 2005, in forum: HTML
    Replies:
    2
    Views:
    388
    Leif K-Brooks
    Feb 3, 2005
  3. Frank Millman

    SSL/TLS - am I doing it right?

    Frank Millman, Mar 13, 2006, in forum: Python
    Replies:
    20
    Views:
    771
    Sybren Stuvel
    Mar 15, 2006
  4. Replies:
    3
    Views:
    376
    Joe Kesselman
    Aug 4, 2007
  5. Nightcrawler

    Am I doing this the right way? ASP.NET/AJAX

    Nightcrawler, Aug 10, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    389
    Nightcrawler
    Aug 10, 2007
Loading...

Share This Page