Re: Form helper issues "Invalid argument supplied for foreach()"
am 30.03.2008 20:48:33 von George Maicovschi
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? :-)
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.
Re: Form helper issues "Invalid argument supplied for foreach()"
am 31.03.2008 00:04:37 von Jerry Stuckle
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.
jstucklex@attglobal.net
==================