Home News Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | PHP form help


You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > Internet Discussion

PHP form help
Reply
 
Thread Tools
Old 25-09-2005, 20:27   #1
cf.geek
 
Join Date: Jun 2003
Services: Weddings, christenings, barmitzvahs and funerals.
Posts: 859
ntl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond repute
PHP form help

OK I've manged to generate a PHP form off some website, but I need to tweak it to my requirements

The code is as follows: -

PHP Code:
<?php
// Website Contact Form Generator 
// http://www.tele-pro.co.uk/scripts/contact_form/ 
// This script is free to use as long as you  
// retain the credit link  

// get posted data into local variables
$EmailFrom "nobody@example.com";
$EmailTo "nobody@example.com";
$Subject "subject subject";
$Name Trim(stripslashes($_POST['Name'])); 
$Email Trim(stripslashes($_POST['Email']));
 

// validation
$validationOK=true;
if (!
$validationOK) {
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body "";
$Body "blah blah blah";
$Body .= "\n";
$Body .= "\n";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";



// send email 
$success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
}
else{
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
How do I get it to check that the form has been filled in correctly - and if it's not displaying an error message on screen. This form supposedly has error checking built in but it doesn't seem to work and you can type in nothing and it still says it's OK and sends a blank email.

Also, how do I get it to so that it gets IP address of the computer sending the form and the browser's user agent string so one can see what they're using - i.e. firefox/ie/opera/safari etc and pasts it in an email?

The current output in the emails is like this: -

Quote:
blah blah blah

Name: ada

Email: dasdada@zzz.com
Ideally I would like it to be like this: -

Quote:
blah blah blah

Name: ada

Email: dasdada

User agent: (UA string here)

IP address: (IP here)
I am not too knowledgeable on PHP, so if someone could rustle me up something then I'd be very grateful.

Thank you.
ntl customer is offline   Reply With Quote
Old 25-09-2005, 20:38   #2
cf.mega poster
 
Bifta's Avatar
 
Join Date: Jul 2003
Location: Derry
Posts: 7,597
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP form help

You could try adding

$body .= $agent['browser'];

(with the rest of the $body content)

Can't guarantee it'll work though.
Bifta is offline   Reply With Quote
Old 25-09-2005, 22:00   #3
cf.geek
 
Join Date: Jun 2003
Services: Weddings, christenings, barmitzvahs and funerals.
Posts: 859
ntl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond reputentl customer has a reputation beyond repute
Re: PHP form help

Quote:
Originally Posted by Bifta
You could try adding

$body .= $agent['browser'];

(with the rest of the $body content)

Can't guarantee it'll work though.
Sadly it doesn't.
ntl customer is offline   Reply With Quote
Old 26-09-2005, 01:15   #4
Eric Cartman Wannabe
 
punky's Avatar
 
Join Date: Jun 2003
Location: Cockney geeza land
Age: 27
Services: c:\> net start punky
Posts: 12,086
punky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver bling
punky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver blingpunky has a lot of silver bling
Re: PHP form help

To stop sending blank emails, the easiest way, but not most elegant would be to change this line:

PHP Code:
$success mail($EmailTo$Subject$Body"From: <$EmailFrom>"); 
to

PHP Code:

if ((isset($_GET['name'])) && (isset($_GET['email'])))
{
// send email
$success mail($EmailTo$Subject$Body"From: <$EmailFrom>"); 
}
else
{
print 
"<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">"

For the agent, use:
PHP Code:
$_SERVER['HTTP_USER_AGENT']; 
It works, because I have just tried it. It will output a raw string though, like: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6

For IP address, your can use:
PHP Code:
$_SERVER['REMOTE_ADDR'
If you want the hostname, you can use $_SERVER['REMOTE_HOST'] sometimes, but if that doesn't work do
PHP Code:
gethostbyaddr($_SERVER['REMOTE_ADDR']) 
instead.

HTH
__________________
"We're not here for a long time, we're here for a good time" - Mike Ness (Social Distortion)
"Reach for the sky, 'cause tomorrow may never come" - Reach For The Sky (Social Distortion)
punky is offline   Reply With Quote
Old 26-09-2005, 01:47   #5
Programming Monkey
 
Join Date: Jan 2004
Location: Between Somerset and Essex
Age: 25
Services: 8MB Office MAX on Freeola, Freeview, Freesat
Posts: 833
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP form help

You might want to have
PHP Code:
 $_SERVER['HTTP_X_FORWARDED_FOR'
to get the ips of machine that are behind proxies (NTL network) otherwise you'll just get the proxy IP.
Do you have the page error.html that it refers to when there's an error?
__________________
www.strzelecki.co.uk
www.sagemhelp.info Help, advice and discussion about Sagem mobiles.
Exmoor Explorer On yer bike!
Strzelecki is offline   Reply With Quote
Reply


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

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


All times are GMT +1. The time now is 00:10.


Links
Google
 
Web www.cableforum.co.uk


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0
Copyright © 2003 - 2008, Cable Forum.
(s204569790.onlinehome.info)