问题标签 [symfony-forms]

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 回答
284 浏览

symfony1 - 在 symfony 中重用动作

假设我们有一个 Article 模型和一个 Comment 模型。

我们基于“文章”和“评论”路由集合生成 2 个模型:

所以,我们基本上每个模型都有 2 个 crud。现在,在文章的显示操作中,我想显示一篇文章,它的相关评论和添加评论的表单。

问题是如何在文章/显示操作中发布评论时重用评论/新建和评论/创建操作?这是组织代码的正确方法吗?

0 投票
2 回答
3329 浏览

symfony1 - Symfony - 重定向到填写表单值的操作

如何重定向到另一个操作,并在新操作中填写表单字段?

我有一个动作,我想调用 redirect() 类似的东西:

哪个应该重定向到我的 Search 操作,并且该操作中的表单应该填写 last_name 参数。该操作的代码如下:

SearchForm 的名称格式为“Search[%s]”。

我为重定向()的参数所做的任何尝试都没有奏效。Search[] 参数总是以某种方式弄乱,并且不会填充表单。

0 投票
1 回答
1308 浏览

symfony1 - 使用 Symfony 验证上传的文件扩展名?

我想阻止用户上传具有某些扩展名的文件。首先想到的是像这样使用 sfValidatorRegex:

但是,这不起作用,因为 sfValidatorRegex::doClean($value) 获取的是 sfValidatedFile 的实例,而不是文件名。

UPD:很抱歉让你们感到困惑,我真的想验证扩展名,而不是文件类型。

0 投票
1 回答
890 浏览

symfony1 - How do i filter and validate form fields in symfony 1.4?

Im trying to integrate a content filtering API. My plan was to use pre/post validators but I've lost may way somehow.

What i need to do is send the values to the content filtering service. If the response comes back that the content has been filtered it will also return a modified value for the field (basic profanity filtering... matches are replace with asterisks). Thats all well and good i can throw validation errors no problem - simple stuff.

However i dont want just throw errors. What needs to happen is that validation errors are thrown as normal, but the values are modified in the form for re-display.

Basically if someone posts something naughty i want them to get a validation error saying their post has been modified, they can re-submit the now "clean" post, or they can go about editing it to make it clean without the word replacements.

But do clean on a validator either throws an error OR returns cleaned values, not both. How can i go about implementing both? This will be used on many different forms with many different field names, so modifying methods on the form or a form base class isnt really an option - it needs to happen in the validation sub-framework somehow.

0 投票
1 回答
357 浏览

php - 用对象填充自定义表单

我有一个简单的表格:UserInfoForm()。当我第一次向用户显示表单时,我希望它填充来自User模型的特定对象的数据。谁能给我一个方向或一个例子?谢谢!

0 投票
2 回答
777 浏览

symfony1 - Symfony 1.4:基于 cookie 隐藏小部件及其验证器?

在我的网站上,我使用用于添加评论的表单中的 ReCaptcha 小部件。正确发送表单后,我将 cookie 写入用户的计算机。

当用户拥有该 cookie 时,我想删除 ReCaptcha 小部件,以便回访者不必输入验证码。我可以这样做forms/commentForm.class.php,还是需要创建一个新表单?

0 投票
1 回答
1197 浏览

symfony1 - Symfony 表单小部件自定义渲染

我正在寻找一种将表单输出自动化为 json 格式而不是 html 的方法。我正在使用 JQuery dform http://plugins.jquery.com/project/dform创建动态表单。

样本输出:

{ "type" : "p", "html" : "你必须登录" }, { "name" : "username", "id" : "txt-username", "caption" : "Username", "type" :“文本”,“占位符”:“例如 user@example.com”},{“名称”:“密码”,“标题”:“密码”,“类型”:“密码”},{“类型”: “提交”,“价值”:“登录”}

请帮忙

0 投票
2 回答
3135 浏览

php - 形式上的一对一关联?

在 symfony 2.0 中,如何在表单中使用一对一关联创建下拉列表?请大家举个例子好吗?

0 投票
0 回答
120 浏览

php - Symfony:模型问题

我正在接管一个旧的 Symfony 1.1 项目,当我向 schema.yml 添加一个属性并运行 symfony propel:build-all 时,一切似乎都正常。但是,当我转到已经制作(并且以前工作过)的表格之一时,它们不再起作用。他们有这样的代码:

echo $form['SOMEPROPERTY']->renderError()

然后,在使用表单加载页面时出现“小部件“SOMEPROPERTY”不存在”错误。

当我尝试检查Base[MyModel]Form.class.php, "someproperty"时(用小写字母写):'someproperty' => new sfWidgetFormInput().

所以我应该纠正$form['SOMEPROPERTY']小写($form['someproperty'])?不行,真的不行。当然,我没有收到错误,但现在表单不会使用数据库中的数据预填充输入字段(这是一个可以编辑现有行的表单)。

有任何想法吗?

0 投票
2 回答
1343 浏览

symfony1 - 如何在 Symfony 1.4 中显示的表单中访问相关对象

我需要显示一个表单以在显示新闻故事的同一页面上输入博客文章。用户正在输入与故事相关的博客文章。

在我的博客表单中,我目前正在这样做以获取正在显示的故事的 ID:

有更清洁的方法吗?从请求参数中获取通知(新闻故事)的 id 感觉很奇怪。

更新

我实际上是通过 ajax 从模态对话框中发布表单,并尝试在请求之间维护 notice_id 值。在返回表单以显示错误之前,我将参数与表单绑定:

我似乎无法让 notice_id 与表单绑定(它是一个隐藏字段)。其他值绑定良好。

进一步更新

在第一次通过表单配置方法时,依赖于请求中的 notice_id,我认为当通过 ajax 再次创建表单时将其设置为 null。这修复了它:

如果有人有更清洁的方法,请告诉我。