Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

empty fields in form

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hey,

I'm writing an website with a form. When I post the form I want to get all the values and elements. I thought using:

while (list($element,$waarde) = each($_POST)) {
echo ("<b>$element</b> = $waarde<br>");
}

but when I don't fill in a field in the form I don't see the element in my echo? Is there a way to get the element by using while ... each when the field is left empty?

The One And Only KryptoS
 
It depends on the type of field.

Form fields of type "text" will always submit data to a script, even when empty. A checkbox will not.

The only way to get them all is to let your script know what field names it should expect. For example:

Code:
<?php
print '<html><body><pre>';
$field_names = array('foo', 'bar');

foreach ($field_names as $field_name)
{
   print $field_name . '="' . $_POST[$field_name] . "\r\n";
}
print '</pre></body></html>';
?>

Keep in mind, too, that the script:

Code:
<?php
print '<html><body><pre>';
print_r ($_POST);
print '</pre></body></html>';
?>[code]


Want the best answers? [url=http://www.catb.org/~esr/faqs/smart-questions.html]Ask the best questions![/url]

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top