dongliao8069 2014-02-12 10:30 采纳率: 0%
浏览 32
已采纳

从前端Joomla形式获得价值?

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.

  • 写回答

1条回答 默认 最新

  • doushan5245 2014-02-12 11:43
    关注
    $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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?