By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

how to show only entered fields ?

P: n/a
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.php">
<p>Please check the data u entered</p>
<p>
<input name="hiddenField" 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_query("SELECT DISTINCT category FROM table ORDER BY
id", $db);
while ($category=mysql_fetch_array($cat)) {
$array_categoy[]=$category["category"];
}

foreach($array_category as $key=>$val) {
$data_link=mysql_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_fetch_array($data_link)) {
$description_link= $link["product"];
$id_link = $link["id"];
$code_link = $link["code"];

print "<option value=\"$code_link = $description_link\">
$description_link </option>";

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

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

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
johnny wrote:
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 )

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
www.kaomso.com
Jul 17 '05 #2

P: n/a
.oO(Scott Orsburn)
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.


empty() exists.

Micha
Jul 17 '05 #3

P: n/a
if (!strlen($formVal))

Jul 17 '05 #4

P: n/a
Michael Fesser wrote:
.oO(Scott Orsburn)
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.


empty() exists.

Cool. I was unaware of that one.
--
Scott Orsburn
scottso_no@spam_maclaunch.com

Kaomso | Information Technology
www.kaomso.com

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.