Re: Form helper issues "Invalid argument supplied for foreach()"
Re: Form helper issues "Invalid argument supplied for foreach()"
am 30.03.2008 23:39:56 von George Maicovschi
On Mar 31, 1:04 am, Jerry Stuckle wrote:
> George Maicovschi wrote:
> > On Mar 30, 7:54 pm, Jerry Stuckle wrote:
> >> mejpark wrote:
> >>> On Mar 30, 2:47 pm, Jerry Stuckle wrote:
> >>>> mejpark wrote:>
> >>> I've only modified the defaults array--the rest of the code is in
> >>> tact. Here it is:
> >> Your problem is your code is checking the value of
> >> $_POST['_submit_check'] but not checking to see if any value is set.
> >> The first time the page is called, this will not be set.
>
> >> Failing code:
>
> >> if ($_POST['_submit_check']) {
>
> >> Should be:
>
> >> if (isset($_POST['_submit_check'])) {
>
> >> Or, better yet.
>
> >> if (isset($_POST['_submit_check']) && $_POST['_submit_check'] == 1) {
>
> >> Normally I think O'Reilly books are pretty good - but your problems with
> >> code makes me wonder about this one...
>
> >> --
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> ==================
>
> > I wouldn't use an syntax like :
> > if (isset($_POST['_submit_check']) && $_POST['_submit_check'] == 1)
>
> > Because, as I was saying earlier if the request method is GET it WILL
> > throw an E_NOTICE error. Better keep your logs only for errors,
> > right? :-)
>
> No, this will NOT throw an E_NOTICE. The isset() call will fail, so the
> later test will never be evaluated. Try it and see.
>
> > Should use if ($_SERVER['REQUEST_METHOD']=='POST') instead, and if you
> > really want to validate $_POST['_submit_check'] you should do it like
> > this:
> > if ($_SERVER['REQUEST_METHOD']=='POST)
> > if (!empty($_POST['_submit_check']))
>
> > My two cents.
>
> Which tells nothing about HOW the page was posted. It could have been a
> POST request from an entirely different page - which doesn't have the
> appropriate values set. It also can't tell which of several different
> SUBMIT buttons might have been pressed.
>
> It is always better to check for specific button than to just check the
> REQUEST_METHOD. I find very little use for the latter. Knowing the
> request method by itself is virtually useless.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Yeah, I might have jumped to conclusions on that E_NOTICE thing but I
rather first detect the request method and only after that validate
the submit button used, in terms of speed. == is faster than isset().
Anyway, the !empty() could be ==1 or any other thing, it was just an
example of how it could be done.
Re: Form helper issues "Invalid argument supplied for foreach()"
am 31.03.2008 03:27:49 von Jerry Stuckle
George Maicovschi wrote:
> On Mar 31, 1:04 am, Jerry Stuckle wrote:
>> George Maicovschi wrote:
>>> On Mar 30, 7:54 pm, Jerry Stuckle wrote:
>>>> mejpark wrote:
>>>>> On Mar 30, 2:47 pm, Jerry Stuckle wrote:
>>>>>> mejpark wrote:>
>>>>> I've only modified the defaults array--the rest of the code is in
>>>>> tact. Here it is:
>>>> Your problem is your code is checking the value of
>>>> $_POST['_submit_check'] but not checking to see if any value is set.
>>>> The first time the page is called, this will not be set.
>>>> Failing code:
>>>> if ($_POST['_submit_check']) {
>>>> Should be:
>>>> if (isset($_POST['_submit_check'])) {
>>>> Or, better yet.
>>>> if (isset($_POST['_submit_check']) && $_POST['_submit_check'] == 1) {
>>>> Normally I think O'Reilly books are pretty good - but your problems with
>>>> code makes me wonder about this one...
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================
>>> I wouldn't use an syntax like :
>>> if (isset($_POST['_submit_check']) && $_POST['_submit_check'] == 1)
>>> Because, as I was saying earlier if the request method is GET it WILL
>>> throw an E_NOTICE error. Better keep your logs only for errors,
>>> right? :-)
>> No, this will NOT throw an E_NOTICE. The isset() call will fail, so the
>> later test will never be evaluated. Try it and see.
>>
>>> Should use if ($_SERVER['REQUEST_METHOD']=='POST') instead, and if you
>>> really want to validate $_POST['_submit_check'] you should do it like
>>> this:
>>> if ($_SERVER['REQUEST_METHOD']=='POST)
>>> if (!empty($_POST['_submit_check']))
>>> My two cents.
>> Which tells nothing about HOW the page was posted. It could have been a
>> POST request from an entirely different page - which doesn't have the
>> appropriate values set. It also can't tell which of several different
>> SUBMIT buttons might have been pressed.
>>
>> It is always better to check for specific button than to just check the
>> REQUEST_METHOD. I find very little use for the latter. Knowing the
>> request method by itself is virtually useless.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Yeah, I might have jumped to conclusions on that E_NOTICE thing but I
> rather first detect the request method and only after that validate
> the submit button used, in terms of speed. == is faster than isset().
>
It is? Can you prove that? I find any difference is so small as to be
immeasurable, at least under normal conditions.
> Anyway, the !empty() could be ==1 or any other thing, it was just an
> example of how it could be done.
>
And my code was to show how it should be done in his case.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Form helper issues "Invalid argument supplied for foreach()"
am 04.04.2008 18:44:06 von good
In article <_NSdnVmThLSTrW3anZ2dnUVZ_jCdnZ2d@comcast.com>,
jstucklex@attglobal.net says...
> > > the submit button used, in terms of speed. == is faster than isset().
> It is? Can you prove that? I find any difference is so small as to be
> immeasurable, at least under normal conditions.
>
It probably is jerry - if you think about it == probably interprets as a
single processor call (effectively) - where as isset may have to do a
couple of extra fetches first ....
But like you say the difference would be so small as to be irrelevant and
certainly not worth bothering about in PHP
In fact I'd go so far as to say the coding documentation benefits of
using isset should make it the method of choice no matter how much slower
it is.
Re: Form helper issues "Invalid argument supplied for foreach()"
am 04.04.2008 20:17:27 von Jerry Stuckle
good@respnse.sic.com wrote:
> In article <_NSdnVmThLSTrW3anZ2dnUVZ_jCdnZ2d@comcast.com>,
> jstucklex@attglobal.net says...
>
>>>> the submit button used, in terms of speed. == is faster than isset().
>
>> It is? Can you prove that? I find any difference is so small as to be
>> immeasurable, at least under normal conditions.
>>
>
>
> It probably is jerry - if you think about it == probably interprets as a
> single processor call (effectively) - where as isset may have to do a
> couple of extra fetches first ....
>
> But like you say the difference would be so small as to be irrelevant and
> certainly not worth bothering about in PHP
>
> In fact I'd go so far as to say the coding documentation benefits of
> using isset should make it the method of choice no matter how much slower
> it is.
>
>
>
That would be true if the value is set. However, if it is not set, then
PHP has to go into error processing for the E_NOTICE. Even if you're
not logging or displaying the E_NOTICE errors, PHP has to still
determine it doesn't have to do anything with the message.
And, of course, if you do have the E_NOTICE messages displayed or
logged, the overhead is even greater.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================