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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NotGiven

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

    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.


  • Andy Hassall

    #2
    Re: update form throws "Undefi ned index" error for unchecked radio button fields on form

    On Tue, 28 Sep 2004 14:10:02 -0400, "NotGiven" <noname@nonegiv en.net> wrote:
    [color=blue]
    >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.[/color]

    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.
    [color=blue]
    >Is this just something that shows with error reporting set to E_ALL and I
    >shouldn't worry about it?[/color]

    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 / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Simon Stienen

      #3
      Re: update form throws &quot;Undefi ned index&quot; error for unchecked radio button fields on form

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

      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.ne t> <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

      Comment

      Working...