Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 6676 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

  • 2 weeks later...
Posted

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]

Posted

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.

Posted

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.

<? } ?>

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.