Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Web Form Field Validation

Featured Replies

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

Check your "$webCompanio nPort" - is there a typo (blank) or is it just copy-paste result?

  • Author

nah just a copy/paste problem the original code is fine

thanks

  • 2 weeks later...

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]

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.

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.

<? } ?>

  • Author

Thanks everyone for for suggestions.

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.