www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Two Submit Buttons for One Form

  1. #1
    Join Date
    Jul 2010
    Posts
    35

    resolved [RESOLVED] Two Submit Buttons for One Form

    Hi guys,

    I have an HTML form which needs two submit buttons. (Pushing one will submit the form data to "insert_info.php" and the other to "publish.php.")

    I have attempted to use javascript to switch the form action attribute to "insert_info.php" when one submit button is pushed, and "publish.php" when the other is pushed, but this fix appears to require that the form have a name attribute. However, the name attribute is not valid in XHTML Strict.

    Does anyone have any suggestions on how to get two submit buttons for one form while maintaining valid XHTML Strict? One solution that looked quite promising and that I think is used in Wordpress involves the "hidden" attribute. Does this ring a bell?

    Here's the form code:

    HTML Code:
    <form method="post" name="form">
    <p>
    Title:  <input type="text" name="title"/>
    </p>
    <p>
    Meta Tags:  <textarea rows="10" cols="30" name="meta"></textarea>
    </p>
    <p>
    Header 1:  <input type="text" name="header_1"/>
    </p>
    <p>
    Paragraph 1:  <textarea rows="10" cols="30" name="paragraph_1"></textarea>
    </p>
    <p>
    Header 2:  <input type="text" name="header_2"/>
    </p>
    <p>
    Paragraph 2:  <textarea rows="10" cols="30" name="paragraph_2"></textarea>
    </p>
    <p>
    Author:  <input type="text" name="author"/>
    </p>
    <p>
    <input type="submit" name="save" value="Save" onclick="javascript: form.action='http://www.thesiteguru.com/php/insert_info.php';"/>
    <input type="submit" name="publish" value="Publish" onclick="javascript: form.action='http://www.thesiteguru.com/php/publish.php';"/>
    </p>
    </form>

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    1) You must provide a value for the action link that specifies what's to be done when there is no JavaScript.

    2) The pseudo-scheme "JavaScript" should not be used with the handlers.

    3) Use:
    Code:
    <input type="submit" name="save" value="Save" onclick="this.form.action='http://www.thesiteguru.com/php/insert_info.php'"/>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Jul 2010
    Posts
    35

    So the Name Attribute Is Superfluous...

    Ah, I see. So the name attribute for the form tag is not needed even when using this javascript. I deleted that, Charles, and made the other changes you suggested, and my form validates! Thanks a lot.

    Mr. Baggins

    ------
    I don't know half of you half as well as I should like; and I like less than half of you half as well as you deserve. - Bilbo in The Fellowship of the Ring

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles