问题标签 [zend-form2]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1299 浏览

php - Zf2 Callback Validator not passing all form values

Currently setting up a form using ZF2. I'd like to be able to setup validation for the form based on comparing the values of 2 different elements on the form. Where in the past I've used the Callback validator to pass in all of the forms values, it seems in my current scenario I can only get the value of the element being validated.

Here is how I setup my form

The problem is that currently var_dump(func_get_args()) is currently only returning:

In the past I would have expected this to also pass in the purchase_date value as a part of the second argument of the callback.

Has anyone experienced this problem before? I'm using the callback function as expected in other areas of my application but can't seem to get it working here.

Thanks in advance

For clarification(although I don't believe it will have any effect on validation), the function $this->addElement is my own function, held on a trait and is simply:

0 投票
1 回答
1743 浏览

php - Zend Framework 2 - 处理表单动作

在 Zend Framework 2 中,我创建了一个扩展Zend\Form\Form名为MyForm.

indexAction一个 Controller 类中,我将MyForm这样初始化:

然后在对应的视图中,我基本上只是做

这一切都有效,但您可能已经注意到表单的操作丢失了。

我试图在视图中添加这样的操作:

然后在我的 IndexController 中的 go 操作中,我只有这个用于测试:

这根本不起作用,我总是再次进入表单视图(==索引操作)。为什么 go 动作从不执行?

我也知道我可以硬编码 action 属性并让段路由处理处理,或者我什至可以为此定义一个自己的路由。

在什么情况下表单动作应该有自己的路线?
在什么情况下应该使用分段路由来处理表单操作?
在什么情况下应该像我的示例一样处理表单操作?

如果对此没有硬性规定:不同方法传达的意图是什么?

是否也可以在控制器而不是视图中添加表单操作?

0 投票
1 回答
659 浏览

php - Zend Framework 2:如何标记表单无效?

在 ZF1 中,可以使用以下代码将表单标记为无效:

我如何在 ZF2 中做到这一点?我试过了

但它不会使表格无效。

0 投票
3 回答
1833 浏览

forms - 在 ZF2 (v2.3.3) 中包含和使用 Zend Service ReCaptcha

如何在 zend 框架 2 中包含 Recaptcha 服务?

我试着这样做:

但是我发现下载框架时 ZendService\ReCaptcha 默认不存在。所以,我从这里下载了它 https://github.com/zendframework/ZendService_ReCaptcha

我把它和vendor\zendframework\zendframework\library\zend图书馆的其他部分放在一起。

我尝试刷新页面,但由于找不到 zend 服务重新验证,因此无法再次工作。

有人能帮我吗?我认为实施 recaptcha 很简单,但事实并非如此!谢谢!

0 投票
1 回答
474 浏览

doctrine-orm - Doctrine 2: Form field shows Doctrine\Common\Collections\ArrayCollection@00 as value

I am pretty new to Zend Framework 2 and Doctrine 2, so I am not even sure how to search or debug my problem.

I have 3 database tables

1. advert
id
adverttitle ...

2. category
id
categoryname ...

3. advert_category
advert_id
category_id

I have created 2 Entities, Advert and Category. I have now got a Form where I show the Categories to choose from. I use jQuery to display the categories as a list instead of a dropdown, together with a selectable function. So when you click on a category, the value of this listelement gets entered into a hidden input field called categories.

Everything works fine, besides that when I display the form, the hidden categories input field got a value of Doctrine\Common\Collections\ArrayCollection@000000000..... instead of being empty. What am I doing wrong here? I have tried to find a solution, but unsuccessfully.

I have chosen a ManyToMany Relationship because I want to be able to save more then 1 category in the end. Currently it is only working with 1, but this way I should be able to change this at a later time.

Here my Advert entity:

Is there an Error in the Advert Entity which causes this? I hope someone can help. I have this problems since weeks and can not get it to work correctly.

UPDATE -- added my Form and part in controller to call form

The below Form displays 2 Dropdown Elements and 2 Hidden Input Fields. The 2 Dropdown Fields get turned into a selectable List via jQuery. When you click on a List Element from the Maincategory, the Subcategories show up for that chosen Maincategory again as a selectable list. The MaincategoryID gets then entered into the hidden categoryID Field. As soon you choose the Subcategory from the List, the id of that category gets written in the hidden categories field. A click on the "next" button saves the value of $_POST['categories'] together with the advertID in my linking table.

In my Controller I call my form the following way:

0 投票
0 回答
117 浏览

php - ZF2 表单集合 - 将集合用于 Doctrine 类型“数组”

我被ZF2卡住了!我正在尝试在我的表单上添加一个 Collection 元素,以显示存储在我的 Doctrine 实体中的一个简单“数组”中的电话号码数组。

我想知道在不使用 Fieldset 的情况下让我的价值观与 Doctrine 一起工作的正确方法是什么,因为它只需要一个字段(电话号码)。

我尝试了很多东西,但没有任何效果。如果有人做过,请告诉我!

0 投票
0 回答
194 浏览

doctrine-orm - 在 ZF2 中以不同的形式重用表单的相同部分

我的许多表单都有相同的字段,但这些字段不是单独的实体。我想要一些Base我可以以各种形式重复使用的东西。我尝试使用字段集,但所有示例都建议使用字段集的实体。如果我使用如下字段集,则填充字段集,但表单的其余部分不会绑定到实体字段。

BaseSF(它将有更多的共享字段)

身份信息表

编辑 1

我有学生在实习期间练习不同的技能。他们获得讲师的评分,并为自己的每项技能分配一个评分。每个技能也有示例(从 db 加载的工具提示文本)。所有这些表单元素对于每个技能都是相同的。有时我需要更改(例如添加 css 类)一个元素(例如讲师等级),并且我想避免遍历每种形式的每个元素。

表单示例,其中一种表单如下所示:

applJusticeFIGrade 和engageJusticeFIGrade 是相同类型的字段 - 讲师等级。我尝试将 FieldSet 用于 applJusticeFIGrade (我尝试了一个等级,记住我会找到一种方法来提供名称作为 fieldset 内的 select 元素的参数):

Instructor Grade 字段显示在视图中,但 Doctrine 无法从数据库中分配值(我留下注释掉的代码只是为了显示我已经尝试过的变体):

0 投票
1 回答
283 浏览

php - ZF2:我可以将文本框附加到多选框吗?如何使用 ZF2 中的 MultiCheckbox 或复选框组创建文本框字段,如“其他”或“评论”?

我正在关注此示例,但我需要在“其他”选项中添加一个额外的文本框,该选项在单击“其他”复选框时被激活。我可以在表单中添加一个单独的文本框,并通过 JS 代码启用它,但是如何将它与 MultiCheckbox 的值或特定 target_class 的特定属性的复选框组组合在一起?

形式

实体

0 投票
1 回答
1157 浏览

zend-framework2 - Zend Framework 2 - InputFilter 添加 InputFilter

我写了一些输入过滤器。现在我想用其中的几个过滤并验证一个表单。所以我想我可以写一个新的 InputFilter 在构造函数中添加我需要的所有其他内容并将这个新的设置为表单,但它不起作用^^这是我的代码:

示例 InputFilter


我的配置:


我的工厂:


RegisterInputFilter(在这里我想添加我需要的所有表单):


现在将过滤器添加到我的 registercontroller 中的表单中:



当我直接将 myEmailFilter 添加到表单时,它可以工作,如果我添加 registerfilter,我会遇到异常

[[附加信息]]:Zend\InputFilter\Exception\InvalidArgumentException [[文件]]:/home/vagrant/project/vendor/zendframework/zendframework/library/Zend/InputFilter/BaseInputFilter.php:137 [[消息]]: Zend\InputFilter\BaseInputFilter::setData 需要一个数组或 Traversable 参数;收到的字符串 [[堆栈跟踪]]: #0 /home/vagrant/project/vendor/zendframework/zendframework/library/Zend/InputFilter/BaseInputFilter.php(535): Zend\InputFilter\BaseInputFilter->setData('') # 1 /home/vagrant/project/vendor/zendframework/zendframework/library/Zend/InputFilter/BaseInputFilter.php(147): Zend\InputFilter\BaseInputFilter->populate() #2 /home/vagrant/project/vendor/zendframework/ zendframework/library/Zend/Form/Form.php(467): Zend\InputFilter\BaseInputFilter->


如何以正确的方式堆叠单个过滤器?认为 add() 函数也接受 InputFilters 但它看起来像。

谢谢帮助:-)

0 投票
3 回答
136 浏览

zend-framework2 - 如何使 MultiCheckBox 标签加粗或加粗?

我有以下多选框:

如何使以下部分加粗?使用 label_attributes 使所有标签变为粗体,我只希望 multibox 的主标签为粗体。

编辑 1:将 label_attributes 添加到“选项”

当我按照@itrascastro 的建议添加 label_attributes 时,所有标签都变为粗体,我只希望顶部的标签变为粗体:multicheckbox