Reputation: 1076
I built a custom component for Joomla 1.5. It' an FAQ component.
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.
So, how to build the front-end user input?
Maybe someone has done that or know some good tutorial for this case?
Upvotes: 0
Views: 837
Reputation: 8415
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. I build up a $html variable like:
$html .= '<input name="addQuestion" value="" type="Text"/>';
then add a reference to it:
$this->assignRef("addQuestion", $html);
so that in your view template (i.e. com_faq/views/tmpl/default.php) you can add it to your page like
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.
You will need to edit your router.php file to pick up the task and pass it to your controller i.e. set it as a task or a view.
There are loads of options for this but fundamentally there are 3 things you need:
Hope this helps :)
Upvotes: 1