PHP form processing (with Javascript)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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"><form onaction = "step1.php"
<div id = "page2"><form onaction = "step2.php"

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?)

Re: PHP form processing (with Javascript)

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.javascript (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

Re: PHP form processing (with Javascript)


on 05/07/2008 07:43 PM Ronald Raygun said the following:
Quoted text here. Click to load it

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:


Manuel Lemos

PHP professionals looking for PHP jobs /

PHP Classes - Free ready to use OOP components written in PHP /

Site Timeline