今天做项目的工程中发现了一个问题(使用的是zend framework 1.11版本),就是使用input提交表单与button提交表单的差别。情况如下:
html视图部分(index.phtml):
- <form action="register/index" method="post">
- <p><label for="mobile">手机号</label><br>
- <input type="text" name="mobile" id="mobile" value=""></p>
- <p>
- <button type="submit" name="gettemp">获取口令</button>
- </p>
- <p><label for="sms_temp">口令</label><br>
- <input type="password" name="sms_temp" id="sms_temp">
- </p>
- <p><input type="checkbox" id="agree" name="agree" value="1" checked="checked"><label
- for="agree">已阅读并同意</label><a href="#">《注册协议》</a>
- </p>
- <p style="margin:1em 0 2em;"><input type="submit" name="auth" value="验证口令并继续"/></p>
- </form>
controller部分(RegisterController):
- public function indexAction()
- {
- $mobile = trim($this->_getParam('mobile'));
- $sms_temp = trim($this->_getParam('sms_temp')); //注册用户收到的短信口令
- //获取临时口令
- if (isset($_POST['gettemp']) && $_POST['gettemp']) {
- echo '获取临时密码。';
- }
- //验证口令并继续,验证成功则注册成功
- if (isset($_POST['auth']) && $_POST['auth']) {
- echo '验证口令并继续。';
- }
- }
当我点击“获取口令”的时候,页面没有反应,没有进入
- if (isset($_POST['gettemp']) && $_POST['gettemp']) {
- echo '获取临时密码。';
- }
条件语句中,而我点击“验证口令并继续”时进入了
- if (isset($_POST['auth']) && $_POST['auth']) {
- echo '验证口令并继续。';
- }
条件语句中
也就是说$_POST['gettemp'] 没有值,于是将html视图文件修改为:
- <form action="register/index" method="post"> <p><label for="mobile">手机号</label><br>
- <input type="text" name="mobile" id="mobile" value=""></p>
- <p>
- <button type="submit" name="gettemp" value="获取口令">获取口令</button>
- </p>
- <p><label for="sms_temp">口令</label><br>
- <input type="password" name="sms_temp" id="sms_temp">
- </p>
- <p><input type="checkbox" id="agree" name="agree" value="1" checked="checked"><label for="agree">已阅读并同意</label><a href="#">《注册协议》</a>
- </p>
- <p style="margin:1em 0 2em;"><input type="submit" name="auth" value="验证口令并继续"/>
- </p>
- </form>
注意第4行的变化,添加了value="获取口令",问题解决。
转载于:https://blog.51cto.com/lfliangli/1050520