How do I parse form elements or am I doing this wrong?

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

    How do I parse form elements or am I doing this wrong?

    I have a food menu. Each area, like beverages, grill, etc. have items
    under them, Coke, Tea, Coffee would be under beverages for example.

    I want to add a new drink to beverages. In my database I have an
    "area" like above, Bevs, Grill, Chicken... In my menu items I have an
    ID from the area so,

    table areas
    id 1 areaname beverages
    id 2 areaname grill

    table menuitems

    id 1 areaid 1 menuitem coke
    id 2 areaid 1 menuitem sprite
    id 3 areaid 2 menuitem hamburger

    Now, in my form, I have the entire menu displayed with all areas and
    menu items. In each area there is small set of textboxes to enter new
    menuitems for that area with a button. Messy yes, but what I can't
    figure out how to do is get the unique table area id for the new menu
    item because when the user clicks submit it doesn't just send the
    "name" across for that particular area addition. it sends all the
    form elements over and since they are all named the same thing I have
    tons of them and I don't know how to get just that unique id. I know
    I've lost you. Let me try again.

    In the display I have beverages and right underneath it has a textbox
    for a new item and next to that a save button. Underneath this I have
    grill and right underneath it has a textbox for a new itema and next
    to that a save button and so on with ever area. These are generated
    by a set of loops from my database.

    Since all the textboxes have the same "name" attribute when I click
    save I get many many identical attributes:

    myprocessor.php ?id=3&item=coke &id=4&item=0... . I just get a
    querystring with lots of blank variables. I know I must be doing
    something to have this. All I really need is one ID. The ID from the
    current area and that textbox only, but I can't since all the
    generated elements are in between the same <formelement. Thank you.
  • RootShell (IFReviews.org)

    #2
    Re: How do I parse form elements or am I doing this wrong?

    hello

    Why not make a <FORMfor every area? that way you will only get a set
    of values for that area.

    For instance <FORM for beveragesand <FORM for grilleach with a
    separate SUBMIT button?

    why not use the POST method instead of the GET?

    Why not use a special ID for each field (areas+menuitem s) ?

    beverages
    coffee

    would be ID = 1-4

    You would then explode the ID by the - and get area and menuitem

    Maybe i'm getting wrongly what you ask, but it seems that it might work.



    jmDesktop wrote:
    I have a food menu. Each area, like beverages, grill, etc. have items
    under them, Coke, Tea, Coffee would be under beverages for example.
    >
    I want to add a new drink to beverages. In my database I have an
    "area" like above, Bevs, Grill, Chicken... In my menu items I have an
    ID from the area so,
    >
    table areas
    id 1 areaname beverages
    id 2 areaname grill
    >
    table menuitems
    >
    id 1 areaid 1 menuitem coke
    id 2 areaid 1 menuitem sprite
    id 3 areaid 2 menuitem hamburger
    >
    Now, in my form, I have the entire menu displayed with all areas and
    menu items. In each area there is small set of textboxes to enter new
    menuitems for that area with a button. Messy yes, but what I can't
    figure out how to do is get the unique table area id for the new menu
    item because when the user clicks submit it doesn't just send the
    "name" across for that particular area addition. it sends all the
    form elements over and since they are all named the same thing I have
    tons of them and I don't know how to get just that unique id. I know
    I've lost you. Let me try again.
    >
    In the display I have beverages and right underneath it has a textbox
    for a new item and next to that a save button. Underneath this I have
    grill and right underneath it has a textbox for a new itema and next
    to that a save button and so on with ever area. These are generated
    by a set of loops from my database.
    >
    Since all the textboxes have the same "name" attribute when I click
    save I get many many identical attributes:
    >
    myprocessor.php ?id=3&item=coke &id=4&item=0... . I just get a
    querystring with lots of blank variables. I know I must be doing
    something to have this. All I really need is one ID. The ID from the
    current area and that textbox only, but I can't since all the
    generated elements are in between the same <formelement. Thank you.

    Comment

    • C. (http://symcbean.blogspot.com/)

      #3
      Re: How do I parse form elements or am I doing this wrong?

      On 14 Sep, 00:37, jmDesktop <needin4mat...@ gmail.comwrote:
      I have a food menu. Each area, like beverages, grill, etc. have items
      under them, Coke, Tea, Coffee would be under beverages for example.
      >
      I want to add a new drink to beverages. In my database I have an
      "area" like above, Bevs, Grill, Chicken... In my menu items I have an
      ID from the area so,
      >
      table areas
      id 1 areaname beverages
      id 2 areaname grill
      >
      table menuitems
      >
      id 1 areaid 1 menuitem coke
      id 2 areaid 1 menuitem sprite
      id 3 areaid 2 menuitem hamburger
      <snip>
      >
      Since all the textboxes have the same "name" attribute when I click
      save I get many many identical attributes:
      don't use 'name' - use 'name[]' and PHP will assign array indices
      automtically. But you'll need to do some testing around this if more
      than one is added at a time to multiple fields.

      C.

      Comment

      • sheldonlg

        #4
        Re: How do I parse form elements or am I doing this wrong?

        C. (http://symcbean.blogspot.com/) wrote:
        On 14 Sep, 00:37, jmDesktop <needin4mat...@ gmail.comwrote:
        >I have a food menu. Each area, like beverages, grill, etc. have items
        >under them, Coke, Tea, Coffee would be under beverages for example.
        >>
        >I want to add a new drink to beverages. In my database I have an
        >"area" like above, Bevs, Grill, Chicken... In my menu items I have an
        >ID from the area so,
        >>
        >table areas
        >id 1 areaname beverages
        >id 2 areaname grill
        >>
        >table menuitems
        >>
        >id 1 areaid 1 menuitem coke
        >id 2 areaid 1 menuitem sprite
        >id 3 areaid 2 menuitem hamburger
        <snip>
        >Since all the textboxes have the same "name" attribute when I click
        >save I get many many identical attributes:
        >
        don't use 'name' - use 'name[]' and PHP will assign array indices
        automtically. But you'll need to do some testing around this if more
        than one is added at a time to multiple fields.
        >
        C.
        Or, what you can do is have the form use post and simply have a test on
        the value of the submit button. You could have the value of those
        sumbit buttons be "Add Beverage", "Add Entree" etc. That would tell you
        the area that it is coming from by which button was pressed.

        Since you now have a long URL listed, you are obviously using method
        get. What are you currently doing to produce that very long URL? Does
        each of the buttons have an exrremely long onclick, with each field
        being filled by something like a
        document.getEle mentById('the_n ame'),value? Are you using a javascript
        function to get and build that string and then doing a submit from
        there? If either of these, it is very easy to just limit the url and in
        the receiving script test to see which was changed. Why, you could even
        add a "director" field to indicate this and switch on that field to
        extract the actual value from the URL via a $_GET.

        There are many way to get what you want. You have been given several
        suggestions here and by previous responders. My suggestion is getrid of
        all those parameters in the URL and change to a method=post.

        Comment

        • sheldonlg

          #5
          Re: How do I parse form elements or am I doing this wrong?

          sheldonlg wrote:
          C. (http://symcbean.blogspot.com/) wrote:
          >On 14 Sep, 00:37, jmDesktop <needin4mat...@ gmail.comwrote:
          >>I have a food menu. Each area, like beverages, grill, etc. have items
          >>under them, Coke, Tea, Coffee would be under beverages for example.
          >>>
          >>I want to add a new drink to beverages. In my database I have an
          >>"area" like above, Bevs, Grill, Chicken... In my menu items I have an
          >>ID from the area so,
          >>>
          >>table areas
          >>id 1 areaname beverages
          >>id 2 areaname grill
          >>>
          >>table menuitems
          >>>
          >>id 1 areaid 1 menuitem coke
          >>id 2 areaid 1 menuitem sprite
          >>id 3 areaid 2 menuitem hamburger
          ><snip>
          >>Since all the textboxes have the same "name" attribute when I click
          >>save I get many many identical attributes:
          >>
          >don't use 'name' - use 'name[]' and PHP will assign array indices
          >automtically . But you'll need to do some testing around this if more
          >than one is added at a time to multiple fields.
          >>
          >C.
          >
          Or, what you can do is have the form use post and simply have a test on
          the value of the submit button. You could have the value of those
          sumbit buttons be "Add Beverage", "Add Entree" etc. That would tell you
          the area that it is coming from by which button was pressed.
          >
          Since you now have a long URL listed, you are obviously using method
          get. What are you currently doing to produce that very long URL? Does
          each of the buttons have an exrremely long onclick, with each field
          being filled by something like a
          document.getEle mentById('the_n ame'),value? Are you using a javascript
          function to get and build that string and then doing a submit from
          there? If either of these, it is very easy to just limit the url and in
          the receiving script test to see which was changed. Why, you could even
          add a "director" field to indicate this and switch on that field to
          extract the actual value from the URL via a $_GET.
          >
          There are many way to get what you want. You have been given several
          suggestions here and by previous responders. My suggestion is getrid of
          all those parameters in the URL and change to a method=post.
          >
          Another comment:

          From the OP's description, it seems that this is a natural fit for
          AJAX. The user would click on a particular button, it would use an
          onclick to pass in the the correct info to the javascript function. The
          call to php would do an insert of that pair and on a return from php
          would update that region and blank the text area. The user would remain
          on the menu page.

          Comment

          • Jerry Stuckle

            #6
            Re: How do I parse form elements or am I doing this wrong?

            jmDesktop wrote:
            I have a food menu. Each area, like beverages, grill, etc. have items
            under them, Coke, Tea, Coffee would be under beverages for example.
            >
            I want to add a new drink to beverages. In my database I have an
            "area" like above, Bevs, Grill, Chicken... In my menu items I have an
            ID from the area so,
            >
            table areas
            id 1 areaname beverages
            id 2 areaname grill
            >
            table menuitems
            >
            id 1 areaid 1 menuitem coke
            id 2 areaid 1 menuitem sprite
            id 3 areaid 2 menuitem hamburger
            >
            Now, in my form, I have the entire menu displayed with all areas and
            menu items. In each area there is small set of textboxes to enter new
            menuitems for that area with a button. Messy yes, but what I can't
            figure out how to do is get the unique table area id for the new menu
            item because when the user clicks submit it doesn't just send the
            "name" across for that particular area addition. it sends all the
            form elements over and since they are all named the same thing I have
            tons of them and I don't know how to get just that unique id. I know
            I've lost you. Let me try again.
            >
            In the display I have beverages and right underneath it has a textbox
            for a new item and next to that a save button. Underneath this I have
            grill and right underneath it has a textbox for a new itema and next
            to that a save button and so on with ever area. These are generated
            by a set of loops from my database.
            >
            Since all the textboxes have the same "name" attribute when I click
            save I get many many identical attributes:
            >
            myprocessor.php ?id=3&item=coke &id=4&item=0... . I just get a
            querystring with lots of blank variables. I know I must be doing
            something to have this. All I really need is one ID. The ID from the
            current area and that textbox only, but I can't since all the
            generated elements are in between the same <formelement. Thank you.
            >
            Yes, this is a problem. Probably the best way to handle it is to give
            each text area a different name - i.e. "new_bevera ge", "new_grill" , etc.
            Then when the form gets submitted, check each area to see that it is
            not empty. An advantage of this over individual forms is you can add
            multiple items (one of each) at once.

            You could even name the text areas new_beverage[], new_grill[], etc. and
            have multiple of each on the page. If you had three of each, you could
            add up to three of each item on every page.

            Alternatives such as having separate forms for each section or having
            "Add Beverage", "Add Grill", etc. buttons limit you to being able to add
            a single item each time. That may be ok, but if you have a lot of items
            to add to a menu, it can get old real fast.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • jmDesktop

              #7
              Re: How do I parse form elements or am I doing this wrong?

              On Sep 14, 6:59 am, "C. (http://symcbean.blogsp ot.com/)"
              <colin.mckin... @gmail.comwrote :
              On 14 Sep, 00:37, jmDesktop <needin4mat...@ gmail.comwrote:
              >
              >
              >
              >
              >
              I have a food menu.  Each area, like beverages, grill, etc. have items
              under them, Coke, Tea, Coffee would be under beverages for example.
              >
              I want to add a new drink to beverages.  In my database I have an
              "area" like above, Bevs, Grill, Chicken...  In my menu items I have an
              ID from the area so,
              >
              table areas
              id 1 areaname beverages
              id 2 areaname grill
              >
              table menuitems
              >
              id 1 areaid 1 menuitem coke
              id 2 areaid 1 menuitem sprite
              id 3 areaid 2 menuitem hamburger
              <snip>
              >
              Since all the textboxes have the same "name" attribute when I click
              save I get many many identical attributes:
              >
              don't use 'name' - use 'name[]' and PHP will assign array indices
              automtically. But you'll need to do some testing around this if more
              than one is added at a time to multiple fields.
              >
              C.- Hide quoted text -
              >
              - Show quoted text -
              use name[] where? Sorry. Never done that before.

              Comment

              • jmDesktop

                #8
                Re: How do I parse form elements or am I doing this wrong?

                On Sep 13, 8:04 pm, "RootShell (IFReviews.org) "
                <rootsh...@ifre views.orgwrote:
                hello
                >
                Why not make a <FORMfor every area? that way you will only get a set
                of values for that area.
                >
                For instance <FORM for beveragesand <FORM for grilleach with a
                separate SUBMIT button?
                >
                why not use the POST method instead of the GET?
                >
                Why not use a special ID for each field (areas+menuitem s) ?
                >
                beverages
                   coffee
                >
                would be ID = 1-4
                >
                You would then explode the ID by the - and get area and menuitem
                >
                Maybe i'm getting wrongly what you ask, but it seems that it might work.
                >
                >
                >
                jmDesktop wrote:
                I have a food menu.  Each area, like beverages, grill, etc. have items
                under them, Coke, Tea, Coffee would be under beverages for example.
                >
                I want to add a new drink to beverages.  In my database I have an
                "area" like above, Bevs, Grill, Chicken...  In my menu items I have an
                ID from the area so,
                >
                table areas
                id 1 areaname beverages
                id 2 areaname grill
                >
                table menuitems
                >
                id 1 areaid 1 menuitem coke
                id 2 areaid 1 menuitem sprite
                id 3 areaid 2 menuitem hamburger
                >
                Now, in my form, I have the entire menu displayed with all areas and
                menu items.  In each area there is small set of textboxes to enter new
                menuitems for that area with a button.  Messy yes, but what I can't
                figure out how to do is get the unique table area id for the new menu
                item because when the user clicks submit it doesn't just send the
                "name" across for that particular area addition.  it sends all the
                form elements over and since they are all named the same thing I have
                tons of them and I don't know how to get just that unique id.  I know
                I've lost you.  Let me try again.
                >
                In the display I have beverages and right underneath it has a textbox
                for a new item and next to that a save button.  Underneath this I have
                grill and right underneath it has a textbox for a new itema and next
                to that a save button and so on with ever area.  These are generated
                by a set of loops from my database.
                >
                Since all the textboxes have the same "name" attribute when I click
                save I get many many identical attributes:
                >
                myprocessor.php ?id=3&item=coke &id=4&item=0... .  I just get a
                querystring with lots of blank variables.  I know I must be doing
                something to have this.  All I really need is one ID.  The ID from the
                current area and that textbox only, but I can't since all the
                generated elements are in between the same <formelement.  Thank you..- Hide quoted text -
                >
                - Show quoted text -
                Thanks. I didn't know you could have more than one form on a page. I
                guess that is from my .NET.

                Comment

                • Jerry Stuckle

                  #9
                  Re: How do I parse form elements or am I doing this wrong?

                  jmDesktop wrote:
                  On Sep 13, 8:04 pm, "RootShell (IFReviews.org) "
                  <rootsh...@ifre views.orgwrote:
                  >hello
                  >>
                  >Why not make a <FORMfor every area? that way you will only get a set
                  >of values for that area.
                  >>
                  >For instance <FORM for beveragesand <FORM for grilleach with a
                  >separate SUBMIT button?
                  >>
                  >why not use the POST method instead of the GET?
                  >>
                  >Why not use a special ID for each field (areas+menuitem s) ?
                  >>
                  >beverages
                  > coffee
                  >>
                  >would be ID = 1-4
                  >>
                  >You would then explode the ID by the - and get area and menuitem
                  >>
                  >Maybe i'm getting wrongly what you ask, but it seems that it might work.
                  >>
                  >>
                  >>
                  >jmDesktop wrote:
                  >>I have a food menu. Each area, like beverages, grill, etc. have items
                  >>under them, Coke, Tea, Coffee would be under beverages for example.
                  >>I want to add a new drink to beverages. In my database I have an
                  >>"area" like above, Bevs, Grill, Chicken... In my menu items I have an
                  >>ID from the area so,
                  >>table areas
                  >>id 1 areaname beverages
                  >>id 2 areaname grill
                  >>table menuitems
                  >>id 1 areaid 1 menuitem coke
                  >>id 2 areaid 1 menuitem sprite
                  >>id 3 areaid 2 menuitem hamburger
                  >>Now, in my form, I have the entire menu displayed with all areas and
                  >>menu items. In each area there is small set of textboxes to enter new
                  >>menuitems for that area with a button. Messy yes, but what I can't
                  >>figure out how to do is get the unique table area id for the new menu
                  >>item because when the user clicks submit it doesn't just send the
                  >>"name" across for that particular area addition. it sends all the
                  >>form elements over and since they are all named the same thing I have
                  >>tons of them and I don't know how to get just that unique id. I know
                  >>I've lost you. Let me try again.
                  >>In the display I have beverages and right underneath it has a textbox
                  >>for a new item and next to that a save button. Underneath this I have
                  >>grill and right underneath it has a textbox for a new itema and next
                  >>to that a save button and so on with ever area. These are generated
                  >>by a set of loops from my database.
                  >>Since all the textboxes have the same "name" attribute when I click
                  >>save I get many many identical attributes:
                  >>myprocessor.p hp?id=3&item=co ke&id=4&item=0. ... I just get a
                  >>querystring with lots of blank variables. I know I must be doing
                  >>something to have this. All I really need is one ID. The ID from the
                  >>current area and that textbox only, but I can't since all the
                  >>generated elements are in between the same <formelement. Thank you.- Hide quoted text -
                  >- Show quoted text -
                  >
                  Thanks. I didn't know you could have more than one form on a page. I
                  guess that is from my .NET.
                  >
                  No, that's from the poor tools .NET has.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • jmDesktop

                    #10
                    Re: How do I parse form elements or am I doing this wrong?

                    On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                    jmDesktop wrote:
                    On Sep 13, 8:04 pm, "RootShell (IFReviews.org) "
                    <rootsh...@ifre views.orgwrote:
                    hello
                    >
                    Why not make a <FORMfor every area? that way you will only get a set
                    of values for that area.
                    >
                    For instance <FORM for beveragesand <FORM for grilleach with a
                    separate SUBMIT button?
                    >
                    why not use the POST method instead of the GET?
                    >
                    Why not use a special ID for each field (areas+menuitem s) ?
                    >
                    beverages
                       coffee
                    >
                    would be ID = 1-4
                    >
                    You would then explode the ID by the - and get area and menuitem
                    >
                    Maybe i'm getting wrongly what you ask, but it seems that it might work.
                    >
                    jmDesktop wrote:
                    >I have a food menu.  Each area, like beverages, grill, etc. have items
                    >under them, Coke, Tea, Coffee would be under beverages for example.
                    >I want to add a new drink to beverages.  In my database I have an
                    >"area" like above, Bevs, Grill, Chicken...  In my menu items I havean
                    >ID from the area so,
                    >table areas
                    >id 1 areaname beverages
                    >id 2 areaname grill
                    >table menuitems
                    >id 1 areaid 1 menuitem coke
                    >id 2 areaid 1 menuitem sprite
                    >id 3 areaid 2 menuitem hamburger
                    >Now, in my form, I have the entire menu displayed with all areas and
                    >menu items.  In each area there is small set of textboxes to enter new
                    >menuitems for that area with a button.  Messy yes, but what I can't
                    >figure out how to do is get the unique table area id for the new menu
                    >item because when the user clicks submit it doesn't just send the
                    >"name" across for that particular area addition.  it sends all the
                    >form elements over and since they are all named the same thing I have
                    >tons of them and I don't know how to get just that unique id.  I know
                    >I've lost you.  Let me try again.
                    >In the display I have beverages and right underneath it has a textbox
                    >for a new item and next to that a save button.  Underneath this I have
                    >grill and right underneath it has a textbox for a new itema and next
                    >to that a save button and so on with ever area.  These are generated
                    >by a set of loops from my database.
                    >Since all the textboxes have the same "name" attribute when I click
                    >save I get many many identical attributes:
                    >myprocessor.ph p?id=3&item=cok e&id=4&item=0.. ..  I just get a
                    >querystring with lots of blank variables.  I know I must be doing
                    >something to have this.  All I really need is one ID.  The ID from the
                    >current area and that textbox only, but I can't since all the
                    >generated elements are in between the same <formelement.  Thank you.- Hide quoted text -
                    - Show quoted text -
                    >
                    Thanks.  I didn't know you could have more than one form on a page.  I
                    guess that is from my .NET.
                    >
                    No, that's from the poor tools .NET has.
                    >
                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstuck...@attgl obal.net
                    =============== ===- Hide quoted text -
                    >
                    - Show quoted text -
                    How do I use the [] with a form element? thank you.

                    Comment

                    • Jeff

                      #11
                      Re: How do I parse form elements or am I doing this wrong?

                      jmDesktop wrote:
                      I have a food menu. Each area, like beverages, grill, etc. have items
                      under them, Coke, Tea, Coffee would be under beverages for example.
                      I'm confused by what you are doing but I think you have multiple rows
                      from your database and you want to update that.

                      You can use many forms as has been indicated, and update one row at a
                      time (a form for each row, with it's id).

                      Or if you need to update all of them, you can prepend the ID to the
                      form element name, such that:

                      my_form_name, with an id of 12
                      becomes:
                      12my_form_name

                      use a regex to parse out the id and field name.

                      /(\d*)(.*)/

                      That implies, of course, that you have an auto increment ID and no
                      starting number in your field name (IMHO, that's a good idea anyways).
                      Otherwise you'll need a different scheme.

                      I usually embed the id like that in a hidden field, parse out the ID
                      and then update that row (many fields) in one swoop and then all the rows:

                      // from something I wrote a few days ago

                      foreach($_POST as $item){

                      if(preg_match("/id_(.*)/",$item,$MATCHE S)){
                      $id_ = $MATCHES[1];

                      $sth->execute(array( $_POST[$id_ . 'some_field'],$_POST[$id_ .
                      'some_other_fie ld']...

                      YMMV. I'm sure there's many ways to do this.

                      Jeff




                      >
                      I want to add a new drink to beverages. In my database I have an
                      "area" like above, Bevs, Grill, Chicken... In my menu items I have an
                      ID from the area so,
                      >
                      table areas
                      id 1 areaname beverages
                      id 2 areaname grill
                      >
                      table menuitems
                      >
                      id 1 areaid 1 menuitem coke
                      id 2 areaid 1 menuitem sprite
                      id 3 areaid 2 menuitem hamburger
                      >
                      Now, in my form, I have the entire menu displayed with all areas and
                      menu items. In each area there is small set of textboxes to enter new
                      menuitems for that area with a button. Messy yes, but what I can't
                      figure out how to do is get the unique table area id for the new menu
                      item because when the user clicks submit it doesn't just send the
                      "name" across for that particular area addition. it sends all the
                      form elements over and since they are all named the same thing I have
                      tons of them and I don't know how to get just that unique id. I know
                      I've lost you. Let me try again.
                      >
                      In the display I have beverages and right underneath it has a textbox
                      for a new item and next to that a save button. Underneath this I have
                      grill and right underneath it has a textbox for a new itema and next
                      to that a save button and so on with ever area. These are generated
                      by a set of loops from my database.
                      >
                      Since all the textboxes have the same "name" attribute when I click
                      save I get many many identical attributes:
                      >
                      myprocessor.php ?id=3&item=coke &id=4&item=0... . I just get a
                      querystring with lots of blank variables. I know I must be doing
                      something to have this. All I really need is one ID. The ID from the
                      current area and that textbox only, but I can't since all the
                      generated elements are in between the same <formelement. Thank you.

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: How do I parse form elements or am I doing this wrong?

                        jmDesktop wrote:
                        On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                        >jmDesktop wrote:
                        >>On Sep 13, 8:04 pm, "RootShell (IFReviews.org) "
                        >><rootsh...@if reviews.orgwrot e:
                        >>>hello
                        >>>Why not make a <FORMfor every area? that way you will only get a set
                        >>>of values for that area.
                        >>>For instance <FORM for beveragesand <FORM for grilleach with a
                        >>>separate SUBMIT button?
                        >>>why not use the POST method instead of the GET?
                        >>>Why not use a special ID for each field (areas+menuitem s) ?
                        >>>beverages
                        >>> coffee
                        >>>would be ID = 1-4
                        >>>You would then explode the ID by the - and get area and menuitem
                        >>>Maybe i'm getting wrongly what you ask, but it seems that it might work.
                        >>>jmDesktop wrote:
                        >>>>I have a food menu. Each area, like beverages, grill, etc. have items
                        >>>>under them, Coke, Tea, Coffee would be under beverages for example.
                        >>>>I want to add a new drink to beverages. In my database I have an
                        >>>>"area" like above, Bevs, Grill, Chicken... In my menu items I have an
                        >>>>ID from the area so,
                        >>>>table areas
                        >>>>id 1 areaname beverages
                        >>>>id 2 areaname grill
                        >>>>table menuitems
                        >>>>id 1 areaid 1 menuitem coke
                        >>>>id 2 areaid 1 menuitem sprite
                        >>>>id 3 areaid 2 menuitem hamburger
                        >>>>Now, in my form, I have the entire menu displayed with all areas and
                        >>>>menu items. In each area there is small set of textboxes to enter new
                        >>>>menuitems for that area with a button. Messy yes, but what I can't
                        >>>>figure out how to do is get the unique table area id for the new menu
                        >>>>item because when the user clicks submit it doesn't just send the
                        >>>>"name" across for that particular area addition. it sends all the
                        >>>>form elements over and since they are all named the same thing I have
                        >>>>tons of them and I don't know how to get just that unique id. I know
                        >>>>I've lost you. Let me try again.
                        >>>>In the display I have beverages and right underneath it has a textbox
                        >>>>for a new item and next to that a save button. Underneath this I have
                        >>>>grill and right underneath it has a textbox for a new itema and next
                        >>>>to that a save button and so on with ever area. These are generated
                        >>>>by a set of loops from my database.
                        >>>>Since all the textboxes have the same "name" attribute when I click
                        >>>>save I get many many identical attributes:
                        >>>>myprocessor .php?id=3&item= coke&id=4&item= 0.... I just get a
                        >>>>querystri ng with lots of blank variables. I know I must be doing
                        >>>>something to have this. All I really need is one ID. The ID from the
                        >>>>current area and that textbox only, but I can't since all the
                        >>>>generated elements are in between the same <formelement. Thank you.- Hide quoted text -
                        >>>- Show quoted text -
                        >>Thanks. I didn't know you could have more than one form on a page. I
                        >>guess that is from my .NET.
                        >No, that's from the poor tools .NET has.
                        >>
                        >--
                        >============== ====
                        >Remove the "x" from my email address
                        >Jerry Stuckle
                        >JDS Computer Training Corp.
                        >jstuck...@attg lobal.net
                        >============== ====- Hide quoted text -
                        >>
                        >- Show quoted text -
                        >
                        How do I use the [] with a form element? thank you.
                        >
                        <input name="myval[]" ...>

                        This will create an array called myval as an element of the $_GET or
                        $_POST array, depending on whether your form method is get or post.

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • jmDesktop

                          #13
                          Re: How do I parse form elements or am I doing this wrong?

                          On Sep 15, 7:43 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                          jmDesktop wrote:
                          On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                          jmDesktop wrote:
                          >On Sep 13, 8:04 pm, "RootShell (IFReviews.org) "
                          ><rootsh...@ifr eviews.orgwrote :
                          >>hello
                          >>Why not make a <FORMfor every area? that way you will only get a set
                          >>of values for that area.
                          >>For instance <FORM for beveragesand <FORM for grilleach with a
                          >>separate SUBMIT button?
                          >>why not use the POST method instead of the GET?
                          >>Why not use a special ID for each field (areas+menuitem s) ?
                          >>beverages
                          >>   coffee
                          >>would be ID = 1-4
                          >>You would then explode the ID by the - and get area and menuitem
                          >>Maybe i'm getting wrongly what you ask, but it seems that it might work.
                          >>jmDesktop wrote:
                          >>>I have a food menu.  Each area, like beverages, grill, etc. have items
                          >>>under them, Coke, Tea, Coffee would be under beverages for example.
                          >>>I want to add a new drink to beverages.  In my database I have an
                          >>>"area" like above, Bevs, Grill, Chicken...  In my menu items I have an
                          >>>ID from the area so,
                          >>>table areas
                          >>>id 1 areaname beverages
                          >>>id 2 areaname grill
                          >>>table menuitems
                          >>>id 1 areaid 1 menuitem coke
                          >>>id 2 areaid 1 menuitem sprite
                          >>>id 3 areaid 2 menuitem hamburger
                          >>>Now, in my form, I have the entire menu displayed with all areas and
                          >>>menu items.  In each area there is small set of textboxes to enter new
                          >>>menuitems for that area with a button.  Messy yes, but what I can't
                          >>>figure out how to do is get the unique table area id for the new menu
                          >>>item because when the user clicks submit it doesn't just send the
                          >>>"name" across for that particular area addition.  it sends all the
                          >>>form elements over and since they are all named the same thing I have
                          >>>tons of them and I don't know how to get just that unique id.  I know
                          >>>I've lost you.  Let me try again.
                          >>>In the display I have beverages and right underneath it has a textbox
                          >>>for a new item and next to that a save button.  Underneath this Ihave
                          >>>grill and right underneath it has a textbox for a new itema and next
                          >>>to that a save button and so on with ever area.  These are generated
                          >>>by a set of loops from my database.
                          >>>Since all the textboxes have the same "name" attribute when I click
                          >>>save I get many many identical attributes:
                          >>>myprocessor. php?id=3&item=c oke&id=4&item=0 ....  I just get a
                          >>>querystrin g with lots of blank variables.  I know I must be doing
                          >>>something to have this.  All I really need is one ID.  The ID from the
                          >>>current area and that textbox only, but I can't since all the
                          >>>generated elements are in between the same <formelement.  Thankyou.- Hide quoted text -
                          >>- Show quoted text -
                          >Thanks.  I didn't know you could have more than one form on a page. I
                          >guess that is from my .NET.
                          No, that's from the poor tools .NET has.
                          >
                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstuck...@attgl obal.net
                          =============== ===- Hide quoted text -
                          >
                          - Show quoted text -
                          >
                          How do I use the  [] with a form element?  thank you.
                          >
                          <input name="myval[]" ...>
                          >
                          This will create an array called myval as an element of the $_GET or
                          $_POST array, depending on whether your form method is get or post.
                          >
                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstuck...@attgl obal.net
                          =============== ===- Hide quoted text -
                          >
                          - Show quoted text -
                          How do I know what to look for on the php side if they all have the
                          name myval[]?

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: How do I parse form elements or am I doing this wrong?

                            jmDesktop wrote:
                            On Sep 15, 7:43 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                            >jmDesktop wrote:
                            >>On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                            >>>jmDesktop wrote:
                            >>>>On Sep 13, 8:04 pm, "RootShell (IFReviews.org) "
                            >>>><rootsh...@ ifreviews.orgwr ote:
                            >>>>>hello
                            >>>>>Why not make a <FORMfor every area? that way you will only get a set
                            >>>>>of values for that area.
                            >>>>>For instance <FORM for beveragesand <FORM for grilleach with a
                            >>>>>separate SUBMIT button?
                            >>>>>why not use the POST method instead of the GET?
                            >>>>>Why not use a special ID for each field (areas+menuitem s) ?
                            >>>>>beverage s
                            >>>>> coffee
                            >>>>>would be ID = 1-4
                            >>>>>You would then explode the ID by the - and get area and menuitem
                            >>>>>Maybe i'm getting wrongly what you ask, but it seems that it might work.
                            >>>>>jmDeskto p wrote:
                            >>>>>>I have a food menu. Each area, like beverages, grill, etc. have items
                            >>>>>>under them, Coke, Tea, Coffee would be under beverages for example.
                            >>>>>>I want to add a new drink to beverages. In my database I have an
                            >>>>>>"area" like above, Bevs, Grill, Chicken... In my menu items I have an
                            >>>>>>ID from the area so,
                            >>>>>>table areas
                            >>>>>>id 1 areaname beverages
                            >>>>>>id 2 areaname grill
                            >>>>>>table menuitems
                            >>>>>>id 1 areaid 1 menuitem coke
                            >>>>>>id 2 areaid 1 menuitem sprite
                            >>>>>>id 3 areaid 2 menuitem hamburger
                            >>>>>>Now, in my form, I have the entire menu displayed with all areas and
                            >>>>>>menu items. In each area there is small set of textboxes to enter new
                            >>>>>>menuite ms for that area with a button. Messy yes, but what I can't
                            >>>>>>figure out how to do is get the unique table area id for the new menu
                            >>>>>>item because when the user clicks submit it doesn't just send the
                            >>>>>>"name" across for that particular area addition. it sends all the
                            >>>>>>form elements over and since they are all named the same thing I have
                            >>>>>>tons of them and I don't know how to get just that unique id. I know
                            >>>>>>I've lost you. Let me try again.
                            >>>>>>In the display I have beverages and right underneath it has a textbox
                            >>>>>>for a new item and next to that a save button. Underneath this I have
                            >>>>>>grill and right underneath it has a textbox for a new itema and next
                            >>>>>>to that a save button and so on with ever area. These are generated
                            >>>>>>by a set of loops from my database.
                            >>>>>>Since all the textboxes have the same "name" attribute when I click
                            >>>>>>save I get many many identical attributes:
                            >>>>>>myprocess or.php?id=3&ite m=coke&id=4&ite m=0.... I just get a
                            >>>>>>querystri ng with lots of blank variables. I know I must be doing
                            >>>>>>somethi ng to have this. All I really need is one ID. The ID from the
                            >>>>>>current area and that textbox only, but I can't since all the
                            >>>>>>generat ed elements are in between the same <formelement. Thank you.- Hide quoted text -
                            >>>>>- Show quoted text -
                            >>>>Thanks. I didn't know you could have more than one form on a page. I
                            >>>>guess that is from my .NET.
                            >>>No, that's from the poor tools .NET has.
                            >>>--
                            >>>============ ======
                            >>>Remove the "x" from my email address
                            >>>Jerry Stuckle
                            >>>JDS Computer Training Corp.
                            >>>jstuck...@at tglobal.net
                            >>>============ ======- Hide quoted text -
                            >>>- Show quoted text -
                            >>How do I use the [] with a form element? thank you.
                            ><input name="myval[]" ...>
                            >>
                            >This will create an array called myval as an element of the $_GET or
                            >$_POST array, depending on whether your form method is get or post.
                            >>
                            >--
                            >============== ====
                            >Remove the "x" from my email address
                            >Jerry Stuckle
                            >JDS Computer Training Corp.
                            >jstuck...@attg lobal.net
                            >============== ====- Hide quoted text -
                            >>
                            >- Show quoted text -
                            >
                            How do I know what to look for on the php side if they all have the
                            name myval[]?
                            >
                            It will be an array on the PHP side, i.e.

                            $_POST['myval'][0]
                            $_POST['myval'][1]
                            $_POST['myval'][2]

                            etc.

                            The value will be whatever the value of the element is, i.e. the value=
                            for a checkbox, and the text in an input field.

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • Jeff

                              #15
                              Re: How do I parse form elements or am I doing this wrong?

                              jmDesktop wrote:
                              On Sep 15, 7:43 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                              >jmDesktop wrote:
                              >>On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                              >>>jmDesktop wrote:
                              >>>>On Sep 13, 8:04 pm, "RootShell (IFReviews.org) "
                              >>>><rootsh...@ ifreviews.orgwr ote:
                              >>>>>hello
                              >>>>>Why not make a <FORMfor every area? that way you will only get a set
                              >>>>>of values for that area.
                              >>>>>For instance <FORM for beveragesand <FORM for grilleach with a
                              >>>>>separate SUBMIT button?
                              >>>>>why not use the POST method instead of the GET?
                              >>>>>Why not use a special ID for each field (areas+menuitem s) ?
                              >>>>>beverage s
                              >>>>> coffee
                              >>>>>would be ID = 1-4
                              >>>>>You would then explode the ID by the - and get area and menuitem
                              >>>>>Maybe i'm getting wrongly what you ask, but it seems that it might work.
                              >>>>>jmDeskto p wrote:
                              >>>>>>I have a food menu. Each area, like beverages, grill, etc. have items
                              >>>>>>under them, Coke, Tea, Coffee would be under beverages for example.
                              >>>>>>I want to add a new drink to beverages. In my database I have an
                              >>>>>>"area" like above, Bevs, Grill, Chicken... In my menu items I have an
                              >>>>>>ID from the area so,
                              >>>>>>table areas
                              >>>>>>id 1 areaname beverages
                              >>>>>>id 2 areaname grill
                              >>>>>>table menuitems
                              >>>>>>id 1 areaid 1 menuitem coke
                              >>>>>>id 2 areaid 1 menuitem sprite
                              >>>>>>id 3 areaid 2 menuitem hamburger
                              >>>>>>Now, in my form, I have the entire menu displayed with all areas and
                              >>>>>>menu items. In each area there is small set of textboxes to enter new
                              >>>>>>menuite ms for that area with a button. Messy yes, but what I can't
                              >>>>>>figure out how to do is get the unique table area id for the new menu
                              >>>>>>item because when the user clicks submit it doesn't just send the
                              >>>>>>"name" across for that particular area addition. it sends all the
                              >>>>>>form elements over and since they are all named the same thing I have
                              >>>>>>tons of them and I don't know how to get just that unique id. I know
                              >>>>>>I've lost you. Let me try again.
                              >>>>>>In the display I have beverages and right underneath it has a textbox
                              >>>>>>for a new item and next to that a save button. Underneath this I have
                              >>>>>>grill and right underneath it has a textbox for a new itema and next
                              >>>>>>to that a save button and so on with ever area. These are generated
                              >>>>>>by a set of loops from my database.
                              >>>>>>Since all the textboxes have the same "name" attribute when I click
                              >>>>>>save I get many many identical attributes:
                              >>>>>>myprocess or.php?id=3&ite m=coke&id=4&ite m=0.... I just get a
                              >>>>>>querystri ng with lots of blank variables. I know I must be doing
                              >>>>>>somethi ng to have this. All I really need is one ID. The ID from the
                              >>>>>>current area and that textbox only, but I can't since all the
                              >>>>>>generat ed elements are in between the same <formelement. Thank you.- Hide quoted text -
                              >>>>>- Show quoted text -
                              >>>>Thanks. I didn't know you could have more than one form on a page. I
                              >>>>guess that is from my .NET.
                              >>>No, that's from the poor tools .NET has.
                              >>>--
                              >>>============ ======
                              >>>Remove the "x" from my email address
                              >>>Jerry Stuckle
                              >>>JDS Computer Training Corp.
                              >>>jstuck...@at tglobal.net
                              >>>============ ======- Hide quoted text -
                              >>>- Show quoted text -
                              >>How do I use the [] with a form element? thank you.
                              ><input name="myval[]" ...>
                              >>
                              >This will create an array called myval as an element of the $_GET or
                              >$_POST array, depending on whether your form method is get or post.
                              >>
                              >--
                              >============== ====
                              >Remove the "x" from my email address
                              >Jerry Stuckle
                              >JDS Computer Training Corp.
                              >jstuck...@attg lobal.net
                              >============== ====- Hide quoted text -
                              >>
                              >- Show quoted text -
                              >
                              How do I know what to look for on the php side if they all have the
                              name myval[]?
                              To elaborate just a bit on this.

                              some_array[] just adds on to the end of the array. If you are familiar
                              with push from other languages, it does the same thing.

                              Jeff

                              Comment

                              Working...