Results 1 to 5 of 5

Thread: [Resolved] Two Submit Buttons

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] Two Submit Buttons

    I have a form where the user inputs some text. I have a Preview button and a Submit button.

    I thought I could have them both as submits, and then check in PHP to see if the preview one is there...but they both are.

    So how can I have a preview type option (like vBulletin)?
    Last edited by The Hobo; Oct 29th, 2003 at 02:22 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Eh, I guess I just had to give them the same name:

    Code:
    <?php
        if (isset($_POST['action'])) {
            switch ($_POST['action']) {
                case 'submitsave':
                    submitsave(); break;
                default:
                    create_form();
            }
        } else {
            create_form();
        }
    
        function create_form($subject = '', $body = '') {
            echo '<form action="work.php" method="post">
                <input type="hidden" name="action" value="submitsave" />
                <b>Subject</b>: <input type="text" name="subject" value="' . $subject . '" /><br />
                <b>Body</b>: <textarea name="body">' . $body . '</textarea><br /><br />
                <input type="submit" name="submit" value=" Preview " />
                <input type="submit" name="submit" value=" Submit " />
            </form>';
        }
    
        function submitsave() {
            if ($_POST['submit'] == ' Preview ') {
                preview();
                create_form($_POST['subject'], $_POST['body']);
            } else {
                echo '<b>Save News...</b>';
            }
        }
    
        function preview() {
            echo '<b>Subject</b>: ' . $_POST['subject'] . '<br />';
            echo '<b>Body</b>: ' . $_POST['body'] . '<br /><br />';
        }
    ?>
    Is this valid HTML/JavaScript?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    that is how vBulliten does it.

    valid html, that is a tough one. as long as you check for which one is pushed then I don't see a problem. I suppose it is valid as you are submitting the same form.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Valid XHTML 1.0 Transitional, but I can't see any JavaScript
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    but I can't see any JavaScript
    Good point. I tried various ways to accomplish what I wanted, and some involved Javascript. I just forgot that the solution I posted didn't use Javascript.

    Thanks, CB.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width