form validation Radio

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xaver Biton

    #1

    form validation Radio

    Hi,

    how can I validate Radio Button group in form.

    tkd.

    XAver


  • Jon Kraft

    #2
    Re: form validation Radio

    "Xaver Biton" <javier@t-online.de> wrote:
    [color=blue]
    > how can I validate Radio Button group in form.[/color]

    How do birds fly?

    What exactly is your problem?

    JOn

    Comment

    • Xaver Biton

      #3
      Re: form validation Radio

      [color=blue][color=green]
      > > how can I validate Radio Button group in form.[/color]
      >
      > How do birds fly?
      >[/color]
      wha the checkbox or a radio Button doesn't work?

      Code:
      <?php
      $name = $_POST['name'];
      $media_type = $_POST['media_type'];
      $filename = $_POST['filename'];
      $caption = $_POST['caption'];
      
      $tried = ($_POST['tried'] == 'yes');
      
      if ($tried) {
      $validated = (!empty($name) && !empty($media_type) && !empty($filename));
      
      if (!$validated) {
      ?>
      <p>
      The name, media type, and filename are required fields. Please fill
      them out to continue.
      </p>
      <?php
      }
      }
      
      if ($tried && $validated) {
      echo '<p>The item has been created.</p>';
      }
      
      // was this type of media selected? print "selected" if so
      function media_selected ($type) {
      global $media_type;
      if ($media_type == $type) { echo "selected"; }
      }
      ?>
      <head>
      <title>Untitled Document</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>
      
      <body>
      
      
      <form action="<?= $PHP_SELF ?>" method="POST">
      Name: <input type=text name="name" value="<?= $name ?>" /><br />
      Status: <input type="checkbox" name="status" value="active"
      <?php if($status == 'active') { echo 'checked'; } ?> /> Active  <br />
      Media: <select name="media_type">
      <option value="">Choose one</option>
      <option value="picture" <?php media_selected('picture') ?>
      />Picture</option>
      <option value="audio" <?php media_selected('audio') ?> />Audio</option>
      <option value="movie" <?php media_selected('movie') ?> />Movie</option>
      </select><br />
      
      File: <input type="text" name="filename" value="<?= $filename ?>" /><br />
      Caption: <textarea name="caption"><?= $caption ?></textarea><br />
      
      <input type="hidden" name="tried" value="yes" />
      <input type="submit"
      value="<?php echo $tried ? 'Continue' : 'Create'; ?>" />
      </form>
      
      </body>
      </html>

      Comment

      • Manuel Lemos

        #4
        Re: form validation Radio

        Hello,

        On 01/23/2004 03:11 PM, Xaver Biton wrote:[color=blue][color=green][color=darkred]
        >>>how can I validate Radio Button group in form.[/color]
        >>
        >>How do birds fly?
        >>[/color]
        >
        > wha the checkbox or a radio Button doesn't work?[/color]

        You may want to try this class that lets you generate and validate forms
        exactly the way you want:

        http://www.phpclasses.org/formsgeneration

        --

        Regards,
        Manuel Lemos

        Free ready to use OOP components written in PHP
        http://www.phpclasses.org/

        MetaL - XML based meta-programming language


        Comment

        Working...