HTML / PHP final edits Expert needed

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

CoopGamer3

Thread Starter
Joined
May 30, 2004
Messages
24
If I post PHP code, would someone be able to look at it & if it needs to be edited to help me? It was done for me & doesn't work yet. It is completely foreign to me. Also & more importantly would someone be able to walk me through step by step on setting it up & the retrieval process?
The main functions of the form include:
-The details of the form be sent to the email
-The upload(browse) button send the picture somewhere where I can access it & resize it to post on my site.
-A simultaneous redirect to another page in my site upon pushing the submit button
-I think there are some security features in there as well which is a bonus.
Thanks in advance
 

CoopGamer3

Thread Starter
Joined
May 30, 2004
Messages
24
The things that are going wrong are:
1. I used to get the form results sent to [email protected] & that is no longer happening.
2. It used to redirect to another page in my site www.lifearoundtown.com/thankyoupage.html it doesn't anymore.
3. I want it to send uploaded pictures to a location where I can retrieve them, resize them & then post them on my site. This is the hardest part. It has never done that.
4. A minor problem is that I have a banner that I created & want to appear at the top. It is not showing up.
If it means anything to you guys, I used Serif Webplus 9.0 to create an 800 page website. It is all drag & drop. I originally used Frontpage for the form & it worked fine, but I was told to dump Frontpage for several reasons. So I am now pasting this code in several different programs to see if it will work. NVU & Dreamweaver to name a few. After making the frontpage form, it seemed easy & I didn't think I would need to know code. I have been working on this since August.

Any input you have would be greatly appreciated.


<?php
/* IMPORTANT NOTICE: Make sure that the <?php tag (above) is the first line, there cannot
** be anything above it, not even a blank line. If there is you will get "HEADERS already
** sent error messages
**Script modified by Gail Kasey 14/01/06*/
**modified by design1online.com 1/16/2005

if (isset($_POST['submitted']))
{
$errors = array(); // Initialize error array.
if ($fundraiserCode != "") //Modified the re-direction code
{
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\') )
{
$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/thankyoupage.html'; // Add the page.
header("Location: $url");
}

// Check for a first name.
if (empty($_POST['firstName'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$firstname = trim($_POST['firstName']);
}

// Check for a last name.
if (empty($_POST['lastName'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$lastname = trim($_POST['lastName']);
}
//Check for name of town
if (empty($_POST['townPictures'])) {
$errors[] = 'Please enter the name of the town.';
} else {
$townPictures = trim($_POST['townPictures']);
}
//Check for State
if (empty($_POST['State'])) {
$errors[] = 'Please enter your State.';
} else {
$State = trim($_POST['State']);
}
//Check for subject
if (empty($_POST['Subject'])) {
$errors[] = 'Please enter a unique name for your pic.';
} else {
$pictureSubject = trim($_POST['Subject']);
}
//Validating Email format
if (!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', trim($_POST['email'])))
{$errors[] = 'The email you entered seems to be invalid.';}

//Redirected to thank you page if box is checked
if ($_POST['actualPicturesEmail'] == 'YES') {
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\') )
{
$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/thankyoupage.html'; // Add the page.
header("Location: $url");

}

//If this box is checked it will look for a valid image to be uploaded
if ($_POST['actualPicturesForm'] == 'YES') {
if (isset($_FILES['upload']))
{
// Validate the type. Should be jpeg, jpg, or gif.
$allowed = array ('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg');
if (in_array($_FILES['upload']['type'], $allowed))
{

// Move the file over. If successfull the user will be redirected to thank you page
if (move_uploaded_file($_FILES['upload']['tmp_name'],
"uploads/{$_FILES['upload']['name']}"))
{
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\') )
{
$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/thankyoupage.html'; // Add the page.
header("Location: $url");

}
else
{ // Couldn't move the file over.

echo '<p><font color="red">The file could not be uploaded because: </b>';

// Print a message based upon the error.
switch ($_FILES['upload']['error']) {
case 1:
print 'The file exceeds the upload_max_filesize setting in php.ini.';
break;
case 2:
print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
break;
case 3:
print 'The file was only partially uploaded.';
break;
case 4:
print 'No file was uploaded.';
break;
case 6:
print 'No temporary folder was available.';
break;
default:
print 'A system error occurred.';
break;
} // End of switch.

print '</b></font></p>';

} // End of move... IF.

} else { // Invalid type.
echo '<p><font color="red">Please upload a JPEG or GIF image.</font></p>';
unlink ($_FILES['upload']['tmp_name']); // Delete the file.
}

} //End checkbox if statement
} //End of uploading image if statement


if (empty($errors)) { // If everything's OK.
// This is the email the support forum is sent to... change it to what you want
$submitemail = "[email protected]";
$subject = "Email from Form";
$title = "Form Submission";
$fundraiserCode = trim($_POST['fundraiserCode']);
$email = trim($_POST['email']);
$message = "Title: {$title}\r\n";
$message .= "First Name: {$firstname}\r\n";
$message .= "Last Name: {$lastname}\r\n"; //Fixed varaible spelling error
$message .= "City: {$townPictures} \r\n";
$message .= "State: {$State} \r\n";
$message .= "Subject: {$pictureSubject} \r\n"; // Fixed variable spelling error
$message .= "Fundraiser code: {$fundraiserCode} \r\n";
$message .= "Actual Pictures in Email: {$_POST['actualPicturesEmail']} \r\n";
$message .= "Actual Pictures with Form: {$_POST['actualPicturesForm']} \r\n";
$message .= "Actual Pictures Printed: {$_POST['actualPicturesPrinted']} \r\n";

$mailHeader = "From: {$email}\r\n";
$mailHeader .= "Reply-To: {$email}\r\n";
$mailHeader .= "X-Mailer: PHP/" . phpversion();

mail($submitemail, $subject, $message, $mailHeader);

$mailHeader = "From: {$submitemail}\r\n";
$mailHeader .= "Reply-To: {$submitemail}\r\n";
$mailHeader .= "X-Mailer: PHP/" . phpversion();

$clientmessage = "Thank you {$firstname} for Submitting your pictures. This is an automated E-mail response, please do not respond to it.\r\n\n" . $message; //This is the message that will be sent to the User
mail($email, $subject, $clientmessage, $mailHeader);
} // End of Email
else
{
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred: foreach($errors as $msg) - $msg';

echo '</p><p>Please try again</p><p>'; }
}// End of the submitted conditional.
?>
<!--Start of HTML section-->
<html>
<head>
<title>Photos Around Town Form</title>
</head>
<body link="blue" vlink="purple" alink="red">

<!--Aussie Girl: I've taken this image out of the form tags, it wont work because
of the name, if it's suppose to be the background for the form try doing a search
for background images in forms if it's a banner leave it has I have changed to and upload the image into the same folder has this script or change the img scr path-->

<img src="backgroundforwebsite26mv.jpg" width="800" height="150" border="0">
<div align="center"><h2>Photos Around Town Form</h2></div>

<form enctype="multipart/form-data" name="Photos Around Town Form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<fieldset>The information below will be used solely for milling, organizational needs, and if contact is required.

<p>First Name: <input type="text" name="firstName">
Last Name: <input type="text" name="lastName"></p>
<p>Email Address: <input type="text" name="email" size="57"></p>
<p>Town picture(s) is/are being placed <input type="text" name="townPictures" > State <input type="text" name="State" size="9"></p>
<p>Picture Subject <input type="text" name="Subject"> Fundraiser Participant Code: <input type="text" name="fundraiserCode"></p>
<p>(For organizational purposes, please give us a unique name for your picture)</p>

<p>Please check this box <input type="checkbox" name="actualPicturesEmail" value="YES">if you are sending the actual picture(s) for this form via <u>email</u>.</p>
<p>Our email is:<a href="mailto:p[email protected]">[email protected]</a></p>

<p>Please check this box <input type="checkbox" name="actualPicturesForm" value="YES">if you are sending the actual picture(s) attached with <u>this form</u>.
<input type="file" name="upload" size="61"></p>
<input type="hidden" name="MAX_FILE_SIZE" value="524288">

<p>Please check this box <input type="checkbox" name="actualPicturesPrinted" value="YES">if you are enclosing the actual picture(s) with a printed copy of this form. You are also initialing here showing that you understand that hard copies of pictures that need to be scanned in, may lose some quality.</p>

<div align="center"><input type="submit" name="Submit" value="Submit Form">
<input type="reset" name="reset" value="Reset Form"></div>
<input type="hidden" name="submitted" value="YES" />
</fieldset>

</form>
Life Around TownAttn: Photos Around Town Dept.PO Box 171Marlton NJ 08053<p style="line-height:100%; margin-top:0; margin-bottom:0;"> </p>
</body>
</html>
 
Joined
Nov 22, 2004
Messages
414
here are some quick observations

Line 6
/* IMPORTANT NOTICE: Make sure that the <?php tag (above) is the first line, there cannot
** be anything above it, not even a blank line. If there is you will get "HEADERS already
** sent error messages
**Script modified by Gail Kasey 14/01/06
**modified by design1online.com 1/16/2005
*/

I corrected this bit as there was a mistype stoping the script from working.

if ((substr($url, -1) == '/') OR (substr($url, -1) == ‘\’) )
{
$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/thankyoupage.html'; // Add the page.
header("Location: $url");
}

line 16
this bit of code has a break in it so php recognises ‘ as the part of a string so you never close the ‘ at the end of the first line.
Would it not be easier at thi point just to use stripslashes() ?

Same again on line 63.

Same again on line 86

Line 169
You need to change:
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred: foreach($errors as $msg) - $msg';

to

echo '<h1 id="mainhead">Error!</h1><p class="error">The following error(s) occurred:<br>';
foreach($errors as $msg){echo $msg.'<br>';}

as this new way will display the errors, one after the other, each on a separate line.

Other than that I can’t see any other errors at a glance..

No offence but you code is very long winded and messy. You could have performed the same task with a quarter of the code.

If you have any more errors, mail me at: [email protected]

attached is a corected copy of your page.

harry
 

Attachments

CoopGamer3

Thread Starter
Joined
May 30, 2004
Messages
24
I sent you an email. The redirect worked but the info wasn't sent nor was the pictures.
Thanks in advance
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top