在我的index.php文件中,我有两组代码。一组代码在很大程度上依赖于php和函数,而另一组代码仅依赖于html。我试图获取提交按钮以获取代码转到文件register.php,但只有html代码进入文件register.php,而php函数代码只是位于同一页面上单击注册按钮。请帮忙。感谢。
在PHP文件中名为functions.php我有3个函数:
<?php
//****************************************************************
function echoForm($action){
echo "<method = 'post' action = '$action'>";
}
//****************************************************************
function echoField($type,$name,$maxlength,$text){
if($type == 'text'){
echo "$text</br><input type = 'text' name='$name' size = '15' maxlength = '$maxlength'/></br>";
}
else if($type == 'pass'){
echo "$text</br><input type = 'password' name = '$name' size = '15' maxlength = '$maxlength'/></br>";
}
else if($type == 'submit'){
echo "<input type = 'submit' name = '$name' value = '$text'/>";
}
}
//****************************************************************
function echoText($text){
echo "$text</br>";
}
?>
在名为index.php的PHP文件中我有我的主要代码:
<?php
include('functions.php');
echoForm('register.php');
echoField('text','username','20','Username');
echoField('pass','password','20','Password');
echoField('text','email','50','Email');
echoField('submit','submit','null','Register');
echoText('</form></br>');
?>
<html>
<body>
<form name = "form" method = "post" action = "register.php">
<input type = "text" name="username" size = "15" maxlength = "20" value=""/>
<input type = "password" name = "password" size = "15" maxlength = "20" value=""/>
<input type = "text" name = "email" size = "15" maxlength = "50" value=""/>
<input type = "submit" name = "submit" value = "Register"/>
</form>
</body>
</html>
答案 0 :(得分:1)
function echoForm($action){
echo "<method = 'post' action = '$action'>";
}
改变它
function echoForm($action){
echo "<form method = 'post' action = '$action'>";
}
答案 1 :(得分:1)
在您的第一个PHP函数echoForm中,您正在尝试打开HTML表单元素,但是您执行此操作的代码缺少form
标记。这就是你所拥有的:
function echoForm($action){
echo "<method = 'post' action = '$action'>";
}
浏览器会将其解释为<method>
标记,但它并不理解。为了让它看作一个表单,你的函数必须重新定义如下:
function echoForm($action){
echo "<form method = 'post' action = '$action'>"; //notice I put `form` before the `method` attribute
}