471,320 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Problem: Javascript & PHP form with HTML_QuickForm

Hi,

I have a problem with a form using the PHP PEAR HTML_QuickForm package &
javascript:

I want to record the content of my form into a mySQL database then
execute a javascript function.

My problem is that javascript is executed before the mySQL insertion.
I actually need the mySQL insertion first, since my javascript function
is supposed to close the window...

Thanks for your help.
Ronan
A short explanation of my code:
#--- 1 ---
#javascript function
#---------
#--- 2 ---
# javascript is called by the action field of my form

# PHP code
$form = new HTML_QuickForm('createNewsCategoryForm',
'post','javascript:addValue();');

# HTML result
<form action="javascript:addValue();" method="post" ... >
#------
#--- 3 ---
# form validation du formulaire and insertion into the mySQL database:
if ($form->validate()) {
$form->process('dataProcessing', false);
}
else {
$form->display();
}

function dataProcessing($values){
#mySQL Insert request
}
#---------
Jul 23 '05 #1
1 1750


Ronan wrote:
I have a problem with a form using the PHP PEAR HTML_QuickForm package &
javascript:

I want to record the content of my form into a mySQL database then
execute a javascript function.

My problem is that javascript is executed before the mySQL insertion.
I actually need the mySQL insertion first, since my javascript function
is supposed to close the window...


Use a HTML form with a normal action attribute pointing to your PHP page
doing the database insertion and then let the PHP page return a HTML
page with script closing the window e.g.

<html>
<head>
<title>confirmation</title>
<script type="text/javascript">
function closeAfterDelay () {
setTimeout('window.close();', 2000);
}
window.onload = function (evt) {
closeAfterDelay();
};
</script>
</head>
<body>
<p>Your data has been stored.</p>
</body>
</html>

Of course there are restrictions on the windows script can close, you
might only be able to close a window that script opened before or the
browser might ask the user for confirmation to close the window.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ronan | last post: by
3 posts views Thread by Bob Bedford | last post: by
6 posts views Thread by bonehead | last post: by
5 posts views Thread by comshiva | last post: by
reply views Thread by WhatsPHP | last post: by
2 posts views Thread by swethak | last post: by
reply views Thread by rosydwin | last post: by

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.