brainonastick Posted September 29, 2006 Posted September 29, 2006 Hi there, I am trying to add some validation checks to a PHP web form processing script so that required fields are not empty, email addresses are corrrectly formatted etc. I have found two different coding solutions neither of which is working - I get a parsing error in both cases. Option 1: <?php include_once('FX/FX.php'); include_once('FX/server_data.php'); $firstname1 = $_POST['firstname1']; $lastname1 = $_POST['lastname1']; $gender1 = $_POST['gender']; $dateofbirth1 = $_POST['dateofbirth']; //etc etc if(!$_POST['firstname1']) {echo "Please enter a first name"; die();} $newregistration = new FX($serverIP,$webCompanionPort); $newregistration -> SetDBData('Web Registration Information.fp7', 'Web Registration Information'); $newregistration -> SetDBPassword($webPW, $webUN); $newregistration -> AddDBParam('First_Name_1', $firstname1); //etc etc ?> Option 2: <?php include_once('FX/FX.php'); include_once('FX/server_data.php'); $firstname1 = $_POST['firstname1']; $lastname1 = $_POST['lastname1']; $gender1 = $_POST['gender']; $dateofbirth1 = $_POST['dateofbirth']; //etc etc if(empty($firstname1)) {echo "Please enter a first name"; die();} $newregistration = new FX($serverIP,$webCompanionPort); $newregistration -> SetDBData('Web Registration Information.fp7', 'Web Registration Information'); $newregistration -> SetDBPassword($webPW, $webUN); $newregistration -> AddDBParam('First_Name_1', $firstname1); //etc etc What am I doing wrong? Cheers, Steven
Jul Posted October 3, 2006 Posted October 3, 2006 Check your "$webCompanio nPort" - is there a typo (blank) or is it just copy-paste result?
brainonastick Posted October 5, 2006 Author Posted October 5, 2006 nah just a copy/paste problem the original code is fine thanks
javierinSFO Posted October 14, 2006 Posted October 14, 2006 Hi Steven: I do all my form validation in javascript rather than in PHP. It's much easier than in PHP as Dreamweaver 8 lets you simply select the fields and add form validation. To see one of my pages in action using Filemaker PHP and javascript validation take a look at this page: http://cprcpr.com/scheduleforclass.php?classname=CPR%20for%20Community Pick any day and try to register for a class. Omit any of the fields in asterisks and you will see javascript validation in action. I know there are cases where PHP validation is needed but for most of my clients we only need to ensure that a field contains a number, a field contains a valid email address, a field contains a number not text, etc and Javascript validation does that quite well. Hope that is helpful. Javier [email protected]
mlindal Posted October 17, 2006 Posted October 17, 2006 it is good to have both validations. I have a Javascript FormValidator that checks the form before it is Posted. Then on the receiving page, I check it with PHP. This is important as some people do not have Java turned on. It makes your site more accessible. Do a Google search -> Java FormValidator for the code.
mlindal Posted October 17, 2006 Posted October 17, 2006 Here is my form checker in PHP $error1url = 'search_e.php?error=1'; if($TitleSubAlt=='' && $PersonalNameList=='' && $YearOfPublication=='' && $OwnerOfRecord=='' && $ISBN=='' && $Series=='' && $Keywords=='' && $Language=='' && $Subject=='' && $PublicationsType=='' && $centre=='') { header( "Location: $error1url" ); exit ; } On the form page you would need $error = $_REQUEST['error']; Then in your html somewhere: <? if($error==1) { ?> You need to add some data. <? } ?>
brainonastick Posted October 23, 2006 Author Posted October 23, 2006 Thanks everyone for for suggestions.
Recommended Posts
This topic is 6676 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now