Problem: Javascript & PHP form with HTML_QuickForm

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

    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( 'createNewsCate goryForm',
    'post','javascr ipt:addValue(); ');

    # HTML result
    <form action="javascr ipt:addValue(); " method="post" ... >
    #------


    #--- 3 ---
    # form validation du formulaire and insertion into the mySQL database:
    if ($form->validate()) {
    $form->process('dataP rocessing', false);
    }
    else {
    $form->display();
    }

    function dataProcessing( $values){
    #mySQL Insert request
    }
    #---------
  • Martin Honnen

    #2
    Re: Problem: Javascript &amp; PHP form with HTML_QuickForm



    Ronan wrote:
    [color=blue]
    > 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...[/color]

    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>confirma tion</title>
    <script type="text/javascript">
    function closeAfterDelay () {
    setTimeout('win dow.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


    Comment

    Working...