Aleksei Sery
Aleksei Sery

Reputation: 5

Geting value from front end Joomla form?

I am just learning Joomla here and it seems that I just cant get it, looked though heaps of websites and still nothing. Can someone explain it to me. I have a form on front end component view:

<form method="post" name="adminForm" id="adminForm">
  <div class="btn-group pull-right">    
    <select name="category" id="category" class="input-medium" onchange="document.adminForm.submit()">    
      <option value="10"><?php echo '10 By';?></option>
      <option value="14"><?php echo '14 By';?></option>                 
    </select>
  </div>                
</form>

Now is this format even correct and how do I now get the option value in model of that view? I tried using:

$category = $mainframe->getUserState( "category", $default_category );

but it seem to not working and I am only getting $default_category value in there.

Any advice or maybe a short example will be much appreciated.

Thank you.

Upvotes: 0

Views: 261

Answers (1)

Ashwin Date
Ashwin Date

Reputation: 301

$category = $mainframe->getUserState( "category", $default_category );

This would work only if you have set the user state in the first place.

To get the values from a POSTed form you can use

$jinput = JFactory::getApplication()->input;
$category = $jinput->get('category', $default_category, 'int');

Suggest you read more about JInput here - JInput

Note that in a typical form saving scenario you won't need to separately get request variables using JInput, since the saving is handled by Joomla if you name your tables and form inputs correctly.

Upvotes: 2

Related Questions