Jump to content

Recommended Posts

Hello:

 

I wanted to learn how to add a file browse/save and send photo to a contact form.

 

Form works fine, but I am trying to add this so a user can upload and send a photo of his or her artwork along with the contact information.

 

Can someone tell me how this work? My other attempts failed so I'm trying to start with a clean form.

 

This is the code I currently have:

<?php

$error = NULL;
$myDate = NULL;
$FullName = NULL;
$Address = NULL;
$City  = NULL;
$State = NULL;
$Zip = NULL;
$Phone = NULL;
$Email = NULL;
$Website = NULL;
$Comments = NULL;

if(isset($_POST['submit'])) {

$myDate = $_POST['myDate'];
$FullName = $_POST['FullName'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$Website = $_POST['Website'];
$Comments = $_POST['Comments'];

if(empty($FullName)) {
   $error .= '<div style=\'margin-bottom: 6px;\'>- Enter your Name.</div>';
}


if(empty($Email) || !preg_match('~^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$~',$Email)) {
  $error .= '<div style=\'margin-bottom: 6px;\'>- Enter a valid Email.</div>';
}

if($error == NULL) {

$sql = sprintf("INSERT INTO myContactData(myDate,FullName,Address,City,State,Zip,Phone,Email,Website,Comments) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",

mysql_real_escape_string($myDate),
mysql_real_escape_string($FullName),
mysql_real_escape_string($Address),
mysql_real_escape_string($City),
mysql_real_escape_string($State),
mysql_real_escape_string($Zip),
mysql_real_escape_string($Phone),
mysql_real_escape_string($Email),
mysql_real_escape_string($Website),
mysql_real_escape_string($Comments));
                        
if(mysql_query($sql)) {
  
$error .= '<div style=\'margin-bottom: 6px;\'>Thank you for contacting us. We will reply to your inquiry shortly.<br /><br /></div>';
    
mail( "mt@gmail.com", "Contact Request",

"Date Sent: $myDate\n Full Name: $FullName\n Address: $Address\n City: $City\n State: $State\n Zip: $Zip\n Phone: $Phone\n Email: $Email\n Website: $Website\n Comments: $Comments\n",
"From: $Email" );

unset($FullName); 
unset($Address);
unset($City);
unset($State);
unset($Zip);
unset($Phone);
unset($Email);
unset($Website);
unset($Comments);

  }
  else {
    $error .= 'There was an error in our Database, please Try again!';
  }
}
}


?>

			<form name="myform" action="" method="post">
			<input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" />

				<div id="tableFormDiv">

					<fieldset><span class="floatLeftFormWidth"><span class="textErrorItalic">* - Required</span></span> <span class="floatFormLeft"> </span></fieldset>
					<?php echo '<span class="textError">' . $error . '</span>';?>
					<fieldset><span class="floatLeftFormWidth"><span class="textErrorItalic">*</span> Full Name:</span> <span class="floatFormLeft"><input type="text" name="FullName" size="45" maxlength="50" value="<?php echo $FullName; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth">Address:</span> <span class="floatFormLeft"><input type="text" name="Address" size="45" maxlength="50" value="<?php echo $Address; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth">City:</span> <span class="floatFormLeft"><input type="text" name="City" size="45" maxlength="50" value="<?php echo $City; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth">State:</span> <span class="floatFormLeft"><input type="text" name="State" size="45" maxlength="50" value="<?php echo $State; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth">Zip:</span> <span class="floatFormLeft"><input type="text" name="Zip" size="45" maxlength="50" value="<?php echo $Zip; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth">Phone:</span> <span class="floatFormLeft"><input type="text" name="Phone" size="45" maxlength="50" value="<?php echo $Phone; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth"><span class="textErrorItalic">*</span> Email:</span> <span class="floatFormLeft"><input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth">Website:</span> <span class="floatFormLeft"><input type="text" name="Website" size="45" maxlength="50" value="<?php echo $Website; ?>" /></span></fieldset>
					<fieldset><span class="floatLeftFormWidth">Comments:</span> <span class="floatFormLeft"><textarea name="Comments" cols="40" rows="10"><?php echo $Comments; ?></textarea></span></fieldset>
				</div>	
					<input type="submit" name="submit" value="Submit" class="submitButton" /><br />
			</form>	

 

Thanks very much!

The upload handling section of the php.net documentation shows what you need for the <form> tag, for a form field, and for basic php code to access the uploaded file information - http://www.php.net/manual/en/features.file-upload.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.