martinn82 Posted June 18, 2012 Share Posted June 18, 2012 Greetings, Here is a piece of sample code that I will be using in a form (form not complete yet). This specific field will not be validated for entry like other ones BECAUSE I want to validate it against a unique client code ie: XML or TXT document. I am looking to have the following happen: ex: Client Number: 12345678 --> validate against XML or TXT "list" of numbers in a document to prove they are a client if not return the error page specified in the below code. Also can you please tell me is it better to list in XML or TXT also give an example? When it comes to validation I get lost. Thanks ---- // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "xxxxxx"; $Subject = "Client Inquiry Request"; $clientnumber = Trim(stripslashes($_POST['clientnumber'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">"; exit; } // prepare email body text $Body = ""; $Body .= "clientnumber: "; $Body .= $clientnumber; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=success.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">"; } ?> ---- Quote Link to comment https://forums.phpfreaks.com/topic/264356-php-w-a-separate-xml-or-txt-field-validation/ Share on other sites More sharing options...
btherl Posted June 18, 2012 Share Posted June 18, 2012 "best" for flexibility and protection against data loss would be putting them in a database. But if you want them in a file, there are 2 basic steps to the validation. 1. Read in the data from the file. This requires opening the file, reading in the lines and removing newline characters. 2. Check each number against the submitted number For #1 you could use a tutorial such as this one, found by googling for "php file read tutorial" : http://www.phphelps.com/8_How_to_read_file_in_PHP.shtml Then once you have a loop that reads in the file, you can add code to check each number. Keep in mind if there might be extra spaces or other invisible characters in either number. I wouldn't consider XML until you are comfortable with dealing with a plain text file. Quote Link to comment https://forums.phpfreaks.com/topic/264356-php-w-a-separate-xml-or-txt-field-validation/#findComment-1354752 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.