PHP form processing (with Javascript)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald Raygun

    PHP form processing (with Javascript)

    I have a form that I am using as a wizard. The wizard comprises of
    several forms contained in divs, which are hidden/made visible,
    depending on the wizard step. Each form has an action parameter set to a
    different php script, which is responsible for returning a true/false (+
    mesage back to the form.

    So I have something like this:

    <div id = "page1"><fo rm onaction = "step1.php"
    method="post">. ..</form></div>
    <div id = "page2"><fo rm onaction = "step2.php"
    method="post">. ..</form></div>


    I know how to set the onclick event of the button in a form to a
    javascript function - so I can validate the form input before sending
    the data to the server. However, this is what I want to do (in
    pesudocode below):

    if (form_is_valid( formId))
    {
    //Send form input data to php server script
    //get server response from php script and display in alert box
    }

    I don't know if its possible to cause a php script to be run by
    "calling" it from JS (ala RPC), but basically, what I want to do is:

    a). Validata user input clientside, using JS (easy bit)
    b). Cause the form to invoke its action method (How?)
    c). Receive server response in JS and display in alert box (HOW?)

  • Rik Wasmus

    #2
    Re: PHP form processing (with Javascript)

    On Thu, 08 May 2008 00:43:59 +0200, Ronald Raygun <invalid@domain .com>
    wrote:
    I don't know if its possible to cause a php script to be run by
    "calling" it from JS (ala RPC), but basically, what I want to do is:
    >
    a). Validata user input clientside, using JS (easy bit)
    b). Cause the form to invoke its action method (How?)
    By gathering the values in the current form and submitting it in a
    XMLHTTPRequest (with possibly slightly altered GET url to indicate JS
    validation), and awating it in the repomse.
    c). Receive server response in JS and display in alert box (HOW?)
    By interpreting the result from the request amd putting it in an alert box.

    For more AJAX questions, I'd advise asking questions in
    comp.lang.javas cript (or read AJAX tutorials) how it works, and just
    output either text, JSON or XML format with PHP for the calling JS script,
    whichever strikes your fancy.
    --
    Rik Wasmus

    Comment

    • Manuel Lemos

      #3
      Re: PHP form processing (with Javascript)

      Hello,

      on 05/07/2008 07:43 PM Ronald Raygun said the following:
      I have a form that I am using as a wizard. The wizard comprises of
      several forms contained in divs, which are hidden/made visible,
      depending on the wizard step. Each form has an action parameter set to a
      different php script, which is responsible for returning a true/false (+
      mesage back to the form.
      >
      So I have something like this:
      >
      <div id = "page1"><fo rm onaction = "step1.php"
      method="post">. ..</form></div>
      <div id = "page2"><fo rm onaction = "step2.php"
      method="post">. ..</form></div>
      >
      >
      I know how to set the onclick event of the button in a form to a
      javascript function - so I can validate the form input before sending
      the data to the server. However, this is what I want to do (in
      pesudocode below):
      >
      if (form_is_valid( formId))
      {
      //Send form input data to php server script
      //get server response from php script and display in alert box
      }
      >
      I don't know if its possible to cause a php script to be run by
      "calling" it from JS (ala RPC), but basically, what I want to do is:
      >
      a). Validata user input clientside, using JS (easy bit)
      b). Cause the form to invoke its action method (How?)
      c). Receive server response in JS and display in alert box (HOW?)
      Yes, you can do that with some AJAX techniques.

      You may want to try this forms generation and validation class that
      comes with a plug-in that supports AJAX form submission.



      The plug-in lets you submit the form without page reloading and have the
      PHP on the server respond with several types of actions like generating
      display alert message, updating parts of the page, or execute any
      Javascript you need. Here a live example:



      Here you may watch a tutorial video:



      --

      Regards,
      Manuel Lemos

      PHP professionals looking for PHP jobs


      PHP Classes - Free ready to use OOP components written in PHP
      Free PHP Classes and Objects 2026 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials

      Comment

      • Ronald Raygun

        #4
        Re: PHP form processing (with Javascript)



        Rik Wasmus wrote:
        On Thu, 08 May 2008 00:43:59 +0200, Ronald Raygun <invalid@domain .com>
        wrote:
        >
        >I don't know if its possible to cause a php script to be run by
        >"calling" it from JS (ala RPC), but basically, what I want to do is:
        >>
        >a). Validata user input clientside, using JS (easy bit)
        >b). Cause the form to invoke its action method (How?)
        >
        >
        By gathering the values in the current form and submitting it in a
        XMLHTTPRequest (with possibly slightly altered GET url to indicate JS
        validation), and awating it in the repomse.
        Any chance of a code snippet here or a link that provides an example of
        how to do this?
        >
        >c). Receive server response in JS and display in alert box (HOW?)
        >
        >
        By interpreting the result from the request amd putting it in an alert box.
        Once again, is there any chance of a code snippet here or a link that
        provides an example of how to do this?

        Comment

        • Gregor Kofler

          #5
          Re: PHP form processing (with Javascript)

          Ronald Raygun meinte:
          >
          >
          Rik Wasmus wrote:
          >
          >On Thu, 08 May 2008 00:43:59 +0200, Ronald Raygun
          ><invalid@domai n.com wrote:
          >>
          >>I don't know if its possible to cause a php script to be run by
          >>"calling" it from JS (ala RPC), but basically, what I want to do is:
          >>>
          >>a). Validata user input clientside, using JS (easy bit)
          >>b). Cause the form to invoke its action method (How?)
          >>
          >>
          >By gathering the values in the current form and submitting it in a
          >XMLHTTPReque st (with possibly slightly altered GET url to indicate JS
          >validation), and awating it in the repomse.
          >
          Any chance of a code snippet here or a link that provides an example of
          how to do this?
          >
          >>
          >>c). Receive server response in JS and display in alert box (HOW?)

          >By interpreting the result from the request amd putting it in an alert
          >box.
          >
          Once again, is there any chance of a code snippet here or a link that
          provides an example of how to do this?


          the JS is "compacted" , if you're interested in the uncompressed source:
          the email is valid. The overall code (widget + library) is around 25kB.

          A "snippet" will hardly explain the whole thing. The basic steps: new
          submit-listener for form; listener collects form values, triggers XHR
          and sends these values, XHR response listener grabs result, then either
          issues error message of submits form.

          Gregor



          --
          http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
          http://web.gregorkofler.com ::: meine JS-Spielwiese
          http://www.image2d.com ::: Bildagentur für den alpinen Raum

          Comment

          • Gregor Kofler

            #6
            Re: PHP form processing (with Javascript)

            Gregor Kofler meinte:
            Oops. http://web.gregorkofler.com/index.php?page=form

            Gregor



            --
            http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
            http://web.gregorkofler.com ::: meine JS-Spielwiese
            http://www.image2d.com ::: Bildagentur für den alpinen Raum

            Comment

            Working...