0

In my index.php file, I have two sets of codes. One set of code relies heavily on php, and functions while the other set of code relies of only html. I'm trying to get the submit button to get the codes to go to the file register.php, but only the html codes are getting to the file register.php, while the php function codes just sits on the same page when you click the register button. Please help. Thanks.

Inside PHP file called functions.php I have 3 functions:

<?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>";

}

?>

Inside PHP file called index.php I have my main codes:

<?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>
3
  • You're missing the tag name in echoForm(). Commented May 16, 2015 at 17:11
  • 1
    You appear to be generating the registration form twice in index.php, once using your strange helper methods and the second time more conventionally in HTML. Why is that? Commented May 16, 2015 at 17:11
  • ...Because I'm trying to use the functions from now on to generate the codes, and one is working in html format while the other one isn't working in the function format, and it's because I was missing a tag from the functions format. @steveklein Commented May 16, 2015 at 18:04

2 Answers 2

1

Inside your first PHP function, echoForm, you are trying to open an HTML form element, but your code for doing that is missing the form tag. This is what you have :

function echoForm($action){

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

}

The browser interpretes that as a <method> tag, which it doesn't understand, and. To get it to see it as a form, your function has to be re-defined like below:

function echoForm($action){

   echo "<form method = 'post' action = '$action'>"; //notice I put `form` before the `method` attribute

   }
Sign up to request clarification or add additional context in comments.

Comments

1
function echoForm($action){

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

}

change it

function echoForm($action){

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

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.