Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-17-2007, 02:33 PM Making a simple form
Skilled Talker

Posts: 58
Trades: 0
How would I make a simple form, that just asked for name, email address, and then had a text box for you to enter your comments/questions - and then of course, for it to email any information entered to me.

I would like for the form to not have any advertising, and once information is submitted I would just like the contact form to be cleared and the person to be kept on the same page.

Any help is always appreciated, and even if you just know of a good tutorial that would be great too.

Thank you!
lilycup is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-17-2007, 02:39 PM Re: Making a simple form
Extreme Talker

Posts: 182
Trades: 0
I think building a simple contact form is one of the best things for beginners.

http://www.phpeasystep.com/phptu/8.html

This is just a link that came up when I googled for php contact forms. I just skimmed over it but it looks like it may be easy to follow and helpful to you.

Give it a shot and post back if you have any questions about it.
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 02:48 PM Re: Making a simple form
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
The php in that tutorial is good but the markup is appalling (Yes its that annoying standards guy again).

For forms the basic principle is :

Code:
<form>
<fieldset>
<legend></legend>
<label></label><input/>
</form>
Not a table in site Any more help you need on forms I will be happy to give you some information.

To redirect the php back to the same page use the header function with the Location segment. The rest of the code in the tutorial is fine, although make sure you validate.

Jamie
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-17-2007, 04:52 PM Re: Making a simple form
Skilled Talker

Posts: 58
Trades: 0
Thank you, both, for your replies. They're very helpful (not annoying!).

I am having some difficultly though, with making the form look the way I would like it do without using a table.

On this page: http://www.alphaberrydesign.com/contact.php the top example is using tables, and that is how I would like to use it but without using the tables.

I'm also a little confused on redirecting the php back to the same page. And how would I make the email section required to fill in?

Thank you so much for your help! (Also, the page doesn't validate but once I've figured it all out I will move on to making it validate).
lilycup is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 05:03 PM Re: Making a simple form
Extreme Talker

Posts: 182
Trades: 0
I would focus on getting the code to work properly, then the display.

You have a few options if you would like to submit the form to the same page:

PHP Code:
<form action="<?=$_SERVER['PHP_SELF']?>".....
That can be spoofed though I believe. However, I think it will work fine for whatever you are doing right now.

Alternatively:

PHP Code:
<form action="?param1=value1&param2=value2" ....... 
That will also submit to itself. The parameters are optional of course
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 06:03 PM Re: Making a simple form
Skilled Talker

Posts: 58
Trades: 0
Thank you for the reply, I appreciate your help. I thought this would only take an hour or so but it's quickly turning into a nightmare.

The only way I was able to get it to work was by was by pasting the php code into the contact.php page under the head section. Is it ok to do this?
lilycup is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 06:49 PM Re: Making a simple form
extra.account's Avatar
Average Talker

Posts: 25
Trades: 0
Hey

I know it can be a bit frustration at times, but take your time
Does it HAVE to be all on the same page? Its easier just using 2 pages and $_POST 'ing the data on the 2nd page etc.
extra.account is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 06:51 PM Re: Making a simple form
Skilled Talker

Posts: 58
Trades: 0
It doesn't have to be on the same page, and the more I think about it I think it would be better to be across two pages.

Thank you for your help
lilycup is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 08:14 PM Re: Making a simple form
Skilled Talker

Posts: 58
Trades: 0
Ok, I've nearly completed this with everyone's help and looking around at tutorials. Thank you, everyone!

The last thing is that every time the page is refreshed, I am sent an email (it's blank unless information is submitted) regardless of whether any text was entered or not.

This is the code:

Code:
<?php


$subject = "Inquiry from Alphaberry Design";


$message="$comments";


$mail_from="$email";


$header="from: $name <$mail_from>";


$to ='holly@alphaberrydesign.com';

$send_contact=mail($to,$subject,$message,$header);

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<link rel="stylesheet" href="alphaberrystyle.css" type="text/css" />

<title>Alphaberry Design - Content Sent</title>



</head>

<body>

<object>
<p class="sentpage">
Thank you, your information has been sent and Alphaberry Design will be in touch with you shortly.
<br />
<br />
<a href="<?php print "http://www.alphaberrydesign.com"; ?>">Return to site.</a>
</p>
</object>


</body>
</html>
Does anyone know why it would do this?

Last edited by lilycup; 08-17-2007 at 08:54 PM.. Reason: Changed coding
lilycup is offline
Reply With Quote
View Public Profile
 
Old 08-18-2007, 07:22 AM Re: Making a simple form
extra.account's Avatar
Average Talker

Posts: 25
Trades: 0
Hey

Why is the page refreshing in the first place? If you refresh the page then the script will run again and, as you said, you will get sent nothing.

Is the script working at the beginning? Like do you recieve an email with the comments etc?
extra.account is offline
Reply With Quote
View Public Profile
 
Old 08-18-2007, 12:28 PM Re: Making a simple form
Skilled Talker

Posts: 58
Trades: 0
When I was creating the page, I would check it in Firefox and refresh everytime I made a change - it would then send me an email.

The script does work at the beginning, it does send me emails also when information is submitted.
lilycup is offline
Reply With Quote
View Public Profile
 
Old 08-18-2007, 12:50 PM Re: Making a simple form
extra.account's Avatar
Average Talker

Posts: 25
Trades: 0
Well thats going to happen because your running the script. The script runs exactly as before, except this time when it posts the data it finds nothing because you are simply refreshing the page and not re-entering the form.
extra.account is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Making a simple form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.23897 seconds with 12 queries