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

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

P: n/a
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.
Sep 13 '08 #1
Share this Question
Share on Google+
14 Replies


P: n/a
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+menuitems) ?

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.
Sep 14 '08 #2

P: n/a
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.
Sep 14 '08 #3

P: n/a
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.getElementById('the_name'),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.

Sep 14 '08 #4

P: n/a
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.getElementById('the_name'),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.
Sep 14 '08 #5

P: n/a
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_beverage", "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.
js*******@attglobal.net
==================

Sep 14 '08 #6

P: n/a
On Sep 14, 6:59*am, "C. (http://symcbean.blogspot.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.
Sep 15 '08 #7

P: n/a
On Sep 13, 8:04*pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.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+menuitems) ?

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.
Sep 15 '08 #8

P: n/a
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.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+menuitems) ?

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.
No, that's from the poor tools .NET has.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 15 '08 #9

P: n/a
On Sep 15, 9:23*am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.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+menuitems) ?
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.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.

No, that's from the poor tools .NET has.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
How do I use the [] with a form element? thank you.
Sep 15 '08 #10

P: n/a
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,$MATCHES)){
$id_ = $MATCHES[1];

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

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.
Sep 15 '08 #11

P: n/a
jmDesktop wrote:
On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.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+menuitems) ?
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.
No, that's from the poor tools .NET has.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.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.
js*******@attglobal.net
==================

Sep 15 '08 #12

P: n/a
On Sep 15, 7:43*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.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+menuitems) ?
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=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. *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...@attglobal.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...@attglobal.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[]?
Sep 16 '08 #13

P: n/a
jmDesktop wrote:
On Sep 15, 7:43 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.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+menuitems) ?
>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.
No, that's from the poor tools .NET has.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.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...@attglobal.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.
js*******@attglobal.net
==================

Sep 16 '08 #14

P: n/a
jmDesktop wrote:
On Sep 15, 7:43 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.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+menuitems) ?
>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.
No, that's from the poor tools .NET has.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.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...@attglobal.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
Sep 16 '08 #15

This discussion thread is closed

Replies have been disabled for this discussion.