Jump to content


creating a form problem


42 replies to this topic

#1 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 21 December 2005 - 01:09 PM

Hello i have never tried to create a form on a site so this is my first attempt.

www.retrodesigner.co.uk/contact.html

i selected the fields and set it up following a guide but when i click n the send button it just opne my mail client and none of the data inputted is there. not sure where i have gone wrong

and is there anway improve the look of he boxes and line them up?

any help would be great thanks

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 December 2005 - 01:49 PM

Since it has a mailto: action, all it will do is open your e-mail client, and add the attributes to the message body of the e-mail. The rest of the info has to be filled out by hand, or you can use the onSubmit attribute of the form to modify the action so it auto-fills out some of the fields for you. Look in the JavaScript section of the tutorial database, i believe there's something in there about this.

Although, the easiest way to handle contact forms is through a server-side language like PHP, which i would recommend looking into (i know there are a ton of tutorials on how to do it in the database).

And i know i'm going to get yelled at for this, but the easiest way to organize a form is with a table.

Edited by rc69, 21 December 2005 - 01:51 PM.


#3 _*Raremandan_*

  • Guests

Posted 21 December 2005 - 09:47 PM

Now this is a tutorial off Pixel2life.com

But i'll post it here as you probably don't want too go reading through tutorials.

<html>

<head>

<title>Comments</title>

</head>

<body><form action="mail.php" method="post">

Your Name: <input type="text" name="name"><br>

E-mail: <input type="text" name = "email"><br><br>

Your Comments:<br>

<textarea name="comment"></textarea><br><br>

<input type="submit" value="Tell Us!">

</form>

</body>

</html>

Now you can change the boxes and stuff they ask etc.

And now for the basic PHP bit you must call the PHP file mail.php

 <? 

$name=$_POST['name']; 

$email=$_POST['email']; 

$comment=$_POST['comment']; 

$to="Write you email address here, it will not be visible"; 

$message=" $name sent you a comment on your site.\n They said $story\n\n Their e-mail address was: $email"; 

if(mail($to,"Comments From Your Site",$message,"From: $email\n")) { 

echo "Your form was succsessful, write what you want here"; 

} else { 

echo "The form didn't send, you can write some kind of messege here when your form has failed."; 

} 

?>

Now I edited the form so it tell you exactly where too put your e-mail address.

Good luck :D

- Dan

#4 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 03 January 2006 - 07:38 AM

Hi dan

Thanks for the help, i have just got round to trying that and it works, just a few questions though, hope you or someone can help me.

1-when the send button is pressed i get a message saying it has been sent bu this just opens on a blank page with the text and then there is no option to go back to the site, is it possible to have the message go to a page of the site?

2- in the PHP file there is an option for if there is an error but when tested i can leave some section of the form empty and it still sends, so theerror message does not work, is it possible to set the form up so that if a section is not completed that the form will not send?

any help would be great, thanks

#5 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 03 January 2006 - 09:05 AM

1. You can easily change that by adding your own html or redirecting the users to another page with the header function.
if you want to redirect them replace this
echo "Your form was succsessful, write what you want here";
with this
header('location: succespage.php');
====
2. The form is send no matter what, because there is simply NO error checking.

#6 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 03 January 2006 - 09:43 AM

View PostAvalanche, on Jan 3 2006, 02:05 PM, said:

1. You can easily change that by adding your own html or redirecting the users to another page with the header function.
if you want to redirect them replace this
echo "Your form was succsessful, write what you want here";
with this
header('location: succespage.php');
====
2. The form is send no matter what, because there is simply NO error checking.
Thanks avalanche,

ihave just had a look at that,

i changed my line to

header('location: aboutrd.html');

but i still seem to load up the original page, this can be viewed at http://www.retrodesi...uk/contact.html

#7 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 03 January 2006 - 02:48 PM

You sure you uploaded your files, because 'aboutrd.html' doesnt seem to be there either

#8 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 04 January 2006 - 07:22 AM

View PostAvalanche, on Jan 3 2006, 02:05 PM, said:

1. You can easily change that by adding your own html or redirecting the users to another page with the header function.
if you want to redirect them replace this
echo "Your form was succsessful, write what you want here";
with this
header('location: succespage.php');
====
2. The form is send no matter what, because there is simply NO error checking.
How do i add error checking? thanks

#9 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 04 January 2006 - 09:58 AM

this should work...

<? 

$name=$_POST['name']; 

$email=$_POST['email']; 

$comment=$_POST['comment']; 

$to="Write you email address here, it will not be visible"; 

$message=" $name sent you a comment on your site.\n They said $story\n\n Their e-mail address was: $email"; 

if(!empty($name) || !empty($email) || !empty($comment)){

	if(mail($to,"Comments From Your Site",$message,"From: $email\n")) { 

	echo "Your form was succsessful, write what you want here"; 
}
} else { 

echo "PLEASE FILL IN ALL FIELDS!!!!!!."; 

} 

?>

edit: fixed a parse error :)

Edited by Avalanche, 04 January 2006 - 09:58 AM.


#10 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 04 January 2006 - 10:49 AM

View PostAvalanche, on Jan 4 2006, 02:58 PM, said:

this should work...

<? 

$name=$_POST['name']; 

$email=$_POST['email']; 

$comment=$_POST['comment']; 

$to="Write you email address here, it will not be visible"; 

$message=" $name sent you a comment on your site.\n They said $story\n\n Their e-mail address was: $email"; 

if(!empty($name) || !empty($email) || !empty($comment)){

	if(mail($to,"Comments From Your Site",$message,"From: $email\n")) { 

	echo "Your form was succsessful, write what you want here"; 
}
} else { 

echo "PLEASE FILL IN ALL FIELDS!!!!!!."; 

} 

?>

edit: fixed a parse error :)

is that that i need to add the last echo command?

whats a parse error?

thanks

#11 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 04 January 2006 - 12:09 PM

this is what i added, it has nothing to do with the last echo command, i should've left it as it was to prevent confusion.
if(!empty($name) || !empty($email) || !empty($comment)){

	if(mail($to,"Comments From Your Site",$message,"From: $email\n")) { 

	echo "Your form was succsessful, write what you want here"; 
}
it simply checks if the fields are NOT empty, if they are not, the form will be send, else it will echo the error

#12 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 04 January 2006 - 12:11 PM

ah right i get you know

i will make the changes thanks

#13 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 04 January 2006 - 02:45 PM

i added those changes but the form still sends

#14 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 04 January 2006 - 04:32 PM

well im clueless from here, because it really should NOT send... lol

#15 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 04 January 2006 - 04:40 PM

Here is what i have can you just check incase i missed something or added something i shouldnt have done

<? 

$name=$_POST['name']; 

$email=$_POST['email']; 

$comment=$_POST['question']; 

$to="enquiries@retrodesigner.co.uk"; 

$message=" $name sent you a comment on your site.\n They asked $question\n\n Their e-mail address was: $email"; 

if(!empty($name) || !empty($email) || !empty($comment)){

	if(mail($to,"Comments From Your Site",$message,"From: $email\n")) { 

	echo "Your form was succsessful, write what you want here"; 
}else { 

echo "Sorry, there was a problem with your question please try again."; 

} 

?>


#16 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 04 January 2006 - 04:43 PM

Lol, i know what your problem is (and i'm laughing because i missed it on my first read through this :)). The wrong operator was used in your if-statement. We want to make sure EVERYTHING is filled out, not one "or" the other thing ;)
if(!empty($name) || !empty($email) || !empty($comment)){
// Needs to be
if(!empty($name) && !empty($email) && !empty($comment)){

Edited by rc69, 04 January 2006 - 04:44 PM.


#17 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 04 January 2006 - 04:52 PM

lol yeah, my mistake :)

#18 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 04 January 2006 - 05:30 PM

thanks i will try that and make he changes

#19 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 06 January 2006 - 03:56 AM

I have just made the changes and tested and now it the form wont send and i get the following

Parse error: parse error in /home/httpd/vhosts/retrodesigner.co.uk/httpdocs/mail.php on line 24


which seems odd as there is no line 24.

Any Ideas?

cheers.

RESULT: after it not working i have just scrapped that file and started agin from the top of this post and although i am sure i just copied an pasted last time, this time when i have copied it it seems to work, so thanks for all your help guys much appreciated.

ARGH!!!!

now the form wont return to a webpage when form is sent.

here is my code, what is wrong? please

<? 

$name=$_POST['name']; 

$email=$_POST['email']; 

$comment=$_POST['question']; 

$to="Write you email address here, it will not be visible"; 

$message=" $name sent you a comment on your site.\n They said $story\n\n Their e-mail address was: $email"; 

if(!empty($name) && !empty($email) && !empty($question)){

	if(mail($to,"Comments From Your Site",$message,"From: $email\n")) { 

	header('location: index.html');
 
}
} else { 

header('location: contact.html');
 

} 

?>

Edited by donkeymusic, 06 January 2006 - 04:10 AM.


#20 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 06 January 2006 - 06:28 AM

yeah they header function sometimes doesnt work for some reason....
try meta refresh instead
echo '<meta http-equiv="refresh" content="0;url=index.html">';
exit();






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users