Kilizo
Kilizo

Reputation: 3392

Custom Form in Custom Joomla Component

I have a basic front-end form within a component that I created using ComponentCreator.

How and where do I direct the form "action"? Where can I handle this so that I am following the MVC design pattern? My form is within a view (default.php)

The form should simply insert to the database upon submission. I don't want to use a form building extension, I have tried these and they don't meet my requirements.

Upvotes: 1

Views: 1330

Answers (1)

Tom
Tom

Reputation: 2634

What version of Joomla? Assuming your not using AJAX then just direct to your controller.

<form id='MyForm' method='post' action='index.php?option=com_mycomponent&task=myoperation'>
<input type='text' name='myname'/>
...</form>

Then you will have a function in your controller (controller.php) called myoperation that will process all the things in your form (not forgetting the token of course)

JSession::checkToken('request') or jexit( JText::_( 'JINVALID_TOKEN' ) );
$jinput = JFactory::getApplication()->input;
$add_name = $jinput->get('myname', '', 'STRING');
//whatever you need to do...
//add to model if you wanted to add name to DB
$model = &$this->getModel();
$model->updateDB(...);

Then create function updateDB in model.

This is a rough example with Joomla 2.5 but should work with 3.x. Hope this helps.

Upvotes: 4

Related Questions