By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,244 Members | 1,772 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,244 IT Pros & Developers. It's quick & easy.

update form throws "Undefined index" error for unchecked radio button fields on form

P: n/a
I have display error ON and error reporting to E_ALL.

I have a form that opens fine. When you submit it, all the fields that have
nothing in them, for example an un-selected radio button, throw the error
similar to that below.

Notice: Undefined index: fld_ONECHOICE in /usr/..../updateFORMFACT.php on
line 29

These fields are not required for the form to be completed.

Do I HAVE to default all fields to yes/no or some entry? Surely not.

Is this just something that shows with error reporting set to E_ALL and I
shouldn't worry about it?

Thank in advance.
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 28 Sep 2004 14:10:02 -0400, "NotGiven" <no****@nonegiven.net> wrote:
I have display error ON and error reporting to E_ALL.

I have a form that opens fine. When you submit it, all the fields that have
nothing in them, for example an un-selected radio button, throw the error
similar to that below.

Notice: Undefined index: fld_ONECHOICE in /usr/..../updateFORMFACT.php on
line 29

These fields are not required for the form to be completed.

Do I HAVE to default all fields to yes/no or some entry? Surely not.
Unchecked checkboxes or radio buttons are not "successful controls" as defined
in the HTML spec. and don't send values, so the index won't be defined.
Is this just something that shows with error reporting set to E_ALL and I
shouldn't worry about it?


Use isset() to determine whether the index is defined before trying to use it.

Or use @ to suppress errors if you're sure the potential side-effects won't
break your code: e.g. $x = @$_GET['fld_ONECHOICE'];

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
Andy Hassall <an**@andyh.co.uk> wrote:
Or use @ to suppress errors if you're sure the potential side-effects won't
break your code: e.g. $x = @$_GET['fld_ONECHOICE'];


You should never suppress errors or warning, if there is a reasonable way
not to raise them:
$x = isset($_GET['some_val'])
? $_GET['some_val']
: $default_value;
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.