FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Not understanding HTML form
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Not understanding HTML form [message #169429] Sun, 12 September 2010 18:06 Go to next message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma: 0
Member
I have a question about form submission in PHP (Perhaps more a HTML
question, but then I don't know).

Please look at the attached sample code. It is a mish-mash of things,
but this is what I want to know:

When the form initially displays, since the "action" field from the
form is not set, the PHP code performs the "else" part of the PHP
code.

Then when I type something into the "action' field, the isset test
evaluates to true and the "if" portion is executed. However the value
of the action field is not carried over, since the form does not have
a "value" clause for that input field.

However, on a 3rd iteration, without typing anything into any field,
the isset still evaluates to true, although the $_POST variable for
"action' shows a null field. How can I then recognize that that field
is in fact not set? or is it set with nulls or what is going on here?

sample code:

<?php
$MAX_FILE_SIZE = 300;
$version = 8;
$_POST['MAX_FILE_SIZE'] = 600;
echo <<<_END
<html>
<head>
<title>PHP Variable test</title>
</head>
<body>
<form method='post' action='TestVar.php'>
<br/>Form version $version</br>
<br/>This value should be the same as the variable
($MAX_FILE_SIZE) sent from PHP:
<input type='text' name='MAX_FILE_SIZE'
value="{$_POST['MAX_FILE_SIZE']}"/>
<br/> Type "X" here to process the form: <input type='text'
name='action' />
<br/> Select File: <input type='file' name='filename' size='60' /
>
<input type='submit' value='Submit' />
</form>
_END;

if (isset($_POST['action'])) {
echo "<br/>Input received<br/> ";
echo "<br/> post variables</br/>";
print_r($_POST);
echo "<br/> Get variables follows<br/>";
print_r($_GET);
echo "<br/> My variable '$MAX_FILE_SIZE': $MAX_FILE_SIZE";
echo "<br/> Form variable '$MAX_FILE_SIZE':
{$_POST['MAX_FILE_SIZE']}";
echo "<br/>print-r of max-f-s<br/>";
print_r($MAX_FILE_SIZE);
echo "<br/>Vardump of max-f-s<br/>";
var_dump($MAX_FILE_SIZE);
} else {
echo "<br/>No input processed.<br/>";
echo "<br/> post variables</br/>";
print_r($_POST);
echo "<br/> Get variables follows<br/>";
print_r($_GET);
echo "<br/> My variable '$MAX_FILE_SIZE': $MAX_FILE_SIZE";
echo "<br/> Form variable '$MAX_FILE_SIZE':
{$_POST['MAX_FILE_SIZE']}";
echo "<br/>print-r of max-f-s<br/>";
print_r($MAX_FILE_SIZE);
echo "<br/>Vardump of mas-f-s<br/>";
var_dump($MAX_FILE_SIZE);
}

echo "</body></html>";
?>
Re: Not understanding HTML form [message #169430 is a reply to message #169429] Sun, 12 September 2010 18:17 Go to previous messageGo to next message
Marious Barrier is currently offline  Marious Barrier
Messages: 25
Registered: September 2010
Karma: 0
Junior Member
On 09/12/2010 02:06 PM, MikeB wrote:
> However, on a 3rd iteration, without typing anything into any field,
> the isset still evaluates to true, although the $_POST variable for
> "action' shows a null field. How can I then recognize that that field
> is in fact not set? or is it set with nulls or what is going on here?

Isset will evaluate to false only when a variable is a *PHP* null or it
is not set. (null anyway too)
Re: Not understanding HTML form [message #169432 is a reply to message #169429] Sun, 12 September 2010 18:24 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/12/2010 2:06 PM, MikeB wrote:
> I have a question about form submission in PHP (Perhaps more a HTML
> question, but then I don't know).
>
> Please look at the attached sample code. It is a mish-mash of things,
> but this is what I want to know:
>
> When the form initially displays, since the "action" field from the
> form is not set, the PHP code performs the "else" part of the PHP
> code.
>
> Then when I type something into the "action' field, the isset test
> evaluates to true and the "if" portion is executed. However the value
> of the action field is not carried over, since the form does not have
> a "value" clause for that input field.
>
> However, on a 3rd iteration, without typing anything into any field,
> the isset still evaluates to true, although the $_POST variable for
> "action' shows a null field. How can I then recognize that that field
> is in fact not set? or is it set with nulls or what is going on here?
>

A variable containing an empty string (i.e. '') is still set. It is not
a "null field" - it is a string containing no characters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Not understanding HTML form [message #169433 is a reply to message #169430] Sun, 12 September 2010 18:25 Go to previous messageGo to next message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma: 0
Member
On Sep 12, 1:17 pm, Marious Barrier <marious.barr...@gmail.com> wrote:
> On 09/12/2010 02:06 PM, MikeB wrote:
>
>> However, on a 3rd iteration, without typing anything into any field,
>> the isset still evaluates to true, although the $_POST variable for
>> "action' shows a null field.  How can I then recognize that that field
>> is in fact not set? or is it set with nulls or what is going on here?
>
> Isset will evaluate to false only when a variable is a *PHP* null or it
> is not set. (null anyway too)


OK, I see it now. If I never enter a value in that field, on a 2nd
iteration, the isset() will also evaluate to true. so it does not
matter if I ever enter a value, just the fact that the form returns a
"null" value means the field is actually set for PHP. I guess I can
use the PHP function unset() to delete the variable from the array?

Hmmm back to the drawing board....

This stuff is hard and complicated. :(
Re: Not understanding HTML form [message #169434 is a reply to message #169433] Sun, 12 September 2010 18:52 Go to previous messageGo to next message
Marious Barrier is currently offline  Marious Barrier
Messages: 25
Registered: September 2010
Karma: 0
Junior Member
On 09/12/2010 02:25 PM, MikeB wrote:
> On Sep 12, 1:17 pm, Marious Barrier<marious.barr...@gmail.com> wrote:
>> On 09/12/2010 02:06 PM, MikeB wrote:
>>
>>> However, on a 3rd iteration, without typing anything into any field,
>>> the isset still evaluates to true, although the $_POST variable for
>>> "action' shows a null field. How can I then recognize that that field
>>> is in fact not set? or is it set with nulls or what is going on here?
>>
>> Isset will evaluate to false only when a variable is a *PHP* null or it
>> is not set. (null anyway too)
>
>
> OK, I see it now. If I never enter a value in that field, on a 2nd
> iteration, the isset() will also evaluate to true. so it does not
> matter if I ever enter a value, just the fact that the form returns a
> "null" value means the field is actually set for PHP. I guess I can
> use the PHP function unset() to delete the variable from the array?

Nah, don’t do unnecessary things.

> Hmmm back to the drawing board....
>
> This stuff is hard and complicated. :(

Not really, just do this.-

Check if isset($_POST['nameofthepost'])
or just count($_POST) to check if there is any post at all.
and... check the data sent with strlen(). remember, everything sent on
posts appears as strings in the server. You must transform them into
whatever you might need.

And remember, always filter... never trust the client’s input.
Re: Not understanding HTML form [message #169440 is a reply to message #169434] Mon, 13 September 2010 10:44 Go to previous message
Piyush Gupta is currently offline  Piyush Gupta
Messages: 6
Registered: September 2010
Karma: 0
Junior Member
On Sep 12, 11:52 pm, Marious Barrier <marious.barr...@gmail.com>
wrote:
> On 09/12/2010 02:25 PM, MikeB wrote:
>
>
>
>
>
>> On Sep 12, 1:17 pm, Marious Barrier<marious.barr...@gmail.com>  wrote:
>>> On 09/12/2010 02:06 PM, MikeB wrote:
>
>>>> However, on a 3rd iteration, without typing anything into any field,
>>>> the isset still evaluates to true, although the $_POST variable for
>>>> "action' shows a null field.  How can I then recognize that that field
>>>> is in fact not set? or is it set with nulls or what is going on here?
>
>>> Isset will evaluate to false only when a variable is a *PHP* null or it
>>> is not set. (null anyway too)
>
>> OK, I see it now. If I never enter a value in that field, on a 2nd
>> iteration, the isset() will also evaluate to true. so it does not
>> matter if I ever enter a value, just the fact that the form returns a
>> "null" value means the field is actually set for PHP. I guess I can
>> use the PHP function unset() to delete the variable from the array?
>
> Nah, don’t do unnecessary things.
>
>>   Hmmm back to the drawing board....
>
>> This stuff is hard and complicated. :(
>
> Not really, just do this.-
>
> Check if isset($_POST['nameofthepost'])
> or just count($_POST) to check if there is any post at all.
> and... check the data sent with strlen(). remember, everything sent on
> posts appears as strings in the server. You must transform them into
> whatever you might need.
>
> And remember, always filter... never trust the client’s input.

Hi ,

We at www.rntlabs.com [RNTLABS Software Solutions] have exciting
openings for the below

1/ PHP
2/ Designers
3/ Android
4/ iPhone
5/ QA
6/ ROR

Please apply at hr(at)rntlabs(dot)com ASAP .

Thanks

Piyush Gupta
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Session Cache
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 15:04:59 GMT 2024

Total time taken to generate the page: 0.01890 seconds