/    Sign up×
Community /Pin to ProfileBookmark

Issue with required fields on PHP form

I have a form that I created using PHP Form Wizard and it works fine except for one thing. I have three file fields where the user can upload a file or three when they submit the form, and for some reason, my form is requiring that three files be uploaded before the form is submitted. PHP Form Wizard doesn’t seem to have an option that makes it optional for the user to upload a file. I want to make it optional to attach a file, not mandatory. So I want to just go into the code and remove whatever is making it mandatory to attach a file.

If you’d like to see my form online it’s [url]http://bannersforcheap.com/ordernodesign.html[/url].

The following is my code, thanks for any help.

[CODE]<?php
# —————————————————-
# —–
# —– This script was generated by PHP-Form Wizard 1.2.5 on 7/28/2010 at 3:27:50 AM
# —–
# —– http://www.tools4php.com
# —–
# —————————————————-

// Receiving variables
@$pfw_ip= $_SERVER[‘REMOTE_ADDR’];
@$Name = addslashes($_POST[‘Name’]);
@$Email = addslashes($_POST[‘Email’]);
@$Confirm_Email = addslashes($_POST[‘Confirm_Email’]);
@$Phone_Number = addslashes($_POST[‘Phone_Number’]);
@$Call = addslashes($_POST[‘Call’]);
@$Height = addslashes($_POST[‘Height’]);
@$Width = addslashes($_POST[‘Width’]);
@$Quantity = addslashes($_POST[‘Quantity’]);
@$Grommets = addslashes($_POST[‘Grommets’]);
@$Pole_Pockets = addslashes($_POST[‘Pole_Pockets’]);
@$Double_Sided = addslashes($_POST[‘Double_Sided’]);
@$File1_Name = $_FILES[‘File1’][‘name’];
@$File1_Size = $_FILES[‘File1’][‘size’];
@$File1_Temp = $_FILES[‘File1’][‘tmp_name’];
@$File1_Mime_Type = $_FILES[‘File1’][‘type’];
@$File2_Name = $_FILES[‘File2’][‘name’];
@$File2_Size = $_FILES[‘File2’][‘size’];
@$File2_Temp = $_FILES[‘File2’][‘tmp_name’];
@$File2_Mime_Type = $_FILES[‘File2’][‘type’];
@$File3_Name = $_FILES[‘File3’][‘name’];
@$File3_Size = $_FILES[‘File3’][‘size’];
@$File3_Temp = $_FILES[‘File3’][‘tmp_name’];
@$File3_Mime_Type = $_FILES[‘File3’][‘type’];
@$Comments = addslashes($_POST[‘Comments’]);

function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}

// Validation
if (strlen($Name) == 0 )
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid name</font></p>”);
}

if (! ereg(‘[A-Za-z0-9_-]+@[A-Za-z0-9_-]+.[A-Za-z0-9_-]+’, $Email))
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid email</font></p>”);
}

if (strlen($Email) == 0 )
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid email</font></p>”);
}

if ($Confirm_Email != $Email)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please ensure your Email and Confirm email match.</font></p>”);
}

if (strlen($Confirm_Email) == 0 )
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please ensure your Email and Confirm email match.</font></p>”);
}

if (strlen($Phone_Number) !=10)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a 10 digit phone number including your area code and no dashes.</font></p>”);
}

if (strlen($Call) == 0 )
{
die(“”);
}

if ( $Height <= 0)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid height greater ‘0’.</font></p>”);
}

if (strlen($Height) == 0 )
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid height greater ‘0’.</font></p>”);
}

if ( $Width <= 0)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid width greater than ‘0’.</font></p>”);
}

if (strlen($Width) == 0 )
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid width greater than ‘0’.</font></p>”);
}

if ( $Quantity <= 0)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid quantity greater than ‘0’.</font></p>”);
}

if (strlen($Quantity) == 0 )
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid quantity greater than ‘0’.</font></p>”);
}

if (strlen($Grommets) == 0 )
{
die(“”);
}

if (strlen($Pole_Pockets) == 0 )
{
die(“”);
}

if (strlen($Double_Sided) == 0 )
{
die(“”);
}

if( $File1_Size == 0)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file into the first File Box.</font></p>”);
}
if( $File1_Size >10000)
{
//delete file
unlink($File1_Temp);
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file into the first File Box.</font></p>”);
}
if( $File1_Mime_Type != “application/msword” AND $File1_Mime_Type != “application/pdf” AND $File1_Mime_Type != “application/rtf” AND $File1_Mime_Type != “application/xml” AND $File1_Mime_Type != “application/zip” AND $File1_Mime_Type != “audio/mpeg” AND $File1_Mime_Type != “image/gif” AND $File1_Mime_Type != “image/ief” AND $File1_Mime_Type != “image/pjpeg” AND $File1_Mime_Type != “image/jpeg” AND $File1_Mime_Type != “image/png” AND $File1_Mime_Type != “image/tiff” AND $File1_Mime_Type != “text/html” )
{
unlink($File1_Temp);
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file into the first File Box.</font></p>”);
}
$uploadFile = “Uploads/”.$File1_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $File1_Temp , $uploadFile);
chmod($uploadFile, 0644);
$File1_URL = “http://www.bannersforcheap.com/Uploads/”.$File1_Name ;

if( $File2_Size == 0)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file for File 2. </font></p>”);
}
if( $File2_Size >10000)
{
//delete file
unlink($File2_Temp);
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file for File 2. </font></p>”);
}
if( $File2_Mime_Type != “application/msword” AND $File2_Mime_Type != “application/pdf” AND $File2_Mime_Type != “application/rtf” AND $File2_Mime_Type != “application/xml” AND $File2_Mime_Type != “application/zip” AND $File2_Mime_Type != “image/gif” AND $File2_Mime_Type != “image/ief” AND $File2_Mime_Type != “image/pjpeg” AND $File2_Mime_Type != “image/jpeg” AND $File2_Mime_Type != “image/png” AND $File2_Mime_Type != “image/tiff” AND $File2_Mime_Type != “text/html” )
{
unlink($File2_Temp);
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file for File 2. </font></p>”);
}
$uploadFile = “Uploads/”.$File2_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $File2_Temp , $uploadFile);
chmod($uploadFile, 0644);
$File2_URL = “http://www.bannersforcheap.com/Uploads/”.$File2_Name ;

if( $File3_Size == 0)
{
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file3</font></p>”);
}
if( $File3_Size >10000)
{
//delete file
unlink($File3_Temp);
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file3</font></p>”);
}
if( $File3_Mime_Type != “application/msword” AND $File3_Mime_Type != “application/pdf” AND $File3_Mime_Type != “application/rtf” AND $File3_Mime_Type != “application/xml” AND $File3_Mime_Type != “application/zip” AND $File3_Mime_Type != “image/gif” AND $File3_Mime_Type != “image/ief” AND $File3_Mime_Type != “image/pjpeg” AND $File3_Mime_Type != “image/jpeg” AND $File3_Mime_Type != “image/png” AND $File3_Mime_Type != “image/tiff” AND $File3_Mime_Type != “text/html” )
{
unlink($File3_Temp);
die(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Please enter a valid file3</font></p>”);
}
$uploadFile = “Uploads/”.$File3_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $File3_Temp , $uploadFile);
chmod($uploadFile, 0644);
$File3_URL = “http://www.bannersforcheap.com/Uploads/”.$File3_Name ;

//Sending Email to form owner
$pfw_header = “From: $Confirm_Emailn”
. “Reply-To: $Confirm_Emailn”;
$pfw_subject = “Banner Order”;
$pfw_email_to = “[email protected]”;
$pfw_message = “Visitor’s IP: $pfw_ipn”
. “Name: $Namen”
. “Email: $Emailn”
. “Confirm_Email: $Confirm_Emailn”
. “Phone_Number: $Phone_Numbern”
. “Call: $Calln”
. “Height: $Heightn”
. “Width: $Widthn”
. “Quantity: $Quantityn”
. “Grommets: $Grommetsn”
. “Pole_Pockets: $Pole_Pocketsn”
. “Double_Sided: $Double_Sidedn”
. “File1: $File1_URLn”
. “File2: $File2_URLn”
. “File3: $File3_URLn”
. “Comments: $Commentsn”;
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
$pfw_header = “From: [email protected]
. “Reply-To: [email protected]”;
$pfw_subject = “Banners For Cheap :: Banner Order Received”;
$pfw_email_to = “$Confirm_Email”;
$pfw_message = “Thank you for your banner order. n”
. “n”
. “We have received it and we’re formulating a design proof to be sent to you. n”
. “n”
. “Expect a design proof within 24 hours of your placed order. We usually get design proofs out within minutes of an order. n”
. “n”
. “We’re available 24/7 at [email protected] and 602-68-VINYL. n”
. “n”
. “Regards, n”
. “Banners For Cheap.com Team”;
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

echo(“<p align=’center’><font face=’Arial’ size=’3′ color=’#FF0000′>Thank you for your order. We’ll get a design proof to you soon.</font></p>”);
?>
[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJul 28.2010 — I don't think it's a matter of deleting code.

Having a quick look at your code, I think you will have to add code to check if any files have been uploaded using IF blocks to check if any of the file parameters that your script expects for those files exist or not.

If the parameters don't exist or are empty then you by pass the relevent file upload code. If the parameters do exist then you let the script run as per normal.
×

Success!

Help @nickwhall spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...