PDA

View Full Version : HTML help


cyrusmekon
2005-10-17, 12:08
Hi guys maybe one of you would be so kind to help.

First off i know very basic HTML and have been asked to make a "form" for our webpage. It does not need to be secure etc

I have made the form but would like the form emailed to me automatically when the user presses the submit button. I see you can send an email but this requires you to open up a mail client.

Can you do this task automatically. Like i say i know very basic HTML, searched the web a bit and found nothing obvious. Its 3AM what is at this time.

If anyone can help, lead me in the right direction that would be awsome.

I have attached the code i have done so far.

Regards, Cyrus.


<html>
<head>
<title>Register</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body bgcolor="ffffff">

<center>
<table border=0 width=75% height=80% cellpadding=10 cellspacing=0>
<tr>
<td align=left valign=top> <p><IMG SRC="../titles/register.jpg" width="280" height="49" border=0></p>
<p>&nbsp;</p>
<div align="center">
<table width="75%" border="0">
<tr>
<td width="39%">&nbsp;</td>
<td width="61%"><div align="left"><strong>Personal details</strong></div></td>
</tr>
<tr>
<td><div align="right"><strong>&nbsp;Name*</strong></div></td>
<td><form name="form2" method="post" action="">
<label>
<input type="text" name="textfield7">
</label>
</form></td>
</tr>
<tr>
<td><div align="right"><strong>Street Address:</strong></div></td>
<td><form name="form3" method="post" action="">
<label>
<input type="text" name="textfield8">
</label>
</form></td>
</tr>
<tr>
<td><div align="right"><strong>Address (Cont)</strong>
<label> </label>
</div></td>
<td><form name="form4" method="post" action="">
<label>
<input type="text" name="textfield9">
</label>
</form></td>
</tr>
<tr>
<td><div align="right"><strong>Country
<label> </label>
</strong>
<label></label>
</div></td>
<td><form name="form6" method="post" action="">
<label>
<input type="text" name="textfield11">
</label>
</form></td>
</tr>
<tr>
<td><div align="right"><strong>Tel #
<label> </label>
</strong></div></td>
<td><form name="form7" method="post" action="">
<label>
<input type="text" name="textfield12">
</label>
</form></td>
</tr>
<tr>
<td><div align="right"><strong>Email*
<label> </label>
</strong>
<label></label>
</div></td>
<td><form name="form5" method="post" action="">
<label>
<input type="text" name="textfield10">
</label>
</form></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</div>
<p>*Required fields</p>
</TD>
</tr>



<tr><td align=left valign=middle bgcolor="9ea4ed">
<p><br>
<a href="../index.html"><IMG SRC="../titles/back.jpg" border=0 align=right></a>
</td></tr></table>
</center>
</body></html>

staph
2005-10-17, 12:14
Do you have php on your web server? You could build a very simple form handler to send the mail with php's built-in email functionality.

Brad
2005-10-17, 12:14
Instead of action="" try action="mailto:youraddress@yourdomain.com" in the form tag.

Also, you only want one opening form tag at the beginning before your inputs and one closing form tag at the end after your submit button.

For example:

<form method="post" action="mailto:name@server.com">
<input type="text" name="name" />
<input type="text" name="address1" />
<input type="text" name="address1" />
<input type="text" name="country" />
<input type="text" name="telephone" />
<input type="text" name="email" />
<input type="submit" name="Submit" value="Submit" />
</form>

staph
2005-10-17, 12:16
Instead of action="" try action="mailto:youraddress@yourdomain.com" in the form tag.


Wouldn't that open up the mail client like he didn't want?

Brad
2005-10-17, 12:20
Yeah. *scratches head* Hmm... I know there was a way to do this. It's been a long time, but I used to write forms that did this.

cyrusmekon
2005-10-17, 12:22
Thanks for the replies

Staph you are right, when the user presses the submit button i would like everything to be automatic, that is all input fields emaild to a given email address without a mail client being involved.


I am positive we have php on our server. How would you build such a form from the built in email functionality?

Sorry im a bit out my depth here but would love to learn.

Appreciate your time.

staph
2005-10-17, 12:27
Right, here's some sample code on how to do a simple email handler. Make the action of the submit button a page with this code in it somewhere.

You'll want to have a line lie $string = "POST['string']"; for each of your strings, with the name in the square brackets, and a unique variable name ($string for each). The next line ($uberstring = $string . $string2) concatenates them together with a newline in between.

I'm not a php person normally, so if I've done anything egregiously wrong, please point it out!

<?php

$uberstring = $string . "\n" . $string2;
// concat your strings with the . symbol
// between each string to be concatenated

$to = 'nobody@example.com';
$subject = 'the subject';
$message = $uberstring;
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers); //send the mail!

?>

BTW: this code sample is largely from the PHP mail documentation page, which can be found here (http://www.php.net/manual/en/function.mail.php)

Edit2: PHP syntax highlighting is way cool!

Brad
2005-10-17, 12:32
PHP? Oh, that makes it EASY. :)

1. Be sure the fields have unique names like in my example.
2. Create a file called something.php and make it the target of that form.
3. Make something.php look like this:

<html>
<head>
<title>Thank you!</title>
</head>
<body>

<p>This is a confirmation page... blah blah blah...</p>

<?php
$to = "you@domain.com";
$subject = "Form Submission";
$body = "Form Results: \n\n";
$body = $body."Real Name: $name \n";
$body = $body."Address Line 1: $address1 \n";
$body = $body."Address Line 2: $address2 \n";
$body = $body."Country: $country \n";
$body = $body."Telephone Number: $phone \n";
$body = $body."Email Address: $email \n";
if (mail($to, $subject, $body))
{ ?>

<p>Message successfully sent!</p>
<p>Click <a href="somewhere.html">here</a> to return to the main page</p>.

<?php} else {?>

<p>Message delivery failed...</p>
<p>Click <a href="somewhere.html">here</a> to return to the main page</p>.

<?php }?>

</body>
</html>


Note that $address1 will correspond to the field whose name was address1. You can add or change those as needed.

edit: yeah, staph's on the right track. Curse my slow fingers. :(

staph
2005-10-17, 12:37
Yeah, but your script is more robust than mine.

staph
2005-10-17, 12:39
Note that $address1 will correspond to the field whose name was address1. You can add or change those as needed.

So you don't need to explicitly get them from the POST query? Nifty!!

cyrusmekon
2005-10-17, 12:39
Wow you guys are quick

Its 3.37am here (Australia).

Im going to give this a go when i wake up in the morning.

Thank you and i will aknowledge you guys (in the code)
:D

staph
2005-10-17, 12:40
Hey, I'm in Australia too.

I'm not planning to go to bed for probably another 5 hours tho'. Damn thesis.

Brad
2005-10-17, 12:41
So you don't need to explicitly get them from the POST query? Nifty!!
Nope! At least, I don't and I've never had a problem with it. :)

staph
2005-10-17, 12:45
Nope! At least, I don't and I've never had a problem with it. :)

God, that's almost reason enough to give up on on Perl for CGI.

deuce868
2005-10-17, 13:26
Nope! At least, I don't and I've never had a problem with it. :)
That only works if the server has REGISTER_GLOBALS turned on. Many hosts have that turned off these days and consider it a security risk.

As someone that writes code, it's so much better to put $_POST/$_GET because then at least when someone else reads the form they can tell where in the world this $address variable comes from.

See this for more info:
http://us3.php.net/manual/en/security.globals.php

Brad
2005-10-17, 19:47
Huh! I didn't know that. I guess I've just been lucky all these years. Thanks for the information. :)

cyrusmekon
2005-10-17, 21:46
Hi well iv wokn from the land of the dead

I have been doing a bit of searching

http://tools4php.com/form-wizard/index.html

Does this look like a waste of money? It seems very appealing to me. It will do what i want and quickly.

The autoresponder etc would be a nice touch. WOrth $19.95.

Remember i have NO experiance with this at all, just basic HTML.

Brad
2005-10-17, 21:49
Well, it's Windows-only. So, that may answer your question immediately.

I've never used that kind of code-generating tool; so, I can't vouch for its usefulness.

cyrusmekon
2005-10-17, 21:55
Windows based is not a problem, im at work slowly converting the masses. Hey i have added 5 new Mac users since i got here.

Yes the generator is appelaing just for the fact i may not have to deal with script, but 19.95 thats what im trying to decide.

Any feedback from anyone using a generator would be greatfull.

Brad
2005-10-17, 22:11
Well, look at it this way:

How much do you get paid per hour? Divide $19.95 by that number to see how much it's really "worth" to you in work-hours. If you get paid $20 an hour at your job, that means it's worth one hour of your time. You've probably spent more than that much time researching these options; so, it could have more than paid for itself by now!

That's one of the best ways to gauge if any software title is worth buying versus inventing/writing your own implementation that does the same task. :) Actually, a good way of gauging the value of any purchase is by comparing it to how much you have to work to pay for it.

Of course, you also need to weigh another important factor: would you want to learn PHP enough so you could understand how the script works (or write your own) and customize it in the future? Say it takes 10 hours to learn and try out the PHP features that you'd need for this form e-mailer. At the $20/hr wage mentioned above, that's a $200 "cost" to get the job done. Now, if learning PHP would be a waste of your time and you never plan to use it again, purchasing the product is the better option. If you think you would benefit in the future by learning PHP now, then that $200 "cost" is significantly offset and may be better than just buying the product.

Did I answer your question with more questions? :p

Well, I hope it helps a little.

LudwigVan
2005-10-18, 01:04
Is someone taking an econ class this semester?

Brad
2005-10-18, 01:16
No. :lol: Though, I did have one two (or was it three?) years ago.

I recently had to explain this whole "value of software" to someone in the Real World™ and it was all still fresh in my mind, I guess. :p

deuce868
2005-10-18, 06:05
the problem with generators is the first time you need something that doesn't have a checkbox in the generator you're back to square one needing to learn how to do it. Not only that, but you're trusting the generator to build something secure, scalable, and when you have issues with it you still have to learn it and figure out what's wrong.

If it works for you cool, but I've never been a fan. I started out with dreamweaver writing my php for me until I had to make my pages do things DW didn't support and then I just had to learn it all and write it by hand anyway. It's usually better that way.