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

Re: [NH] HTML radio button forms with submission capability

Expand Messages
  • Rudolf Horbas
    Hi Mike, ... Here s an extended version of the first. Caution: No whitespace or extra lines before the opening
    Message 1 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.