473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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"><form onaction = "step1.php"
method="post">...</form></div>
<div id = "page2"><form 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?)

Jun 2 '08 #1
2 2203
On Thu, 08 May 2008 00:43:59 +0200, Ronald Raygun <in*****@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.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
Jun 2 '08 #2
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"><form onaction = "step1.php"
method="post">...</form></div>
<div id = "page2"><form 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.

http://www.phpclasses.org/formsgeneration

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:

http://www.meta-language.net/forms-e...test_ajax_form

Here you may watch a tutorial video:

http://www.phpclasses.org/browse/vid...ugin-ajax.html

--

Regards,
Manuel Lemos

PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Jun 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: dmcconkey | last post by:
Hi folks, I have a client with four websites. Each site has a contact form that is identical. They all have "required" fields validated through a JavaScript onSubmit() function. Upon validation,...
1
by: Display Name | last post by:
the customer I'm developing a site for uses a canned form-parsing page that allows her to have an email subscription opt-in page add emails to a list she can manage using a link that you point your...
1
by: David Bradbury | last post by:
Hi On my form, as soon as the user clicks my submit button a message pops up saying "Form processing" as the form submits. This is fine as long as the user only clicks the submit button once....
7
by: Randell D. | last post by:
Folks, I am working on a contact db using PHP and MySQL. My results so far outputs a slimed down version of records to the browser. I would like to implement a method whereby the user can...
4
by: Howard Jess | last post by:
In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865), my form disappears from the HTML markup (below). To summarize: 1) In a <script> block in the <head> I create a form...
2
by: Esa | last post by:
Hi, I'm having problems with one strange web system where submitting an application and making queries about its handling status require a series of form submits and response parsing - all in...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
4
by: Brad Everman | last post by:
I have an HTML form that passes arrays of values to PHP. Basically, each row of the form tracks three separate values for processing. I have a JS program that will dynamically add (or delete) rows...
4
by: pbd22 | last post by:
hi. could somebody tell me, when uploading a file, i know the form where the upload component is must have enctype=multipart/form-data but, is the same true for the form with the server code to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.