1

I have a very large webform that is the center of my Yii web application. The form actually consists of multiple html form elements, many of which are loaded via AJAX as needed.

Because of the form's size and complexity, having multiple save or submit buttons isn't really feasible. I would rather update each field in the database as it is edited by asynchrously AJAXing the new value to the server using jeditable or jeditable-like functionality.

Has anyone done anything like this? In theory I'm thinking I could set up an AJAX endpoint and have each control pass in its name, its new value, and the CRUD operation you want to perform. Then the endpoint can route the request appropriately based on some kind of map and return the product. It just seems like someone has to have solved this problem before and I don't want to waste hours reinventing the wheel.

Your thoughts on architecture/implementation are appreciated, thanks for your time.

4

2 回答 2

1

在类似的情况下,我决定使用CActiveForm仅用于 Yii 标准的简单验证(它可以使用 Ajax 验证),避免使用“ required”属性。当然,要保持表单的逻辑结构良好。

总的来说,你是对的。我手动使用 jQuery 向控制器生成 AJAX 请求(和任何其他操作),并根据需要在那里处理它们。

因此,您可以在控制器(分析请求中的参数)和自定义 jQuery(使用组选择器)中使用 CRUD,但您几乎不能CActiveForm直接在其中使用(这很好:压缩不一定总是击败模型的逻辑和结构) .

任何在 PHP 中使用 javascript 的复合解决方案都会影响您非平凡应用程序的灵活性。

于 2012-07-25T06:21:29.987 回答
0

昨晚睡了之后,我发现了这个帖子:

jQuery 聚焦/模糊表单,而不是单个输入

我在客户端使用它的修改版本通过 AJAX 更新每个表单,而不是更新每个字段。每个表单在两秒钟不活动后自动提交其数据。缺点是如果他们的浏览器崩溃,客户端可能会丢失一些数据,但好处是我可以主要使用 Yii 的内置控制器操作,我不必编写很多自定义 PHP。由于我的表格很小,但有很多,到目前为止它似乎运作良好。

感谢 Alexander 的出色投入,感谢 Afnan 的帮助 :)

于 2012-07-25T15:39:07.240 回答