Jump to content

PHP form help


cry of war

Recommended Posts

I am kind of new to PHP form files and was wondering if this was set up correct. I took this from parts of a book I am reading. This is my 2nd try at it. I havent tested this yet because I cant get on my server ATM but the first time I tried the whole page was blank including the Source code.

<?
$page = "form1.php"
?>
<html>
<head>
<style type="text/css">
.error {color:red;}
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
fuction error_flag($error, $field) {
if($error[$field]) {
print ("<td class=error>");
} else {
print ("<td>");
}
}

funtion print_form() {
global $error, $print_again, $first, $last, $page;
?>
<form action="<?echo $page ?>" method="post">
<?
if($print_again) {
?><h3> You missed some fields. Please correct the <span class=error>red</span> fields.<?
} else {
/><h3> Please fill-in the following fields.<h3><?
}
?>
<table border="0">
<tr><td><? error_flag($error, "first"): ?> First Name:</td>
<td><input type="text" name="first" value="<?=$first ?>"></td></tr>
<tr><td><? error_flag($error, "last"): ?> Last Name:</td>
<td><input type="text" name="last" value="<?=$last ?>"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" name="submit" value="Submit Form"></td></tr>
</table>
</form>
<?
}

function check_form() {
global $error, $print_again, $first, $last;
$error['first'] = false;
$error['last'] = false;
$print_again = false;
if($first == "") {
$errror['first'] = true;
$print_again = true;
}
if($last == "") {
$errror['last'] = true;
$print_again = true;
}
if($print_again) {
print_form();
} else {
print("<h3>Thank you for copleting the form!</h3>");
}
}


if(isset($submit)) {
check_form();
} else {
print_form();
}
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/60352-php-form-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.