Form Help Needed Please

This is a discussion on "Form Help Needed Please" within the PHP Forum section. This forum, and the thread "Form Help Needed Please are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 18th, 2006, 13:08
New Member
Join Date: Oct 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Form Help Needed Please

Could someone help me (walk me through) what is wrong or what is going wrong with my form.

Background Info:
I built a very large site using Serif Webplus 9.0 (drag & drop).
I originally used Frontpage for my form(s) but was told to drop Frontpage for numerous reasons.
So now, I am attempting to make a new form using Dreamweaver or NVU.

The major functions of the form is supposed to:
1. Send the filled out details to an email address. (photosaroundtown@lifearoundtown.com)
2. Send an uploaded picture file somewhere where I can access it for resizing & future posting.
3. Simultaneously redirect to another page in my site upon pushing the submit button. (www.lifearoundtown.com/thankyoupage.html)
4. Have the banner that I created actually show up at the top of the form to match the site.

Other notes:
I have been told by the creator that the code is correct. It is possible that I am not doing something else that needs to be done? It might be something little that most people take for granted & do all the time.
Any help you could shed on this would be greatly appreciated. Please keep in mind that I don't know code at all & need to be slowly walked through the process.
Thanks in advance

Here is the code:

<?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*/

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 = "PhotosAroundTown@LifeAroundTown.com";
$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)
{
echo " - $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:PhotosAroundTown@LifeAroundTown.com"> PhotosAroundTown@LifeAroundTown.com</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>
Reply With Quote

  #2 (permalink)  
Old Jan 21st, 2006, 16:58
Junior Member
Join Date: Jan 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Help Needed Please

No one will be able to tell you what is wrong since you have not said what isn't working with the form.

You have also posted the entire form. Good etiquette in these and other forums is to post only parts of your code that you are having trouble with rather than posting an entire code with hundred plus lines and saying "help me with this".

Take a look at the form, remove everything from it that you don't understand. Get a basic form working. If you don't know how to get a basic form working with php and mysql then do a search (Kevin Yank has a good book out and I think four chapters are available online) and find such an example.

Once you have a basic form that is working then add error checking to it.

Trying to run in the Boston Marathon when you have first started a fitness program is possible. It isn't likely though. It looks like you are doing something similar in having a large form, trying to do many things when you don't necessarily know the basics.

Post back here when you have simplified the form and have a specific question about a specific part of the code. Then work through it by adding other needed pieces as you understand them.
Reply With Quote
Reply

Tags
form, help, needed

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
very basic form prefill command needed antonyx JavaScript Forum 1 Apr 18th, 2008 12:09
Help needed with subscription form JewelEnterprises Web Page Design 6 Sep 3rd, 2007 11:48
Form Validation Help needed please chimp Web Page Design 4 Dec 2nd, 2006 22:38
Form security help needed moisea PHP Forum 3 Nov 6th, 2006 10:10
Form Help needed! Chris PHP Forum 3 Jul 2nd, 2006 20:08


All times are GMT. The time now is 07:16.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43