Re: Form helper issues "Invalid argument supplied for foreach()"
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Sun, 30 Mar 2008 20:27:49 -0500
George Maicovschi wrote:
On Mar 31, 1:04 am, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:George Maicovschi wrote:On Mar 30, 7:54 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:No, this will NOT throw an E_NOTICE. The isset() call will fail, so themejpark wrote:I wouldn't use an syntax like :On Mar 30, 2:47 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:Your problem is your code is checking the value ofmejpark wrote:>I've only modified the defaults array--the rest of the code is in
tact. Here it is:
$_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...@xxxxxxxxxxxxx
==================
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? :-)
later test will never be evaluated. Try it and see.
Should use if ($_SERVER['REQUEST_METHOD']=='POST') instead, and if youWhich tells nothing about HOW the page was posted. It could have been a
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.
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...@xxxxxxxxxxxxx
==================
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@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- References:
- Form helper issues "Invalid argument supplied for foreach()"
- From: mejpark
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: Mike Placentra II
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: mejpark
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: mejpark
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: Jerry Stuckle
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: mejpark
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: Jerry Stuckle
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: George Maicovschi
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: Jerry Stuckle
- Re: Form helper issues "Invalid argument supplied for foreach()"
- From: George Maicovschi
- Form helper issues "Invalid argument supplied for foreach()"
- Prev by Date: memcache issue
- Next by Date: Re: addslashes/mysql_real_escape_string
- Previous by thread: Re: Form helper issues "Invalid argument supplied for foreach()"
- Next by thread: Re: Form helper issues "Invalid argument supplied for foreach()"
- Index(es):