SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using A Form For Several Purposes?

    I'm programming a Flashcard interface for my website. First, users are displayed a list of words with checkboxes next to each. They can check which words they wish to view in the Flashcard interface.

    It currently works with only this functionality, but I want to expand on it so that users have different options. For example, they can check the words and then view them in the Flashcard interface. Or, they could check words and save them to a custom list.

    The only way I can think of doing this currently is to have a simple drop down / combo box for "view cards" or "save to list" and a single submit button. On the processing page, I then check the value of the drop down and use standard conditionals.

    This would work, but there is also a fair amount of programming involved. I would like to separate the two actions into separate files to make organization easier. Furthermore, if I add additional actions, such as 'printable version' then the script would become even longer. It would be better to be able to break each action into separate scripts.

    Is it possible to have multiple submit buttons and submit the data to different locations depending on the submit button clicked? This seems like it would be the most user friendly method. Simply have the words with checkboxes and then one button for each action, each leading to a location for that given action.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,036
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    You could have multiple submits, but I think it would be better to have "action option" radios and process the form inputs based on that value. eg.
    Code:
    if($action == 'view') {
    // do view stuff
    }
    else if($action == 'save') {
    // do save stuff
    }
    else if($action == 'print') {
    // do print stuff
    }

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you can have multiple submit buttons. You need a name attribute on each button, so that its value is passed to the server on submission.

    I think Internet Explorer has some bugs related to this, but I don't remember the details. I've never had any problems with it, though.
    Birnam wood is come to Dunsinane

  4. #4
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For example

    <input type="submit" name="location" value="europe" src="europe.png" alt="Europe">, a click should produce something along the lines of location=europe&location.x=27&location.y=123. Unfortunately Internet Explorer will only send the X and Y co-ordinates.

    It gets worse though, Internet Explorer 6 has a further bug where it will treat all <button> elements as successful controls, and submit their data to the server, even if they were not clicked. This effectively makes using multiple button elements impossible.


    Text from this article

  5. #5
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    You could have multiple submits, but I think it would be better to have "action option" radios and process the form inputs based on that value. eg.
    Code:
    if($action == 'view') {
    // do view stuff
    }
    else if($action == 'save') {
    // do save stuff
    }
    else if($action == 'print') {
    // do print stuff
    }
    That way of branching is typical, you could also use a switch instead, e.g.,

    switch ( $action ) {
    case 'view':
    // do stuff
    break;

    case 'save':
    // do stuff
    break;

    case 'print':
    // do stuff
    break;

    default: // do stuff
    }

    As in the prior post, you should avoid multiple button elements as they send their innerHTML/innerText as the value and not just the real value. You could have multiple anchor elements and use Javascript to enhance them and add event handlers to have different behavior.
    Cross browser css bugs

    Dan Schulz you will be missed

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BBoardX, don't you mean <input type="image"...> there? The src and alt attributes should be ignored for <input type="submit"> and you should get a regular submit button with the text 'europe' in it.
    Birnam wood is come to Dunsinane

  7. #7
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I simply copied and pasted from the article. Check it out.

  8. #8
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BBoardX View Post
    I simply copied and pasted from the article. Check it out.
    Did you read it, or test the code?

    Code:
    <!doctype html>
    <form> <input type="image" src="http://www.sitepoint.com/forums/image.php?u=59436&dateline=1177067539" /> </form>
    This redirects to same page with x, y coordinates.

    Code:
    <!doctype html>
    <form> <input type="submit" src="http://www.sitepoint.com/forums/image.php?u=59436&dateline=1177067539" /> </form>
    This doesn't render the image at all, and shouldn't because its of type=submit as AutisticCuckoo pointed out.

    Edit: Oh, I've seen the author of the article on IRC a few times, I'll have to inform him to update his article.
    Cross browser css bugs

    Dan Schulz you will be missed

  9. #9
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was just copy and pasting. I scanned the article for relevance, saw it had some. Then pasted on here but gave reference to the author...I think the article is over a year old though.


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
  •