how to show only entered fields ?

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

    #1

    how to show only entered fields ?

    hi all,

    I am getting lost in showing data entered in a form to a confirm page.
    I have a form with as many list/menu as the categories existing in the
    database. DONE

    when user choose the items from the list/menus they are passed on to a
    second page where he can check if all data are correct and then send
    it. DONE

    However on the confirm page the script returns also empty lines of text
    for the missing fields. I would like to just have the fields entered by
    the user one after each other and not as they were on the first form.
    How can I get rid of the empty fields ? ( of course just removing the
    <BR> tag is not a solution )

    I post the code of both pages below ( only the part of interest )

    TIA

    Johnny


    CONFIRM PAGE


    <form name="form1" method="post" action="send.ph p">
    <p>Please check the data u entered</p>
    <p>
    <input name="hiddenFie ld" type="hidden" value="<?php

    foreach ($_POST['field'] as $name=>$value) {


    echo nl2br("$value") ;
    }

    ?>">

    <?php

    foreach ($_POST['field'] as $name=>$value) {


    $split = split("\=", $value);
    $pieces = explode("=", $value);
    echo nl2br("$pieces[1]<BR>");
    }

    ?>
    </p>

    <input name="Submit" type="submit" value="PROCEDI &gt;&gt;">
    </p>
    </form>


    FORM PAGE

    <form name="form1" method="post" action="confirm .php">

    <?php



    $cat=mysql_quer y("SELECT DISTINCT category FROM table ORDER BY
    id", $db);
    while ($category=mysq l_fetch_array($ cat)) {
    $array_categoy[]=$category["category"];
    }



    foreach($array_ category as $key=>$val) {
    $data_link=mysq l_query("SELECT * FROM table WHERE
    category='$val' ",$db);
    ?>
    <?php $label = str_replace ( "_"," ",$val) ; ?>
    <p> <?php echo $label; ?></p>

    <select name="field[<?php $val ?>]"id="<?php $val ?>">
    <option > - - - - - - - - - - - - </option>
    <?php
    while ($link=mysql_fe tch_array($data _link)) {
    $description_li nk= $link["product"];
    $id_link = $link["id"];
    $code_link = $link["code"];



    print "<option value=\"$code_l ink = $description_li nk\">
    $description_li nk </option>";





    }
    ?>
    </select>
    <?php
    }
    ?>

    <input name="Submit" type="submit" value="GO ON &gt;&gt;">
    </form>

  • Scott Orsburn

    #2
    Re: how to show only entered fields ?

    johnny wrote:
    [color=blue]
    >However on the confirm page the script returns also empty lines of text
    >for the missing fields. I would like to just have the fields entered by
    >the user one after each other and not as they were on the first form.
    >How can I get rid of the empty fields ? ( of course just removing the
    ><BR> tag is not a solution )
    >[/color]


    Before you echo out the form value check to see if it's empty. I think
    comparing it to an empty string will do, but if it doesn't try comparing
    to null.

    if($FormVal != "") // Possibly need to use: != null instead.
    {
    echo $FormVal;
    }


    --
    Scott Orsburn
    scottso_no@spam _maclaunch.com

    Kaomso | Information Technology



    Comment

    • Michael Fesser

      #3
      Re: how to show only entered fields ?

      .oO(Scott Orsburn)
      [color=blue]
      >Before you echo out the form value check to see if it's empty. I think
      >comparing it to an empty string will do, but if it doesn't try comparing
      >to null.[/color]

      empty() exists.

      Micha

      Comment

      • Steve

        #4
        Re: how to show only entered fields ?

        if (!strlen($formV al))

        Comment

        • Scott Orsburn

          #5
          Re: how to show only entered fields ?

          Michael Fesser wrote:
          [color=blue]
          > .oO(Scott Orsburn)
          >
          >
          >[color=green]
          >>Before you echo out the form value check to see if it's empty. I think
          >>comparing it to an empty string will do, but if it doesn't try comparing
          >>to null.
          >>
          >>[/color]
          >
          >empty() exists.
          >
          >[/color]


          Cool. I was unaware of that one.


          --
          Scott Orsburn
          scottso_no@spam _maclaunch.com

          Kaomso | Information Technology


          Comment

          Working...