简体   繁体   English

Joomla 1.5前端用户将内容添加到自定义组件中

[英]Joomla 1.5 Front End user add content into custom component

I built a custom component for Joomla 1.5. 我为Joomla 1.5构建了一个自定义组件。 It' an FAQ component. 这是一个FAQ组件。

I'd like to let users add questions from the Front-End. 我想让用户从前端添加问题。

I have several fields that shouldn't be displayed for the user on the front end. 我有几个字段不应该在前端为用户显示。

For ex. 对于前。 in the back-end admin has fields like Approved, Ordering and Published and the rest. 后端管理员中的字段具有“已批准”,“订购”和“已发布”等字段。 I would like to let any user without signing in to add question front the front-end but these 3 fields shouldn't be displayed to the users on the front-end. 我想让任何用户都无需登录即可在前端添加问题,但是这3个字段不应在前端显示给用户。

So, how to build the front-end user input? 那么,如何构建前端用户输入呢?

Maybe someone has done that or know some good tutorial for this case? 也许有人这样做了,或者知道一些适用于这种情况的好教程?

In the view.html.php file of your component (eg. com_faq/views/view.html.php) you can define the mark up for your input field section. 在您组件的view.html.php文件(例如com_faq / views / view.html.php)中,您可以定义输入字段部分的标记。 I build up a $html variable like: 我建立了一个$ html变量,如:

$html .= '<input name="addQuestion" value="" type="Text"/>';

then add a reference to it: 然后添加对它的引用:

$this->assignRef("addQuestion", $html);

so that in your view template (ie com_faq/views/tmpl/default.php) you can add it to your page like 这样您就可以在视图模板(即com_faq / views / tmpl / default.php)中将其添加到页面中,例如

echo $this->addQuestion;

When you click your submit button you can reroute back to the same view. 单击提交按钮时,您可以重新路由回同一视图。 So user a url like 因此,用户使用类似

index.php?option=com_faq&task=addQuestion&view=default

So before you mark up your page (so within the first few lines of your display function for example) you can grab the contents of your user's input on the front end 因此,在标记页面之前(例如,在显示功能的前几行之内),您可以在前端获取用户输入的内容

$question = JRequest::getVar('addRequest', null);

Once you have this you can either store it to your database or display it. 一旦有了它,您既可以将其存储到数据库中,也可以显示它。 Alternatively you can AJAX submit your form and process it in a controller function so the you don't have the refresh etc. 另外,您也可以AJAX提交表单并在控制器函数中进行处理,以免刷新等。

You will need to edit your router.php file to pick up the task and pass it to your controller ie set it as a task or a view. 您将需要编辑router.php文件以选择任务并将其传递给控制器​​,即将其设置为任务或视图。

There are loads of options for this but fundamentally there are 3 things you need: 有很多选择,但是从根本上讲,您需要三件事:

  1. Create your mark up in your view.html.php file and assign a reference to it 在view.html.php文件中创建标记,并为其分配引用
  2. Include the reference in your template ie default.php 在模板中包含引用,即default.php
  3. Submit your form to an address that your same component can process it ie index.php?option=com_faq&task=addQuestion&view=default 将表单提交到您的相同组件可以处理的地址,即index.php?option = com_faq&task = addQuestion&view = default

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM