Zend Forms识别 [英] Zend Forms identification

查看:84
本文介绍了Zend Forms识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能识别Zend Forms?,我在官方文档中找不到它!!!

例如在控制器中我们有2个表单,我们如何找到它是否已提交?

解决方案

好了,提交按钮保持一个值,当你按下提交按钮时,除了其他提交按钮之外,所有输入字段值都将被发送。



例子

< form> 
< INPUT name ='me'>
< INPUT type ='submit'value ='data1'name ='ae'>
< INPUT type ='submit'value ='data2'name ='fe'>
< / form>





如果按data1,收到的查询将是

? me =& ae = data1

如果你按数据2然后收到的查询将是

?me =& fe = data2



使用isset函数可以验证已经请求了哪个提交。



如果它们是两个完全不同的表单,只需添加两个不同的隐藏字段。


请参阅我对该问题的评论。它似乎没有多大意义。但是,如果你了解事情是如何运作的,你将能够决定你想做什么。



你在官方文件中找不到它,因为没有一个是要写一个关于这个奇怪主题的文档部分。这样的话题实际上并不存在,只是因为本身没有这样的问题,人们对事物的运作方式有了一般性的了解(当然还有很好的记录),加上一些简单的逻辑。让我们遵循这样的逻辑。



原因如下:通常情况下,如果你有不同的表格,他们通常会有不同的属性值 action 代表一些网址;通过此URL,您向某个表单处理代理发送HTTP请求:

请参阅:

http://www.w3.org/TR/html4/interact/forms.html [ ^ ],

http://www.w3.org/TR/html4/interact/forms.html#adef-action [ ^ ]。



此外,通常,此URL与表单的URL相同。代理程序代码检测是否发布了某些内容,并在其HTTP响应中生成稍微不同的页面,以显示输入数据,验证结果,或者只是向用户说谢谢您的信息。



但是,想象一下,由于一个或另一个原因,您仍然需要具有两个具有相同 action 属性值的表单。但它如何可能产生识别它的问题呢?请记住,表格显然是不同。您无法事先知道表单中填写的数据,以便在PHP代理程序代码中考虑它。但是,您确切知道什么是元数据,它由表单控件及其名称属性表示。如果您使用表单,您应该知道它是 name 属性,该属性是在表单提交后写入HTTP请求正文中的:

http://www.w3.org/TR/html4/interact/forms.html#控制名称 [ ^ ]。



如果表格确实不同,至少其控件的某些名称应该是不同的。我甚至要解释原因吗?那么,因为如果它们是相同的,那么从加工代理的角度来看,形式是相同的,没有区别,即使它们实际上是不同的元素。您的PHP(或任何其他)处理代理程序代码只接收HTTP请求文本,没有别的。



如果某些名称不同,您可以看到它的形式。如您所知,PHP通过PHP数组(关联容器,基本上)


_POST 访问HTTP请求参数。该数组由字符串键索引,这些键是相同的名称。如果表单中没有某个名称,则数组中不会出现相同值的键,您可以使用函数 isset 进行检查。例如,在此处对此进行了演示:

http ://www.html-form-guide.com/php-form/php-form-post.html [ ^ ]。



-SA

How can I identificate Zend Forms?, I can't find it in official documentation!!!
For example in controller we have 2 forms, how we can find out with is submited?

解决方案

Well, the submit button hold a value, when you press a submit button all the input filed value will be send except other submit button.

example

<form >
	<INPUT name='me'>
	<INPUT type='submit' value='data1' name='ae'>
	<INPUT type='submit' value='data2' name='fe'>
</form>



if you press data1 the received query would be
?me=&ae=data1
if you press data2 then the received query would be
?me=&fe=data2

with isset function you can verify which submit has been requested.

And if they are two complete different form just add two different hidden field.


Please see my comment to the question. It does not seem to make a whole lot of sense. However, if you understand how things work, you will be able to decide what you want to do.

You could not find it in "official documentation", because no one is going to write a documentation section on such a weird topic. Such topic does not actually exist, just because there is no such problem per se, there is general understanding of how things work (well documented, of course), plus some simple logic. Let's follow such logic.

Here is why: Normally, if you have different forms, they usually have different values of the attribute action which represent some URL; through this URL you send an HTTP request to some form processing agent:
Please see:
http://www.w3.org/TR/html4/interact/forms.html[^],
http://www.w3.org/TR/html4/interact/forms.html#adef-action[^].

Moreover, very typically, this URL is the same as the URL of the form. The agent code detects if something was posted and generate somewhat different page in its HTTP response, to show input data, validation results, or just to say "thank you for your information" to the user.

Imagine however, that you still need to have two form with identical values of the action attribute, by one or another reason. But how it possibly create a problem of "identification" of it? Remember that the forms are, apparently, different. You cannot know in advance what would be the data filled in the form, to take it into account in your PHP agent code. However, you know exactly what will be metadata, which is represented by form controls and their name attributes. If you use forms, you should know that it's the name attribute which is written in the body of HTTP request as a result of form submission:
http://www.w3.org/TR/html4/interact/forms.html#control-name[^].

And if the forms are really different, at least some of the names of their controls should be different. Do I even have to explain why? Well, because if they are identical, the forms, from the standpoint of the processing agent, are identical, not different, even if they are actually different elements. You PHP (or any other) processing agent code only receives HTTP request text, nothing else.

And if some names are different, you can see which form it that. As you should know, PHP gets access to HTTP request parameters via the PHP array (associative container, essentially)


_POST. The array is indexed by the strings keys which are the same very names. If some name is not present in the form, the key of the same value does not present in the array, which you can check up using the function isset. This is demonstrated, for example, here:
http://www.html-form-guide.com/php-form/php-form-post.html[^].

—SA


这篇关于Zend Forms识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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