SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submit form.. is there any onclick="userinfo.form.submit()" possible in my condition?

    hi, i would like to find out is it possible to make a button to submit a form in a preview state where the preview state do not contain any form ???

    is there any onclick="userinfo.form.submit()" possible to make this happen ???

    i have previded my code example here...

    wish to get some help from you guys...

    thank you!

    Code:
    <?php 
    if ($_SERVER['REQUEST_METHOD'] != 'POST')
    {
    ?>
    
    <form name="userinfo" method="post" action="<?php echo $_SERVER['PHP_SELF"]; ?> ">
    .
    .
    .
    <input type="submit" name="preview" value="Preview">
    <input type="submit" name="send" value="Send">
    </form>
    
    <?php 
    if (isset($_POST['preview']))
    {
    ?>
    
    .
    .
    .
    <input type="button" name="back" value="Back" onclick="javascript:history.back()">
    <input type="button" name="submit" value="Submit" onClick="javascript:">
    
    <?php			
    }
    if (isset($_POST['send']))
    {
    //code to save info into database is here
    }
    ?>
    newbie...really need your guidance......

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I would do is have 2 forms, one of which has hidden fields which are populated by the first. So this means you would have to split your form logic (in PHP anyway) into three parts.

    Case A - first time viewer sees the page, no $_POST['submit'] variables set.
    Case B - viewer submits form and is sent to preview of the form instead which includes a hidden form with all of the required attributes from the first form. Here an extra $_POST['preview'] or whatever attribute is set.
    Case C - Check for the existance of the $_POST['preview'] variable and do whatever database stuff is required.

    Now your form will work properly for people who, for whatever misguided reason, have Javascript disabled. If you want to stop the extra call to the server, what you would have to do is use the something like:

    Code:
    <form name="userinfo" method="post" action="<?php echo $_SERVER['PHP_SELF"]; ?> onsubmit="generatePreview(this)"">
    in your form, and then in the head of your document create a script element (or include it in an external Javascript file) and use something like:

    Code:
    function generatePreview(el) {
            var preview = document.getElementById("preview");
            el.style.display = "none";
            // etc....
            return false;
    }
    Hopefully this gives you a place to start.

    Dave


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •