在我的index.php文件中,我有两组代码。 一组代码严重依赖php和功能,而另一组代码仅依赖html。 我正在尝试使“提交”按钮将代码转到文件register.php,但是只有html代码才能到达文件register.php,而当您单击php函数代码时,它们只是位于同一页面上注册按钮。 请帮忙。 谢谢。

在名为functions.php的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>

===============>>#1 票数:1

function echoForm($action){

echo "<method = 'post' action = '$action'>";

}

更改

function echoForm($action){

echo "<form method = 'post' action = '$action'>";

}

===============>>#2 票数: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

   }

  ask by iscattered translate from so

未解决问题?本站智能推荐: