PDA

View Full Version : Required Fields???



jasonhardwick
September 19th, 2006, 09:55 AM
I need to make the e-mail and address fields required but I'm haveing trouble can anyone help.


<?php
$Type = $_POST['Type'];
$First_Name = $_POST['First_Name'];
$Last_Name = $_POST['Last_Name'];
$Company = $_POST['Company'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$Ports_of_Interest = $_POST['Ports_of_Interest'];
$Collector_Level = $_POST['Collector_Level'];
$Collector_Type = $_POST['Collector_Type'];
$Designer_Specialty = $_POST['Designer_Specialty'];
$Designer_Preferences = $_POST['Designer_Preferences'];
$Designer_Visit_with_Client = $_POST['Designer_Visit_with_Client'];
$Designer_Preview = $_POST['Designer_Preview'];
$Designer_Name_to_Dealers = $_POST['Designer_Name_to_Dealers'];
$Consultant_Specialty = $_POST['Consultant_Specialty'];
$Consultant_Type = $_POST['Consultant_Type'];
$Gallery_Specialty = $_POST['Gallery_Specialty'];
$Gallery_Handle = $_POST['Gallery_Handle'];
$Gallery_Fairs = $_POST['Dealer_Fairs'];
$Gallery_Other = $_POST['Dealer_Other'];
$Dealer_Type = $_POST['Dealer_Type'];
$Dealer_Fairs = $_POST['Dealer_Fairs'];
$Dealer_Other = $_POST['Dealer_Other'];
$Curator_Title = $_POST['Curator_Title'];
$Press_Title = $_POST['Press_Title'];
$Press_Media_Type = $_POST['Press_Media_Type'];
$link = mysql_connect( 'XXXXXXXXXXXX', 'XXXXXX', 'XXXX' ) or die( mysql_error() );
mysql_select_db( 'XXXXXX', $link ) or die( mysql_error() );

$result = mysql_query( "INSERT INTO Invitation_Request (Type, First_Name, Last_Name, Company, Address, City, State, Zip, Phone, Email, Ports_of_Interest, Collector_Level, Collector_Type, Designer_Specialty, Designer_Preferences, Designer_Visit_with_Client, Designer_Preview, Designer_Name_to_Dealers,Consultant_Specialty, Consultant_Type, Gallery_Specialty, Gallery_Handle, Gallery_Fairs, Gallery_Other, Dealer_Type, Dealer_Fairs, Dealer_Other, Curator_Title, Press_Title, Press_Media_Type, Artist_Affiliation) VALUES ( '$Type','$First_Name','$Last_Name','$Company','$Ad dress','$City','$State','$Zip','$Phone','$Email',' $Ports_of_Interest','$Collector_Level','$Collector _Type','$Designer_Specialty','$Designer_Preference s','$Designer_Visit_with_Client','$Designer_Previe w','$Designer_Name_to_Dealers','$Consultant_Specia lty','$Consultant_Type','$Gallery_Specialty','$Gal lery_Handle','$Gallery_Fairs','$Gallery_Other','$D ealer_Type','$Dealer_Fairs','$Dealer_Other','$Cura tor_Title','$Press_Title','$Press_Media_Type','$Ar tist_Affiliation' )" ) or die( mysql_error() );
?>

bwh2
September 19th, 2006, 10:11 AM
/* get all the post vars */
$Email = $_POST['Email'];
$Address = $_POST['Address'];

if( trim($Email)=='' || trim($Address)=='' ) {
echo 'Email and address are both required.';
}
else {
/* hit db and run query */
}
that's really basic validation - just testing if they are blank strings. you can also run regex tests to see if the email is valid.

jasonhardwick
September 19th, 2006, 10:35 AM
<?php
$Type = $_POST['Type'];
$First_Name = $_POST['First_Name'];
$Last_Name = $_POST['Last_Name'];
$Company = $_POST['Company'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$Ports_of_Interest = $_POST['Ports_of_Interest'];
$Collector_Level = $_POST['Collector_Level'];
$Collector_Type = $_POST['Collector_Type'];
$Designer_Specialty = $_POST['Designer_Specialty'];
$Designer_Preferences = $_POST['Designer_Preferences'];
$Designer_Visit_with_Client = $_POST['Designer_Visit_with_Client'];
$Designer_Preview = $_POST['Designer_Preview'];
$Designer_Name_to_Dealers = $_POST['Designer_Name_to_Dealers'];
$Consultant_Specialty = $_POST['Consultant_Specialty'];
$Consultant_Type = $_POST['Consultant_Type'];
$Gallery_Specialty = $_POST['Gallery_Specialty'];
$Gallery_Handle = $_POST['Gallery_Handle'];
$Gallery_Fairs = $_POST['Dealer_Fairs'];
$Gallery_Other = $_POST['Dealer_Other'];
$Dealer_Type = $_POST['Dealer_Type'];
$Dealer_Fairs = $_POST['Dealer_Fairs'];
$Dealer_Other = $_POST['Dealer_Other'];
$Curator_Title = $_POST['Curator_Title'];
$Press_Title = $_POST['Press_Title'];
$Press_Media_Type = $_POST['Press_Media_Type'];

if( trim($Email)=='' || trim($Address)=='' ) {
echo 'Email and address are both required.';
}
else {
/* hit db and run query */
}

$link = mysql_connect( 'XXXX', 'XXXX', 'XXXX' ) or die( mysql_error() );
mysql_select_db( 'XXXX', $link ) or die( mysql_error() );

$result = mysql_query( "INSERT INTO Invitation_Request (Type, First_Name, Last_Name, Company, Address, City, State, Zip, Phone, Email, Ports_of_Interest, Collector_Level, Collector_Type, Designer_Specialty, Designer_Preferences, Designer_Visit_with_Client, Designer_Preview, Designer_Name_to_Dealers,Consultant_Specialty, Consultant_Type, Gallery_Specialty, Gallery_Handle, Gallery_Fairs, Gallery_Other, Dealer_Type, Dealer_Fairs, Dealer_Other, Curator_Title, Press_Title, Press_Media_Type, Artist_Affiliation) VALUES ( '$Type','$First_Name','$Last_Name','$Company','$Ad dress','$City','$State','$Zip','$Phone','$Email',' $Ports_of_Interest','$Collector_Level','$Collector _Type','$Designer_Specialty','$Designer_Preference s','$Designer_Visit_with_Client','$Designer_Previe w','$Designer_Name_to_Dealers','$Consultant_Specia lty','$Consultant_Type','$Gallery_Specialty','$Gal lery_Handle','$Gallery_Fairs','$Gallery_Other','$D ealer_Type','$Dealer_Fairs','$Dealer_Other','$Cura tor_Title','$Press_Title','$Press_Media_Type','$Ar tist_Affiliation' )" ) or die( mysql_error() );
?>

Like this... when i try it with the fields blank the form still sends.

bwh2
September 19th, 2006, 10:55 AM
that's because you didn't put your db and query code within the else statement. put it directly below the comments but before the }

jasonhardwick
September 19th, 2006, 11:36 AM
Ok i'm a little slow this morning...what do you mean query code?

bwh2
September 19th, 2006, 12:03 PM
if( trim($Email)=='' || trim($Address)=='' ) {
echo 'Email and address are both required.';
}
else {
/* hit db and run query */
$link = mysql_connect( 'XXXX', 'XXXX', 'XXXX' ) or die( mysql_error() );
mysql_select_db( 'XXXX', $link ) or die( mysql_error() );

$result = mysql_query( "INSERT INTO Invitation_Request (Type, First_Name, Last_Name, Company, Address, City, State, Zip, Phone, Email, Ports_of_Interest, Collector_Level, Collector_Type, Designer_Specialty, Designer_Preferences, Designer_Visit_with_Client, Designer_Preview, Designer_Name_to_Dealers,Consultant_Specialty, Consultant_Type, Gallery_Specialty, Gallery_Handle, Gallery_Fairs, Gallery_Other, Dealer_Type, Dealer_Fairs, Dealer_Other, Curator_Title, Press_Title, Press_Media_Type, Artist_Affiliation) VALUES ( '$Type','$First_Name','$Last_Name','$Company','$Ad dress','$City','$State','$Zip','$Phone','$Email',' $Ports_of_Interest','$Collector_Level','$Collector _Type','$Designer_Specialty','$Designer_Preference s','$Designer_Visit_with_Client','$Designer_Previe w','$Designer_Name_to_Dealers','$Consultant_Specia lty','$Consultant_Type','$Gallery_Specialty','$Gal lery_Handle','$Gallery_Fairs','$Gallery_Other','$D ealer_Type','$Dealer_Fairs','$Dealer_Other','$Cura tor_Title','$Press_Title','$Press_Media_Type','$Ar tist_Affiliation' )" ) or die( mysql_error() );
}

Seb Hughes
September 19th, 2006, 12:27 PM
Since its going into a Db woulnt you want to stripslashes to prevent SQL injection.

jasonhardwick
September 19th, 2006, 12:28 PM
Ok thats what i thought...

Ok i did that and it still sends the form, maybe i didnt explain the problem in its entierty i have a flash form that post the form info to my confirmation php page and then post it to my database. So here is the entire confirmation page html is there something wrong with it?


<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
color: #333333;
}
.style2 {font-family: Arial, Helvetica, sans-serif; color: #333333; font-weight: bold; }
-->
</style>
<title>Thank You</title><p align="center" class="style2"> - Your application has been sent - </p>
<p align="center" class="style1">Thank you for your interest in attending SeaFair<br>
We will make every effort to address all invitation requests in a timely manner.<br>
We also would like to remind you that invitations to board the yacht are available from participating galleries in each segment<br>
Feel free to contact us with any further questions <a href="Mailto:info@expoships.com">info@expoships.com</a></p>
<p align="center" class="style1">&nbsp;</p>
<p align="center" class="style1">You may close this window </p>
<?php

$Type = $_POST['Type'];
$First_Name = $_POST['First_Name'];
$Last_Name = $_POST['Last_Name'];
$Company = $_POST['Company'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$Ports_of_Interest = $_POST['Ports_of_Interest'];
$Collector_Level = $_POST['Collector_Level'];
$Collector_Type = $_POST['Collector_Type'];
$Designer_Specialty = $_POST['Designer_Specialty'];
$Designer_Preferences = $_POST['Designer_Preferences'];
$Designer_Visit_with_Client = $_POST['Designer_Visit_with_Client'];
$Designer_Preview = $_POST['Designer_Preview'];
$Designer_Name_to_Dealers = $_POST['Designer_Name_to_Dealers'];
$Consultant_Specialty = $_POST['Consultant_Specialty'];
$Consultant_Type = $_POST['Consultant_Type'];
$Gallery_Specialty = $_POST['Gallery_Specialty'];
$Gallery_Handle = $_POST['Gallery_Handle'];
$Gallery_Fairs = $_POST['Dealer_Fairs'];
$Gallery_Other = $_POST['Dealer_Other'];
$Dealer_Type = $_POST['Dealer_Type'];
$Dealer_Fairs = $_POST['Dealer_Fairs'];
$Dealer_Other = $_POST['Dealer_Other'];
$Curator_Title = $_POST['Curator_Title'];
$Press_Title = $_POST['Press_Title'];
$Press_Media_Type = $_POST['Press_Media_Type'];

if( trim($Email)=='' || trim($Address)=='' ) {
echo 'Email and address are both required.';
}
else {
/* hit db and run query */
$link = mysql_connect( 'XXXX', 'XXXX', 'XXXX' ) or die( mysql_error() );
mysql_select_db( 'XXXX', $link ) or die( mysql_error() );

$result = mysql_query( "INSERT INTO Invitation_Request (Type, First_Name, Last_Name, Company, Address, City, State, Zip, Phone, Email, Ports_of_Interest, Collector_Level, Collector_Type, Designer_Specialty, Designer_Preferences, Designer_Visit_with_Client, Designer_Preview, Designer_Name_to_Dealers,Consultant_Specialty, Consultant_Type, Gallery_Specialty, Gallery_Handle, Gallery_Fairs, Gallery_Other, Dealer_Type, Dealer_Fairs, Dealer_Other, Curator_Title, Press_Title, Press_Media_Type, Artist_Affiliation) VALUES ( '$Type','$First_Name','$Last_Name','$Company','$Ad dress','$City','$State','$Zip','$Phone','$Email',' $Ports_of_Interest','$Collector_Level','$Collector _Type','$Designer_Specialty','$Designer_Preference s','$Designer_Visit_with_Client','$Designer_Previe w','$Designer_Name_to_Dealers','$Consultant_Specia lty','$Consultant_Type','$Gallery_Specialty','$Gal lery_Handle','$Gallery_Fairs','$Gallery_Other','$D ealer_Type','$Dealer_Fairs','$Dealer_Other','$Cura tor_Title','$Press_Title','$Press_Media_Type','$Ar tist_Affiliation' )" ) or die( mysql_error() );
}
?>

bwh2
September 19th, 2006, 12:38 PM
Since its going into a Db woulnt you want to stripslashes to prevent SQL injection.ideally you would use regex to clean things up.

jasonhardwick
September 19th, 2006, 12:40 PM
Should my php info be first on this page?

mlk
September 19th, 2006, 12:49 PM
you'll first hand to do a client-side verification (ie let flash check if the fields have variables and output an error message if they don't).

Then you should do the server-side verification as pointed out.

jasonhardwick
September 19th, 2006, 01:03 PM
Ok... I am lost on this, is there a way to in the if/else statment to say

if( trim($Email)=='' || trim($Address)=='' ) {
goto url http://www.expoships.com/required.html

which would bring up the "error/required" window with fields that need to be filled out, and a submit button?

does that make sence or is there a way to put the "Requirement" in the flash actionscript?