+ -
当前位置:首页 → 问答吧 → 请问如何获取smarty模板文件中form提交的变量?

请问如何获取smarty模板文件中form提交的变量?

时间:2010-01-24

来源:互联网

大部分情况下都是php文件处理好变量值交给模板文件输出,那么想从模板文件获取form变量该怎么办?
我的情况如下:
index.php文件内容如下:
引用

<?php
include('global.php');   //实例化mysql类,连接数据库,配置smarty等

$smarty->display("index.html");

.....                 //获取并处理$_POST[ ]

?>


index.html

引用

<form action="logio.php" method="post">
<div class="mainbg">
<div class="center">

<div class="title">
用户登陆
</div>

<div class="username">
<div class="cleft">用户名:
</div>
<div class="cright">
<input name="user" type="text" size="20" />
</div>
</div>

<div class="userpass">
<div class="cleft">口令:
</div>
<div class="cright">
<input name="pw" type="password" size="20" />

作者: couth   发布时间: 2010-01-24

post提交:
    $smarty.post.user
    $smarty.post.password

如果是get提交:
    $smarty.get.user
    $smarty.get.password

注意:这些都是直接输出的,如果你不是一个很直接的人就请做个判断吧 :)

作者: ehen   发布时间: 2010-01-24

你应该使用MVC模式,也就是说要给index.php一个指令action,
你要显示登陆框就给它一个action="login"指令;
如果要验证该登陆用户名和密码给它另一个指令action="checkuser";
比如:
复制代码
  1. <?php
  2. if($action == 'login'){
  3.     $smarty->display("index.html");
  4. }
  5. if($action == 'checkuser' ){
  6.    //验证用户名和密码;
  7. }
  8. ?>

作者: figo0505   发布时间: 2010-01-25

相关阅读 更多