Loading ...
Sorry, an error occurred while loading the content.

HTML radio button forms with submission capability

Expand Messages
  • Mike Breiding
    Howdy, I am looking for examples of form list using radio buttons. Heree is what I wan to do. Create a list with button for each item. Any number of items can
    Message 1 of 4 , Apr 26, 2008
    • 0 Attachment
      Howdy,
      I am looking for examples of form list using radio buttons.

      Heree is what I wan to do.

      Create a list with button for each item.
      Any number of items can be selected.

      When selection is finished and submission made, the output is saved as
      a text file.

      I googledd and checked numersous site but did ot come accross such a page.

      Thanks,
      -Mike
    • Rudolf Horbas
      Hi Mike, ... Any number meaning multiple selections or just one item? For the latter, radio buttons would be right; multiple choices require checkboxes. ...
      Message 2 of 4 , Apr 26, 2008
      • 0 Attachment
        Hi Mike,

        > I am looking for examples of form list using radio buttons.
        >
        > Heree is what I wan to do.
        >
        > Create a list with button for each item.
        > Any number of items can be selected.

        "Any number" meaning multiple selections or just one item?
        For the latter, radio buttons would be right; multiple choices require
        checkboxes.

        Here's a simple example with both, using php:

        ------------------------------------------------------
        <form method="post" action="<?=$_SERVER['PHP_SELF']?>">

        Radio buttons:
        <ul style="list-style-type: none;">
        <li>
        <input type="radio" name="foo" value="Foo" />
        Foo
        </li>
        <li>
        <input type="radio" name="bar" value="Bar" />
        Bar
        </li>
        </ul>

        Checkboxes:
        <ul style="list-style-type: none;">
        <li>
        <input type="checkbox" name="checkbox[foo]" value="Foo" />
        Foo
        </li>
        <li>
        <input type="checkbox" name="checkbox[bar]" value="Bar" />
        Bar
        </li>
        </ul>

        <input type="submit" value="Send" />
        </form>
        These are the form values that are being submitted:
        <pre>
        <?php
        print_r( $_POST );
        ?>
        </pre>

        ------------------------------------------------------

        > When selection is finished and submission made, the output is saved as
        > a text file.

        That's where the trickier part starts: processing the values.
        Where'd you want to save the text file? On the server? Or on the
        client's computer?

        Rudi
      • Mike Breiding
        ... Hi Rudi, Multiple selections. To be specific: This would be a list of birds. The birds observed would be checked off in the form and then a list of the
        Message 3 of 4 , Apr 26, 2008
        • 0 Attachment
          Rudolf Horbas wrote:
          > Hi Mike,
          >> I am looking for examples of form list using radio buttons.
          >> Heree is what I wan to do.
          >> Create a list with button for each item.
          >> Any number of items can be selected.
          >>
          > "Any number" meaning multiple selections or just one item?
          > For the latter, radio buttons would be right; multiple choices require
          > checkboxes.
          >

          Hi Rudi,
          Multiple selections.
          To be specific: This would be a list of birds. The birds observed would
          be checked off in the form and then a list of the birds checked off
          would be generated on submission.
          To make it more useful I guess it should have entry boxes for the
          location, time , date and observer as well.

          > Here's a simple example with both, using php:
          > ------------------------------------------------------
          > <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
          >
          > Checkboxes:
          > <ul style="list-style-type: none;">
          > <li>
          > <input type="checkbox" name="checkbox[foo]" value="Foo" />
          > Foo
          > </li>
          > <li>
          > <input type="checkbox" name="checkbox[bar]" value="Bar" />
          > Bar
          > </li>
          > </ul>
          >
          > <input type="submit" value="Send" />
          > </form>
          > These are the form values that are being submitted:
          > <pre>
          > <?php
          > print_r( $_POST );
          > ?>
          > </pre>
          >
          > ------------------------------------------------------
          > When selection is finished and submission made, the output is saved as
          > a text file.
          > That's where the trickier part starts: processing the values.
          > Where'd you want to save the text file? On the server? Or on the
          > client's computer? Rudi


          I like the check boxes!
          The file would need to be saved to the client.
          Thanks,
          -Mike
        • Rudolf Horbas
          Hi Mike, ... Here s an extended version of the first. Caution: No whitespace or extra lines before the opening
          Message 4 of 4 , Apr 26, 2008
          • 0 Attachment
            Hi Mike,

            > Multiple selections.
            > To be specific: This would be a list of birds. The birds observed would
            > be checked off in the form and then a list of the birds checked off
            > would be generated on submission.
            > To make it more useful I guess it should have entry boxes for the
            > location, time , date and observer as well.
            > (...)
            > The file would need to be saved to the client.

            Here's an extended version of the first. Caution: No whitespace or extra
            lines before the opening <?php, or else the script fails with an error
            that headers are already sent!

            <?php
            # form has been submitted:
            if( count( @$_POST['birds'] ) > 0 )
            {
            $birdlist = '';
            # build list from form fields:
            foreach( $_POST['birds'] as $bird )
            {
            $birdlist .= "$bird\r\n";
            }
            # send as file to client
            header( 'Content-type: application/text' );
            # make filename with date
            header( 'Content-Disposition: attachment; filename=birdlist_' .
            date('Ymdhis') . '.txt' );
            echo $birdlist;
            exit; # finish processing
            }
            ?>
            <html>
            <head>
            <title>Birdlist</title>
            </head>
            <body>
            <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
            Birds:
            <ul style="list-style-type: none;">
            <li>
            <input type="checkbox" name="birds[]" value="Sparrow" />
            Sparrow
            </li>
            <li>
            <input type="checkbox" name="birds[]" value="Wren" />
            Wren
            </li>
            </ul>
            <input type="submit" value="Send" />
            </form>
            </body>
            </html>

            To submit more information, you'd have to extend the form.
            I'd send a more distinguished example for the processing, but I'm
            running out of time today, sorry.

            Rudi
          Your message has been successfully submitted and would be delivered to recipients shortly.