Initialize form values to NULL
Initialize form values to NULL
am 24.08.2007 04:22:10 von Oberon
I am looking to initialize form values to NULL prior to the client filling
in the form.
I would like to do this using an array by putting all of the form variables
into it and setting them using a foreach() loop to NULL.
Is there a way to do this using PHP 5.1.2?
Re: Initialize form values to NULL
am 24.08.2007 04:28:57 von Jerry Stuckle
Oberon wrote:
> I am looking to initialize form values to NULL prior to the client filling
> in the form.
>
> I would like to do this using an array by putting all of the form variables
> into it and setting them using a foreach() loop to NULL.
>
> Is there a way to do this using PHP 5.1.2?
>
>
HTML does not recognize null values. A form object always has a value,
although that value may be an empty string.
Some types of form objects (i.e. checkboxes) will only send their value
of they are checked. Others (i.e. text fields) will send an empty
string if there is nothing in the field.
PHP cannot change this behavior.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Initialize form values to NULL
am 24.08.2007 05:36:50 von Oberon
Understood.
However, I have done this before using
$_POST['<--hardCodedValueGoesHere-->'] = NULL;. I was wondering if there
was a way to accomplish this with a loop structure instead of longhand,
line-by-line for each form value....particularly if I have a form with 30+
fields which I am required to build.
Currently this is the test form:
*****************************************************
*****************************************************
The reason I want to do what I want to do is two-fold:
1. Preserve entered data in the fields in case the form is not properly
filled out.
2. Use an array structure for error checking and changing the CSS
properties to visually indicate an error on the page.
--Like I said, I've done this before, I'm just looking for a short form way
to do it.
Thanks,
Rob
"Jerry Stuckle" wrote in message
news:c9SdnUknBuwr31PbnZ2dnUVZ_jednZ2d@comcast.com...
> Oberon wrote:
>> I am looking to initialize form values to NULL prior to the client
>> filling in the form.
>>
>> I would like to do this using an array by putting all of the form
>> variables into it and setting them using a foreach() loop to NULL.
>>
>> Is there a way to do this using PHP 5.1.2?
>
> HTML does not recognize null values. A form object always has a value,
> although that value may be an empty string.
>
> Some types of form objects (i.e. checkboxes) will only send their value of
> they are checked. Others (i.e. text fields) will send an empty string if
> there is nothing in the field.
>
> PHP cannot change this behavior.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
Re: Initialize form values to NULL
am 24.08.2007 06:27:56 von Steve
| However, I have done this before using
| $_POST['<--hardCodedValueGoesHere-->'] = NULL;. I was wondering if there
| was a way to accomplish this with a loop structure instead of longhand,
| line-by-line for each form value....particularly if I have a form with 30+
| fields which I am required to build.
| The reason I want to do what I want to do is two-fold:
|
| 1. Preserve entered data in the fields in case the form is not properly
| filled out.
which setting posted variables to null accomplished...in reverse. ;^)
| 2. Use an array structure for error checking and changing the CSS
| properties to visually indicate an error on the page.
which has nothing to do with setting the $_POST *array* values to null.
| --Like I said, I've done this before, I'm just looking for a short form
way
| to do it.
function senselessButAskedFor(&$value)
{
$value = null;
}
array_walk('senselessButAskedFor', $_POST);
short enough?
Re: Initialize form values to NULL
am 24.08.2007 09:22:29 von Oberon
array_walk eh?
Thanks for the tip.
"Steve" wrote in message
news:X6tzi.418$Yj6.215@newsfe06.lga...
>| However, I have done this before using
> | $_POST['<--hardCodedValueGoesHere-->'] = NULL;. I was wondering if
> there
> | was a way to accomplish this with a loop structure instead of longhand,
> | line-by-line for each form value....particularly if I have a form with
> 30+
> | fields which I am required to build.
>
>
>
> | The reason I want to do what I want to do is two-fold:
> |
> | 1. Preserve entered data in the fields in case the form is not
> properly
> | filled out.
>
> which setting posted variables to null accomplished...in reverse. ;^)
>
> | 2. Use an array structure for error checking and changing the CSS
> | properties to visually indicate an error on the page.
>
> which has nothing to do with setting the $_POST *array* values to null.
>
> | --Like I said, I've done this before, I'm just looking for a short form
> way
> | to do it.
>
> function senselessButAskedFor(&$value)
> {
> $value = null;
> }
>
> array_walk('senselessButAskedFor', $_POST);
>
> short enough?
>
>