NickG21 Posted December 28, 2006 Share Posted December 28, 2006 hey everyone,i have my form validation pretty well in place to where i am about satisfied with everyone i have to do. The only thing i do not know how to do is to redisplay my error messages by the text box that the error occurred in, instead of just an echoed list on the top of the page. Also, when i link to my <form action = "write.php"....> how do i redisplay the webpage the information was submitted from and not just the errors? if this is as unclear to you as it sounded to me writing it let me know and i will try to elaborate lol thank youwrite.php:[code]<?phpfunction checkEmail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(getmxrr($Domain, $MXHost)) { return TRUE; } else { if(@fsockopen($Domain, 25, $errno, $errstr, 15)) { return TRUE; } else { return FALSE; } }}if (isset($_POST['submit'])) { $company = $_POST['CompanyName']; $name = $_POST['YourName']; $email = $_POST['YourEmailAddress']; $domainName = $_POST['ListOrDomainName']; $username = $_POST['Username']; $password = $_POST['Password']; $credit = $_POST['CreditCardNumber']; $error = array(); if (empty($company)) { $error[] = "Comapny"; }if (empty($name)) { $error[] = "Your Name"; }elseif (!preg_match("/^([a-zA-Z])+/",$name)) { $error[] = "Your Name"; $name=""; }if(checkEmail($email) == FALSE) { $error[]="E-Mail Address"; $email = "";} $url = fsockopen($domainName, 20);if ($url){ $error[]=""}else{ $error[]="Invalid Domain Name"; $domainName = "";}if(empty($username)) { $error[] = "User Name"; }if(empty($password)){ $error[]="Password";}elseif (strlen($password) < 6) { $error[]= "Password Must Contain At Least Six Characters";}if(empty($credit)){ $error[]="Credit Card Number"; } elseif(!preg_match("/^([0-9])+/",$credit)) { $error[] = "Invalid Credit Card Number"; }if(count($error) > 0) { echo "<big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br/>', $error). "</p>"; } else { header('Location: ./Thanks.php'); exit; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32091-redisplaying-errors/ Share on other sites More sharing options...
ted_chou12 Posted December 28, 2006 Share Posted December 28, 2006 For displaying errors beside the input boxes of the form, try setting your messages into strings, so when there are invalid inputs, set the string as the messages you want to display, and have the echo string beside the boxes, so echo shows up blank at first, and have messages if invalid.In order to pass variables, use sessions or pass them through the page urleg.page one...Username: ted_chou12the link to the next page will be "page2.php?username=ted_chou12"and then use:$username = $_GET['username'];then you will get ted_chou12 into the $username variable of the second page.for sessions, you will have to set them. Link to comment https://forums.phpfreaks.com/topic/32091-redisplaying-errors/#findComment-148937 Share on other sites More sharing options...
NickG21 Posted December 28, 2006 Author Share Posted December 28, 2006 is there anyway to leave them in an array and individually assign the array values such as $error[1], $error[2]...... and so on? just seems that would be easier to implement into the code than going through and making all of the errors go into individual strings.thanks Link to comment https://forums.phpfreaks.com/topic/32091-redisplaying-errors/#findComment-148955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.