[英]Adding a Text Form to Component View Joomla 3
我正在组件视图上创建一个简单的提交表单。 这是设置:
<?php
// no direct access
defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
$jinput = JFactory::getApplication()->input;
$newValue = $jinput->get('newValueSubmit');
?>
这是我在视图中创建的表单:
<div style="position:relative; top:173px; left:357px;">
<label for="newValue" class="col-sm-2 control-label"><h1>Enter</h1></label>
</div>
<div class="form-group" style="position:relative; top:120px; height:350px; width:950px; left:450px;">
<div style="position:relative; left:120px; width:950px;>
<form class="form-horizontal" role="form" action="<?php echo JURI::current(); ?>" method="post">
<input id="newValueSubmit" name="newValueSubmit" type="text" class="form-control input-lg text-success" placeholder="Value"/>
<button id="submit" type="submit" name="submit" class="btn btn-primary btn-large">Submit</button>
</div>
</div>
</form>
</div>
<?
$data =new stdClass();
$data->id = '';
$data->request = $newValue;
JFactory::getDbo()->insertObject('#__mytable', $data);
?>
因此,我的尝试是让用户在文本字段中输入一个值,然后单击“提交”按钮以将其发布到结果中。 然后将该值放置在newValue
列条目的'#__mytable'
位置。 这是行不通的。
必须有更好的方法来做到这一点。 我是否需要创建一个新的视图,以便表单将值定向到? 考虑到整个项目的架构,这可能是更好的选择。 无论哪种方式,如何将用户提交的值保存到数据库中?
更新:我已经更新了脚本,以包括最近的更改建议。
更新:由于Joomla 3,更新了对Jinput的请求
尝试这样的事情:
$newValue = JRequest::getVar('newValue');
$data =new stdClass();
$data->id = '';
$data->newvalue = $newValue;
JFactory::getDbo()->insertObject('#__mytable', $data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.