我如何解析表单元素或我做错了什么? [英] How do I parse form elements or am I doing this wrong?

查看:59
本文介绍了我如何解析表单元素或我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有食物菜单。每个区域,如饮料,烧烤等,都有物品

,可乐,茶,咖啡等都是饮料。


我想要在饮料中加入新饮料。在我的数据库中,我有一个

" area"像上面一样,Bevs,Grill,Chicken ......在我的菜单项中,我有一个

来自该地区的ID,


桌面区域

id 1 areaname drinks

id 2 areaname grill


table menuitems


id 1 areaid 1 menuitem可乐

id 2 areaid 1 menuitem sprite

id 3 areaid 2 menuitem汉堡


现在,在我的表格中,我有整个菜单显示所有区域和

菜单项。在每个区域都有一小组文本框,可以通过按钮为该区域输入新的

菜单项。凌乱是的,但是我不能用b $ b来弄清楚如何做新菜单获得唯一的表区域ID

项目,因为当用户点击提交时并不只是发送

" name"为特定区域添加。它发送了所有的

表单元素,因为它们都被命名为同样的东西我有b
吨它们我不知道如何得到那个独特的ID。我知道

我失去了你。让我再试一次。


在显示屏上我有饮料,下面有一个文本框

表示新项目,旁边有一个保存按钮。在这下面我有一个烧烤,它下面有一个新文件盒,下一个

到一个保存按钮,依此类推。这些是由我的数据库中的一组循环生成的。


由于所有文本框都具有相同的名称。当我点击

保存属性时,我会得到许多相同的属性:

myprocessor.php?id = 3& item = coke& id = 4& item = 0 ....我只是得到一个带有大量空白变量的

查询字符串。我知道我一定要做点什么才能得到这个。我真正需要的只是一个ID。来自

当前区域和该文本框的ID,但我不能因为所有

生成的元素都位于相同的< formelement之间。谢谢。

解决方案

你好


为什么不为每个区域制作一个< FORM?这样你只能得到一个

的那个区域的值。


例如< FORM for formsand< FORM for grilleach with a br />
单独的SUBMIT按钮?


为什么不使用POST方法代替GET?


为什么不使用特殊的每个字段的ID(区域+菜单项)?


饮料

咖啡

将是ID = 1- 4


然后您将通过 - 并获取区域和菜单来爆炸ID


也许我错了你的要求,但似乎它可能会奏效。


jmDesktop写道:


我有食物菜单。每个区域,如饮料,烧烤等,都有物品

,可乐,茶,咖啡等都是饮料。


我想要在饮料中加入新饮料。在我的数据库中,我有一个

" area"像上面一样,Bevs,Grill,Chicken ......在我的菜单项中,我有一个

来自该地区的ID,


桌面区域

id 1 areaname drinks

id 2 areaname grill


table menuitems


id 1 areaid 1 menuitem可乐

id 2 areaid 1 menuitem sprite

id 3 areaid 2 menuitem汉堡


现在,在我的表格中,我有整个菜单显示所有区域和

菜单项。在每个区域都有一小组文本框,可以通过按钮为该区域输入新的

菜单项。凌乱是的,但是我不能用b $ b来弄清楚如何做新菜单获得唯一的表区域ID

项目,因为当用户点击提交时并不只是发送

" name"为特定区域添加。它发送了所有的

表单元素,因为它们都被命名为同样的东西我有b
吨它们我不知道如何得到那个独特的ID。我知道

我失去了你。让我再试一次。


在显示屏上我有饮料,下面有一个文本框

表示新项目,旁边有一个保存按钮。在这下面我有一个烧烤,它下面有一个新文件盒,下一个

到一个保存按钮,依此类推。这些是由我的数据库中的一组循环生成的。


由于所有文本框都具有相同的名称。当我点击

保存属性时,我会得到许多相同的属性:

myprocessor.php?id = 3& item = coke& id = 4& item = 0 ....我只是得到一个带有大量空白变量的

查询字符串。我知道我一定要做点什么才能得到这个。我真正需要的只是一个ID。来自

当前区域和该文本框的ID,但我不能因为所有

生成的元素都位于相同的< formelement之间。谢谢。


9月14日00:37,jmDesktop< needin4mat ... @ gmail.comwrote:


我有食物菜单。每个区域,如饮料,烧烤等,都有物品

,可乐,茶,咖啡等都是饮料。


我想要在饮料中加入新饮料。在我的数据库中,我有一个

" area"像上面一样,Bevs,Grill,Chicken ......在我的菜单项中,我有一个

来自该地区的ID,


桌面区域

id 1 areaname drinks

id 2 areaname grill


table menuitems


id 1 areaid 1 menuitem可乐

id 2 areaid 1 menuitem sprite

id 3 areaid 2 menuitem hamburger



< snip>


>

由于所有文本框都具有相同的名称当我点击

保存属性时,我得到许多相同的属性:



不要使用''name'' - 使用'' name []''和PHP将自动分配数组索引

。但是你需要做一些测试,如果比一个更多的话,你可以在多个领域添加一个。


C.
>


℃。 ( http://symcbean.blogspot.com/ )写道:
< blockquote class =post_quotes>
9月14日00:37,jmDesktop< needin4mat ... @ gmail.comwrote:


> I有食物菜单。每个区域,如饮料,烧烤等都有下面的物品,可乐,茶,咖啡等都是饮料。

我想在饮料中加入新饮料。在我的数据库中,我有一个
区域。像上面一样,Bevs,Grill,Chicken ...在我的菜单项中我有一个来自该地区的
ID,

表区域
id 1 areaname drinks
id 2 areaname grill




id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem汉堡包



< snip>


>由于所有文本框都具有相同的名称属性,当我点击
保存我得到许多相同的属性:



不要使用''name'' - 使用''name []' '和PHP将自动分配数组索引

。但是你需要做一些测试,如果更多的话,那么每次将多于一个的b $ b加到多个领域。


C.



或者,你可以做的是使用表格使用帖子,只需要在

上测试提交按钮的值。你可以将那些

sumbit按钮的值设为Add Beverage,Add Entree和Add Beree。那会告诉你

来自按下哪个按钮的区域。


因为你现在列出了一个很长的URL,你就是显然使用方法

get。您目前正在做什么来生成这么长的URL?

每个按钮都有一个非常长的onclick,每个字段

被类似

document.getElementById(''的东西填充the_name ''),价值吗?你是否使用javascript

函数来获取并构建该字符串,然后从

进行提交?如果其中任何一个,很容易限制网址,并在

接收脚本测试中查看哪些更改了。为什么,你甚至可以给b $ b添加一个导演。字段以指示此并打开该字段

通过

从URL中提取实际值

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.

解决方案

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.


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.


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


这篇关于我如何解析表单元素或我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆