Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1171 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Building a secure contact form

Thread title: Building a secure contact form
Closed Thread  
Page 3 of 4 < 1 2 3 4 >
    Thread tools Search this thread Display Modes  
05-25-2008, 04:57 PM
#21
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

Originally Posted by enigma View Post
Simple way is like this;

PHP Code:
<?php

if($email == "") {

echo 
"You must enter your email!";

} else {

mail();

}

?>
But you add as many error check as you like. Expanding on the above..

PHP Code:
<?php

if($name == "") {

echo 
"Give me your name dammit!";

}

if(
$subject == "") {

echo 
"Enter a subject!";

}

if(
$email == "") {

echo 
"You must enter your email!";

} else {

if(
$comments == ""){

echo 
"Comments - Empty!";

} else {

mail();

}

?>
Well, not only have you not finished an if statement in there, that's a horrid way of doing it. Just use elseifs, otherwise they could send an email without entering a name or a subject.

05-25-2008, 05:08 PM
#22
Vizon is offline Vizon - Click for my Image
Status: R'tard
Join date: Jan 2007
Location: USA
Expertise:
Software:
 
Posts: 2,959
iTrader: 21 / 100%
 

Vizon is an unknown quantity at this point

  Old

Originally Posted by ncmason View Post
In something like this, how would I be able to use CSS for the fonts?

PHP Code:
echo "<span class=\"red\">Provide a name please!</span>"
Code:
.red {
     color: red;
     margin-bottom: 10px;
}
Edited.

05-25-2008, 05:13 PM
#23
mason.sklut is offline mason.sklut
mason.sklut's Avatar
Status: Junior Member
Join date: Mar 2007
Location: North Carolina
Expertise: Photography
Software:
 
Posts: 73
iTrader: 0 / 0%
 

mason.sklut is on a distinguished road

  Old

Thanks Vizon. I was trying this earlier and I had the quote mark one spot off. I was close, but no cigar

Appreciate it,
Mason

05-25-2008, 05:15 PM
#24
Vizon is offline Vizon - Click for my Image
Status: R'tard
Join date: Jan 2007
Location: USA
Expertise:
Software:
 
Posts: 2,959
iTrader: 21 / 100%
 

Vizon is an unknown quantity at this point

  Old

No problem, you may have to throw a "display: block;" in there to make the margin work.

05-25-2008, 05:22 PM
#25
mason.sklut is offline mason.sklut
mason.sklut's Avatar
Status: Junior Member
Join date: Mar 2007
Location: North Carolina
Expertise: Photography
Software:
 
Posts: 73
iTrader: 0 / 0%
 

mason.sklut is on a distinguished road

  Old

Thanks for the tip! It works.

I'm still working on making the form not send me an email with empty fields.

05-25-2008, 05:32 PM
#26
Vizon is offline Vizon - Click for my Image
Status: R'tard
Join date: Jan 2007
Location: USA
Expertise:
Software:
 
Posts: 2,959
iTrader: 21 / 100%
 

Vizon is an unknown quantity at this point

  Old

Update us with your code.

05-25-2008, 06:00 PM
#27
mason.sklut is offline mason.sklut
mason.sklut's Avatar
Status: Junior Member
Join date: Mar 2007
Location: North Carolina
Expertise: Photography
Software:
 
Posts: 73
iTrader: 0 / 0%
 

mason.sklut is on a distinguished road

  Old

PHP Code:
<?php

// Pick up the form data and assign it to variables

    
$name $_POST['name'];
    
$email $_POST['email'];
    
$url $_POST['url'];
    
$comments $_POST['comments'];

// Build the email 

    
$to 'mason@masonsklut.com';
    
$subject "Comment";
    
$message "Name: $name"\n"  "E-mail: $email"\n" "URL: $url"\n" "Comment: $comments";
    
$headers "From: $name"\r\n" .
        
"Reply-To: $email";

// Send the mail using PHPs mail() function

    
mail($to$subject$message$headers);


// Mail header removal

    
function remove_headers($string) { 
      
$headers = array(
        
"/to\:/i",
        
"/from\:/i",
        
"/bcc\:/i",
        
"/cc\:/i",
        
"/Content\-Transfer\-Encoding\:/i",
        
"/Content\-Type\:/i",
        
"/Mime\-Version\:/i" 
      
); 
      
$string preg_replace($headers''$string);
      return 
strip_tags($string);
    } 

// Pick up the cleaned form data

    
$name remove_headers($_POST['name']);
    
$email remove_headers($_POST['email']);
    
$url remove_headers($_POST['url']);
    
$comments remove_headers($_POST['comments']);
    
// Field verification

        
if($name == "") { 
    
    echo 
"<span class=\"text\"><p>Provide a name please!</p></span>"
    
    }
    
    if(
$subject == "") { 
    
    echo 
"<span class=\"text\"<p>Enter a subject!</p></span>"
    
    } else {
    
    if(
$email == "") { 
    
    echo 
"<span class=\"text\"<p>You must enter your email!</p></span>"
    
    } else { 
    
    
mail(); 
    
    } }
?>
My 3 problems now are:

1. Getting the success page to come up only upon valid completion of the forms.

2. Only send an email if the forms are complete.

3. When the user sees the "go back and try it again" page, I want it to automatically go back to the form.

Thanks,
Mason

05-25-2008, 09:05 PM
#28
thebluenote is offline thebluenote
Status: Junior Member
Join date: May 2008
Location: NY
Expertise:
Software:
 
Posts: 39
iTrader: 0 / 0%
 

thebluenote is on a distinguished road

Send a message via AIM to thebluenote

  Old

Originally Posted by ncmason View Post
PHP Code:
<?php

// Pick up the form data and assign it to variables

    
$name $_POST['name'];
    
$email $_POST['email'];
    
$url $_POST['url'];
    
$comments $_POST['comments'];

// Build the email 

    
$to 'mason@masonsklut.com';
    
$subject "Comment";
    
$message "Name: $name"\n"  "E-mail: $email"\n" "URL: $url"\n" "Comment: $comments";
    
$headers "From: $name"\r\n" .
        
"Reply-To: $email";

// Send the mail using PHPs mail() function

    
mail($to$subject$message$headers);


// Mail header removal

    
function remove_headers($string) { 
      
$headers = array(
        
"/to\:/i",
        
"/from\:/i",
        
"/bcc\:/i",
        
"/cc\:/i",
        
"/Content\-Transfer\-Encoding\:/i",
        
"/Content\-Type\:/i",
        
"/Mime\-Version\:/i" 
      
); 
      
$string preg_replace($headers''$string);
      return 
strip_tags($string);
    } 

// Pick up the cleaned form data

    
$name remove_headers($_POST['name']);
    
$email remove_headers($_POST['email']);
    
$url remove_headers($_POST['url']);
    
$comments remove_headers($_POST['comments']);
    
// Field verification

        
if($name == "") { 
    
    echo 
"<span class=\"text\"><p>Provide a name please!</p></span>"
    
    }
    
    if(
$subject == "") { 
    
    echo 
"<span class=\"text\"<p>Enter a subject!</p></span>"
    
    } else {
    
    if(
$email == "") { 
    
    echo 
"<span class=\"text\"<p>You must enter your email!</p></span>"
    
    } else { 
    
    
mail(); 
    
    } }
?>
My 3 problems now are:

1. Getting the success page to come up only upon valid completion of the forms.

2. Only send an email if the forms are complete.

3. When the user sees the "go back and try it again" page, I want it to automatically go back to the form.

Thanks,
Mason

1. Just put a redirect under the mail function to a page that you make that says success.

2. Use the elseifs like Andrew said

3. Just use one echo to say "please enter information for all fields" if the email doesn't go through.

05-25-2008, 09:45 PM
#29
mason.sklut is offline mason.sklut
mason.sklut's Avatar
Status: Junior Member
Join date: Mar 2007
Location: North Carolina
Expertise: Photography
Software:
 
Posts: 73
iTrader: 0 / 0%
 

mason.sklut is on a distinguished road

  Old

1. I'm not sure how to use the elseifs with three variables ($name, $subject, $email).

2. The "header" method for redirect won't work because I have <html> on the same page. Ideas?

Thanks,
Mason

05-26-2008, 02:30 AM
#30
thebluenote is offline thebluenote
Status: Junior Member
Join date: May 2008
Location: NY
Expertise:
Software:
 
Posts: 39
iTrader: 0 / 0%
 

thebluenote is on a distinguished road

Send a message via AIM to thebluenote

  Old

Well for the redirect just use a div saying success and then reveal it when the mail message goes through. I'm not an expert so does this make sense guys?

Closed Thread  
Page 3 of 4 < 1 2 3 4 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed