我在处理使用 codeigniter 创建的表单时遇到问题。我尝试了多种在网页上呈现表单的方法。但是在不同的点上我都不成功。
我正在寻找渲染这个
我试图用代码渲染一个表单:
<?php $this -> load -> helper('form');
$formattr = array('id="form1"');
form_open('registerUsr', $formattr);?>
<fieldset>
<legend>Registration Form</legend>
<p class="first">
<label for="firstName">First Name: </label>
<input type="text" id="name" name="firstName" size="20" value="<?php echo set_value('first_name'); ?>" />
</p>
</fieldset>
<p class="submit"><button type="submit" value="Submit" /></p>
<?php echo form_close(); ?>
我尝试使用 codeigniter 函数创建它
<?php echo form_open('registerUsr');
echo form_input('$data');
echo form_submit('submit', 'Submit');
echo form_close();?>
我尝试了混合使用 html 标签和辅助类函数的混合品种。
但在所有方面,最终呈现网页上的表单<form class=“form1”>
标签都丢失了。它也不是 index.php/registerUsr,而是进入 index.php/searchUniv 页面。(我已经检查了路线配置文件。它被正确指出)
任何建议/想法表示赞赏。
蒂亚:)
更新:这是控制器和路由文件
public function registration() {
$this -> template -> title -> set('Register');
$this -> template -> _content -> view('register_index', $overwrite = TRUE);
$this -> template -> _sidebar -> view('gen_sidebar', $overwrite = TRUE);
$this -> template -> publish();
}
public function registerUsr(){
$this -> template -> title -> set('Register');
$searchItem = $this -> input -> post('form1');
$this -> template -> publish();
}
}
register_index.php 是问题中的代码,现在看起来还可以。
$route['searchUniv']="sglobal/searchUniv";
$route['registration']="sglobal/registration";
$route['registerUsr']="sglobal/registerUsr";
模板是我编写的自定义库,在所有其他页面中都可以正常工作。这个应用程序处于最后阶段,所以我可以有 95% 的信心说,模板工作正常。此外,我正在查看最终渲染页面的来源以及它到底想要什么。那么,我们可以在指向模板之前查看任何配置吗?
现在最终的渲染看起来像:
<form action="http://localhost/univapp/index.php/registerUsr" method="post" accept-charset="utf-8" id="form1" class="form1">
但是在提交它的时候http://localhost/univapp/index.php/searchUniv
仅供参考,我在同一页面上还有另一个搜索表单(很远的 div,不同的 id,不同的名称,不同的类),它使用指向 index.php/searchUniv 的 POST。有什么问题吗?