cry of war Posted July 17, 2007 Share Posted July 17, 2007 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 More sharing options...
matto Posted July 17, 2007 Share Posted July 17, 2007 One thing that stands out in this php script, is it relies on register_globals being switched on. Link to comment https://forums.phpfreaks.com/topic/60352-php-form-help/#findComment-300258 Share on other sites More sharing options...
cry of war Posted July 17, 2007 Author Share Posted July 17, 2007 And what does that mean ??? and is this type of Form not secure when it uses globals because it sounds like its not very secure from what i am reading about Register_globals? Link to comment https://forums.phpfreaks.com/topic/60352-php-form-help/#findComment-300261 Share on other sites More sharing options...
matto Posted July 17, 2007 Share Posted July 17, 2007 Yes, it's not very secure. Basically the difference is when you are passing variables from one page to another you should reference variables like this Instead of $variable use $_GET['variable'] or $_POST['variable'] depending on how the data is passed from one page to another. Link to comment https://forums.phpfreaks.com/topic/60352-php-form-help/#findComment-300265 Share on other sites More sharing options...
cry of war Posted July 17, 2007 Author Share Posted July 17, 2007 ok thats the way i know how to do it but how do i make it so the 2nd php file will display any information that the user missed? Link to comment https://forums.phpfreaks.com/topic/60352-php-form-help/#findComment-300269 Share on other sites More sharing options...
matto Posted July 19, 2007 Share Posted July 19, 2007 if(empty($_POST['name'])) { echo "You forgot to provide your name\n"; } Link to comment https://forums.phpfreaks.com/topic/60352-php-form-help/#findComment-302206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.