Joomla在同一页面上处理多个Ajax表单 [英] Joomla handling multiple ajax forms on the same page

查看:151
本文介绍了Joomla在同一页面上处理多个Ajax表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Joomla开发一个带有AJAX的用户档案管理组件。



目标是允许用户编辑他自己的用户信息。有很多信息,所以我决定制作子表格或部分。并且为了方便用户使用,我希望通过AJAX发送表单并刷新用户信息。



以下是一个示例:



有两个部分,分别显示人的名字,姓氏和年龄的基本用户信息以及显示职业,公司和技能的扩展用户信息此人。每个部分都有一个编辑链接(或按钮),可将内容转换为允许用户修改呈现信息的表单(AJAX)。您一次只能编辑一个部分的信息。当用户完成修改数据时,他会发送带有发送链接(或按钮)的表单,并且该部分回到仅显示该部分的信息(包含刚创建的更新)。



所以我需要知道开发这种组件的最有效方法是什么。我想到了两种方法:
$ b $ 1)在主要组件视图的tmpl目录下,我们有以下文件:


  • default_basic.php (显示基本用户信息),
  • default_basic_edit.php (显示允许用户编辑基本信息的表单)

  • default_extended.php (显示扩展用户信息),
  • default_extended_edit.php (显示允许用户编辑扩展的表单info)加载每个显示子模板,调用 JView :: loadTemplate(


    当用户点击一个编辑链接时,AJAX调用遵循URI index.php?option = com_userinfo& view = userinfo& subview = basic_edit& format = ajax ,这会导致视图类调用 $ this - > loadTemplate( 'basic_edit')在分配用户信息之后。
    如果用户单击取消,则使用相同的过程再次加载基本模板。如果用户修改信息并点击发送链接,表单将被发送,然后'基本'模板也被加载。

    2)只有一个 tmpl目录下的default.php文件,其中包含编辑版本和每个版块的显示版本。但所有的编辑版本都是隐藏起来的。当用户点击编辑链接时,该部分的显示版本将隐藏,并显示编辑版本(使用display:none和display:block)。然后,如果用户点击取消按钮,我们会做相反的事情。如果用户点击发送按钮,我们发送一个AJAX请求来更新数据库中的数据,并返回更新后的用户信息,该信息将被加载到该部分的显示版本中。我们最终用其显示版本替换了该部分的编辑版本。



    我知道有很多文本,但最终还是要选择刷新完整的HTML使用AJAX块,或只发送更新的信息并修改隐藏块的内容,然后使其显示。那么,您认为最合理的方法是什么?知道我们处于Joomla 1.5环境中?你将如何继续? (也许还有其他的方法来创建这样的组件?)

    (我尝试了两种方法,但我不能完全使它工作,所以我决定询问是否这是一个概念问题......)

    感谢您花时间阅读所有文本。

    解决方案

    我已经尝试了两种解决方案,#2是唯一适用于我的解决方案。


    I'm using Joomla to develop a user profile management component with AJAX.

    The goal is to allow the user to edit his own user information. There is a lot of information so instead of having one massive form, I decided to make "subforms" or sections. And for the whole thing to be user-friendly I want to send the forms and refresh the user information with AJAX.

    Here's an example :

    There are two sections, "Basic user info" which displays the first name, the last name and the age of the person and "Extended user info" which displays the occupation, the company and the skills of the person. Each section has an "edit" link (or button) which turns the content into a form (AJAX) allowing the user to modify the presented information. You can only edit one section's information at a time. When the user has finished modifying the data, he sends the form with a "send" link (or button) and the section gets back to simply displaying the information of the section (with the updates that were just made).

    So I need to know what is the most efficient way to develop such a component. I thought of two approaches :

    1) In the "tmpl" directory of the main component view we the following files :

    • default_basic.php (displays the basic user information),
    • default_basic_edit.php (displays the form which allows the user to edit the basic information)
    • default_extended.php (displays the extended user information),
    • default_extended_edit.php (displays the form which allows the user to edit the extended info)
    • default.php (loads each of the display subtemplates with calls to JView::loadTemplate($subtemplate))

    When the user clicks on an edit link, an AJAX call is made to the following URI index.php?option=com_userinfo&view=userinfo&subview=basic_edit&format=ajax, which causes the view class to call $this->loadTemplate('basic_edit') after assigning the user information to it. If the user clicks cancel the same process is used to load the 'basic' template again. And if the user modifies the information and clicks the send link, the form is sent and then the 'basic' template is loaded too.

    2) There is only a "default.php" file in the "tmpl" directory which holds the edit version and the display version of each section. But all the edit versions are hidden at first. And when the user clicks on the edit link the display version of the section becomes hidden and the edit version is displayed (using display:none and display:block). Then, if the user clicks the cancel button we do the opposite. And if the user clicks the send button we send an AJAX request to update the data in the database and return the updated user info which will be loaded into the display version of the section. And we finally replace the edit version of the section with its display version.

    I know there's a lot of text but in the end it goes down to choosing between refreshing full HTML blocks with AJAX, or just sending the updated info and modifying the content of hidden blocks and then make them appear. So what do you think is the most logical approach, knowing that we are in a Joomla 1.5 environment ? How would you procede ? (maybe there are other ways to create such a component ?)

    (I tried both ways and I couldn't entirely make it work so I decided to ask to see if it is a matter of conception...)

    Thank you for taking the time to read all the text.

    解决方案

    I have tried both solutions and #2 is the only one that worked for me.

    这篇关于Joomla在同一页面上处理多个Ajax表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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