...

View Full Version : PLEASE HELP! Form not showing!



ShadowIce
10-13-2009, 09:24 PM
Hi all. can someone tell me why my form says "validate" and "processing" instead of showing the correct form for my login?

code:

top of login.php:


<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<?php
session_start();
?>
<?php
require("formvalidation.php");
?>


formvalidation.php:


<?php
function validate_form(){
$ListErrors = array();
echo "<br>validate<br>\n";

if (isset( $_POST['user'] )) $input1 = $_POST['user'];
if (isset( $_POST['pass'] )) $input2 = $_POST['pass'];

if ($input1==1)
$ListErrors["user"]="You forgot to enter a username";
if ($input2==2)
$ListErrors["pass"]="You forgot to enter a password";

return $ListErrors;
}


function show_form(){

if ($num_args = func_num_args()>0)
$Errors=func_get_arg(0);


echo " <form name=\"login\" id=\"login\" action=\"".$_SERVER['PHP_SELF']."\" method=post>\n";
echo " </p>\n";
echo " <p>\n";
echo " <div name=\"login1\" id=\"login1\"></div>\n";
echo " User (e-mail):<br/><input type=\"text\" value=\"\" name=\"user\" id=\"user\"/><br/>\n";
echo " Password:<br/><input type=\"text\" value=\"\" name=\"pass\" id=\"pass\"/><br/><br/>\n";
echo " <input type=\"hidden\" name=\"_submit_check\" value=\"1\"/>\n";
echo " <input type=\"submit\" name=\"loginform\" value=\"Login\"/></p>\n";
echo " </form>\n";
echo " </div>\n";

}

function process_form(){
echo "processing<br>\n";
//run the control

}
?>


code inside login.php that shows the form:



<?php
if (array_key_exists('_submit_check',$_POST)) {
// If validate_form() returns errors, pass them to show_form()
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
// The submitted data is valid, so process it
process_form();
}
} else {
// The form wasn't submitted, so display
show_form();
}
?>


If u need the login form, I can give it to u

ANY help is GREATLY appreciated! :)

Thanks!

Rez~

ShadowIce
10-13-2009, 09:52 PM
it basically shows the actual form, but what i mean by 'it doesn't show the form', is that it wont show the errors even when there is 1

tomws
10-13-2009, 10:43 PM
I don't see any code to echo the errors in function show_form.

ShadowIce
10-13-2009, 11:55 PM
Here's what I have now. It's not returning anything but an error ><

formvalidation.php:



<?php
function validate_form(){
$ListErrors = array();
echo "<br>validate<br>\n";

if (isset( $_POST['user'] )) $input1 = $_POST['user'];
if (isset( $_POST['pass'] )) $input2 = $_POST['pass'];

if ($input1==1)
$ListErrors["user"]="You forgot to enter a username";
if ($input2==2)
$ListErrors["pass"]="You forgot to enter a password";

return $ListErrors;

}


function show_form(){

if ($num_args = func_num_args()>0){
$Errors=func_get_arg(0);
$login = true;

echo " <form name=\"login\" id=\"login\" action=\"".$_SERVER['PHP_SELF']."\" method=post>\n";
echo " </p>\n";
echo " <p>\n";
echo " <div name=\"login1\" id=\"login1\"></div>\n";
echo " User (email):<br/><input type=\"text\" value=\"\" name=\"user\" id=\"user\"/><br/>\n";
echo " Password:<br/><input type=\"text\" value=\"\" name=\"pass\" id=\"pass\"/><br/><br/>\n";
echo " <input type=\"hidden\" name=\"_submit_check\" value=\"1\"/>\n";
echo " <input type=\"submit\" name=\"loginform\" value=\"Login\"/></p>\n";
echo " </form>\n";
echo " </div>\n";

}else{

$login = false;

echo " <form name=\"login\" id=\"login\" action=\"login1.php\" method=post>\n";
echo " </p>\n";
echo " <p>\n";
echo " <div name=\"login1\" id=\"login1\"></div>\n";
echo " User (email):<br/><input type=\"text\" value=\"\" name=\"user\" id=\"user\"/><br/>\n";
echo " Password:<br/><input type=\"text\" value=\"\" name=\"pass\" id=\"pass\"/><br/><br/>\n";
echo " <input type=\"hidden\" name=\"_submit_check\" value=\"1\"/>\n";
echo " <input type=\"submit\" name=\"loginform\" value=\"Login\"/></p>\n";
echo " </form>\n";
echo " </div>\n";

$Error = validate_form();

echo $Error;

}

}

function process_form(){
echo "processing<br>\n";
//run the form if no errors are found

}
?>


login.php:


<?php
if (array_key_exists('_submit_check',$_POST)) {
// If validate_form() returns errors, pass them to show_form()
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
// The submitted data is valid, so process it
process_form();
}
} else {
// The form wasn't submitted, so display
show_form();
}
?>


also, $login is defined in login1.php, which is where it SHOULD take u if there are no errors

I need it to return the correct error depending on which input box the user didnt enter information into. (user or pass input box)

tomws
10-14-2009, 02:25 AM
What's the error?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum