I am new at php I am creating my own contact form for my site. But don't know how to get started are there any tutorials for this. Thanks in advance.
contact form with logo tutorial
Started by midnightrose2008, Jun 25 2008 09:16 AM
35 replies to this topic
#1
Posted 25 June 2008 - 09:16 AM
|
|
|
#2
Posted 25 June 2008 - 10:44 AM
It's really simple. Just create a <form> object, and point it to the PHP script using the "action" attribute. Then, create the input controls such as text boxes within the form, assigning them unique names. Add a submit button, then the browser will automatically send the data to the PHP file, putting the data in either the $_GET[] or $POST[] array variable. Just grab the data, pop it in a mail() function (perhaps with some validation first) and you're done.
This will get you started: PHP Mail.
This will get you started: PHP Mail.
#3
Posted 25 June 2008 - 11:34 AM
Xav explained it really well but your gonna need a SMTP server to send the mail and validating the input would be good to learn how to do when your learning. :D learn good habits from the beginning :)
good luck :D
good luck :D
#4
Posted 25 June 2008 - 11:43 AM
Yes, I did explain it really well... ;)
You're absolutely right. You also need an email address to receive the messages... :)
And as for validating input, John did an excellent validation class at http://forum.codecal...tion-class.html.
Here's the code to save you going there:
You're absolutely right. You also need an email address to receive the messages... :)
And as for validating input, John did an excellent validation class at http://forum.codecal...tion-class.html.
Here's the code to save you going there:
<?php
/**
* @author John Ciacia
* @copyright 2008
*/
class Validator
{
const ALPHA = 1;
const NUMBER = 2;
const ALPHNUM = 3;
const UPPER = 4;
const LOWER = 5;
function __construct()
{
}
//This function validates a string of a particular type.
//You can either pass in a number (1-5) or its defininion
//as defined above. If the string is of the valid type
//this function will return true. If the string is not
//of the valid type, it will return false.
static public function valid_string($input, $type)
{
switch ($type) {
//such a string can only contain alphabetical characters
case ALPHA:
if (preg_match('/^[a-z]+$/i', $input))
return true;
return false;
break;
//such a string can only contain numbers
case NUMBER:
if (preg_match('/^\d+$/', $input))
return true;
return false;
break;
//such a string can only contain numbers and alphabetical characters
case ALPHNUM:
if (preg_match('/^[a-zA-Z0-9]+$/i', $input))
return true;
return false;
break;
//such a string can only contain uppercase characters
case UPPER:
if (preg_match('/[A-Z]/', $input) && !preg_match('/[a-z]/', $input))
return true;
return false;
break;
//such a string can only contain lowercase characters
case LOWER:
if (!preg_match('/[A-Z]/', $input) && preg_match('/[a-z]/', $input))
return true;
return false;
break;
}
}
//This function checks whether an email address is valid. It is
//not perfect as it does not account for .museum email addresses
//however this tradeoff is preferable to the other downsides
//of allowing it.
static public function valid_email($input)
{
if (!eregi("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", $input)) {
return false;
}
return true;
}
//This function checks whether a string is within certain size constraints.
//For example, the required length of a password might be 5 characters. Setting
//$min to 5 will require the password to be larger than or equal to five
//characters. If not, it will display an error message. If either $max
//or $min is set to 0, length checking is ignored on that constraing. The max
//constraint might be set on a contact form, where the text entered should
//not be any longer than 250 characters.
static public function valid_size($input, $min = 0, $max = 0)
{
//check the minimum size constraints
//in this case: the string needs to be longer
if (strlen($input) < $min) {
return false;
}
//check the maximum size constraints
//in this case: the string is too long
if (($max != 0) && (strlen($input) > $max)) {
return false;
}
return true;
}
}
?>
#5
Posted 25 June 2008 - 12:05 PM
Thanks, that will be really helpful *goes and does some random validating* :)
I wish i saw that class a long time ago :)
I use mercury mail to send and receive my email. Kinda cool that i setup my own email address :)
I wish i saw that class a long time ago :)
I use mercury mail to send and receive my email. Kinda cool that i setup my own email address :)
#7
Posted 25 June 2008 - 12:35 PM
No it's a web server that sends emails to an email client like outlook. It doesn't send to things like gmail when you run it locally. Great for PHP :D
#8
Posted 25 June 2008 - 12:56 PM
#9
Posted 25 June 2008 - 01:02 PM
I would do that too but I don't have a place online to put a web site or a web site. :P
#10
Posted 25 June 2008 - 01:24 PM
chili5 said:
Thanks, that will be really helpful *goes and does some random validating* :)
I wish i saw that class a long time ago :)
I use mercury mail to send and receive my email. Kinda cool that i setup my own email address :)
I wish i saw that class a long time ago :)
I use mercury mail to send and receive my email. Kinda cool that i setup my own email address :)
If you need any other validations (or have any I've missed) let me know. I'd like to expand this class. I think it can be really helpful.
#12
Posted 26 June 2008 - 08:52 AM
I don't know if this was in your class or not but postal codes and zip codes?
Canada format: N2J 34F
UK format: A99 9AA
US zip code: 78350
just an idea? btw i have no idea how to use the class lol
Canada format: N2J 34F
UK format: A99 9AA
US zip code: 78350
just an idea? btw i have no idea how to use the class lol


Sign In
Create Account


Back to top









