spaces in $_REQUEST (or $_GET, $_POST)

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

    spaces in $_REQUEST (or $_GET, $_POST)

    I have a legacy database table that has spaces in the field names.

    So I have a form that looks like this:

    <input type="text" name="name with space" value="some_val ue">

    on the server I have:

    $field_name = 'name with space';

    $my_form_value = $_POST[$field_name];

    That doesn't work, I never see the form element. How do I get around this?

    Note that I have many tables like this and I'm generating the edits
    programaticaly.

    Jeff
  • Willem Bogaerts

    #2
    Re: spaces in $_REQUEST (or $_GET, $_POST)

    Jeff wrote:
    I have a legacy database table that has spaces in the field names.
    >
    So I have a form that looks like this:
    >
    <input type="text" name="name with space" value="some_val ue">
    >
    on the server I have:
    >
    $field_name = 'name with space';
    >
    $my_form_value = $_POST[$field_name];
    >
    That doesn't work, I never see the form element. How do I get around this?
    What does enumerating the $_POST array say (the keys, that is)? I know
    periods are replaced with underscores. So spaces may be replaced with
    underscores as well.

    Best regards,
    --
    Willem Bogaerts

    Application smith
    Kratz B.V.

    Comment

    • Michael Fesser

      #3
      Re: spaces in $_REQUEST (or $_GET, $_POST)

      ..oO(Jeff)
      I have a legacy database table that has spaces in the field names.
      >
      So I have a form that looks like this:
      >
      ><input type="text" name="name with space" value="some_val ue">
      Such names are invalid:

      | ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
      | followed by any number of letters, digits ([0-9]), hyphens ("-"),
      | underscores ("_"), colons (":"), and periods (".").
      >on the server I have:
      >
      >$field_name = 'name with space';
      >
      >$my_form_val ue = $_POST[$field_name];
      >
      >That doesn't work, I never see the form element. How do I get around this?
      Fix the names.

      Micha

      Comment

      • Bill H

        #4
        Re: spaces in $_REQUEST (or $_GET, $_POST)

        On Sep 18, 10:24 am, Jeff <jeff@spam_me_n ot.comwrote:
          I have a legacy database table that has spaces in the field names.
        >
           So I have a form that looks like this:
        >
        <input type="text" name="name with space" value="some_val ue">
        >
        on the server I have:
        >
        $field_name = 'name with space';
        >
        $my_form_value = $_POST[$field_name];
        >
        That doesn't work, I never see the form element. How do I get around this?
        >
        Note that I have many tables like this and I'm generating the edits
        programaticaly.
        >
           Jeff
        Can you not just put in a translator? IE for outgoing html forms,
        replace the " " in the field with an underscore, then when reading the
        form and putting information in the database, replace the "_" in the
        field name with an underscore.

        Bill H

        Comment

        • Captain Paralytic

          #5
          Re: spaces in $_REQUEST (or $_GET, $_POST)

          On Sep 18, 8:02 pm, Bill H <b...@ts1000.us wrote:
          On Sep 18, 10:24 am, Jeff <jeff@spam_me_n ot.comwrote:
          >
          >
          >
            I have a legacy database table that has spaces in the field names.
          >
             So I have a form that looks like this:
          >
          <input type="text" name="name with space" value="some_val ue">
          >
          on the server I have:
          >
          $field_name = 'name with space';
          >
          $my_form_value = $_POST[$field_name];
          >
          That doesn't work, I never see the form element. How do I get around this?
          >
          Note that I have many tables like this and I'm generating the edits
          programaticaly.
          >
             Jeff
          >
          Can you not just put in a translator? IE for outgoing html forms,
          replace the " " in the field with an underscore, then when reading the
          form and putting information in the database, replace the "_" in the
          field name with an underscore.
          >
          Bill H
          Wouldn't you want to replace the "_" with a space?

          Comment

          • Jeff

            #6
            Re: spaces in $_REQUEST (or $_GET, $_POST)

            Bill H wrote:
            On Sep 18, 10:24 am, Jeff <jeff@spam_me_n ot.comwrote:
            > I have a legacy database table that has spaces in the field names.
            >>
            > So I have a form that looks like this:
            >>
            ><input type="text" name="name with space" value="some_val ue">
            >>
            >on the server I have:
            >>
            >$field_name = 'name with space';
            >>
            >$my_form_val ue = $_POST[$field_name];
            >>
            >That doesn't work, I never see the form element. How do I get around this?
            >>
            >Note that I have many tables like this and I'm generating the edits
            >programaticaly .
            >>
            > Jeff
            >
            Can you not just put in a translator? IE for outgoing html forms,
            replace the " " in the field with an underscore,
            I used a "+" to replace the spaces in the forms and when building the
            key for $_POST. I usually use underscores to replace spaces but I didn't
            want to use it here as I wanted some symbol that I wouldn't see
            otherwise, yet had some meaning.

            I don't know what naming conventions Access users use, but these
            tables have been driving me crazy. Field and table names are
            uppercase and have spaces in them. Primary keys may or may not be there
            and if they are they aren't autoincrement. Unfortunately, it's all
            mission critical stuff.

            Jeff

            then when reading the
            form and putting information in the database, replace the "_" in the
            field name with an underscore.
            >
            Bill H

            Comment

            • Jeff

              #7
              Re: spaces in $_REQUEST (or $_GET, $_POST)

              Jeff wrote:
              Bill H wrote:
              >On Sep 18, 10:24 am, Jeff <jeff@spam_me_n ot.comwrote:
              >> I have a legacy database table that has spaces in the field names.
              >>>
              >> So I have a form that looks like this:
              >>>
              >><input type="text" name="name with space" value="some_val ue">
              >>>
              >>on the server I have:
              >>>
              >>$field_name = 'name with space';
              >>>
              >>$my_form_valu e = $_POST[$field_name];
              >>>
              >>That doesn't work, I never see the form element. How do I get around
              >>this?
              >>>
              >>Note that I have many tables like this and I'm generating the edits
              >>programatical y.
              >>>
              >> Jeff
              >>
              >Can you not just put in a translator? IE for outgoing html forms,
              >replace the " " in the field with an underscore,
              >
              I used a "+" to replace the spaces in the forms and when building the
              key for $_POST. I usually use underscores to replace spaces but I didn't
              want to use it here as I wanted some symbol that I wouldn't see
              otherwise, yet had some meaning.
              After further thought, it didn't seem like + was legal in a form
              field name, so I went with the underscore.

              Jeff
              >
              I don't know what naming conventions Access users use, but these
              tables have been driving me crazy. Field and table names are
              uppercase and have spaces in them. Primary keys may or may not be there
              and if they are they aren't autoincrement. Unfortunately, it's all
              mission critical stuff.
              >
              Jeff
              >
              then when reading the
              >form and putting information in the database, replace the "_" in the
              >field name with an underscore.
              >>
              >Bill H

              Comment

              • =?iso-8859-1?Q?=C1lvaro?= G. Vicario

                #8
                Re: spaces in $_REQUEST (or $_GET, $_POST)

                *** Jeff escribió/wrote (Thu, 18 Sep 2008 10:24:56 -0400):
                I have a legacy database table that has spaces in the field names.
                >
                So I have a form that looks like this:
                >
                <input type="text" name="name with space" value="some_val ue">
                >
                on the server I have:
                >
                $field_name = 'name with space';
                >
                $my_form_value = $_POST[$field_name];

                If you print the contents of $_POST:

                print_r($_POST) ;

                You'll see the actual name:

                Array
                (
                [name_with_space] =some_value
                )

                The reason is that PHP used to create a local variable for each form value
                (now it's optional an deprecated) and you can't have a variable with spaces
                on its name.


                --
                -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
                -- Mi sitio sobre programación web: http://bits.demogracia.com
                -- Mi web de humor en cubitos: http://www.demogracia.com
                --

                Comment

                • John Dunlop

                  #9
                  Re: spaces in $_REQUEST (or $_GET, $_POST)

                  Michael Fesser:
                  .oO(Jeff)
                  >
                  <input type="text" name="name with space" value="some_val ue">
                  >
                  Such names are invalid:
                  >
                  | ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
                  | followed by any number of letters, digits ([0-9]), hyphens ("-"),
                  | underscores ("_"), colons (":"), and periods (".").
                  No, the value of the name attribute of the form element is declared as
                  CDATA, not as a NAME token, so pretty much anything goes, including
                  spaces.

                  But, as the FAQ says, PHP would convert these spaces to underscores.



                  --
                  Jock

                  Comment

                  • Michael Fesser

                    #10
                    Re: spaces in $_REQUEST (or $_GET, $_POST)

                    ..oO(John Dunlop)
                    >Michael Fesser:
                    >
                    >.oO(Jeff)
                    >>
                    ><input type="text" name="name with space" value="some_val ue">
                    >>
                    >Such names are invalid:
                    >>
                    >| ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
                    >| followed by any number of letters, digits ([0-9]), hyphens ("-"),
                    >| underscores ("_"), colons (":"), and periods (".").
                    >
                    >No, the value of the name attribute of the form element is declared as
                    >CDATA, not as a NAME token, so pretty much anything goes, including
                    >spaces.
                    Indeed, had forgotten that. Thanks for the correction.

                    I would still avoid them.

                    Micha

                    Comment

                    Working...