Client Support Community Server Status Contact Us Client Login
Email Hosting Website Hosting Reseller Hosting VPS Hosting Dedicated Servers

    Join our Community      Check your private messages       Profile       Search       FAQ       Memberlist       Log in


Hiding FormMail recipient address from spammers
Goto page Previous  1, 2
 
Post new topic   Reply to topic    NetHosted Community Index -> E-mail Support
Mike T Reply with quote
 Community Liason

 

 Joined: 26 Apr 2004
 Posts: 453
 Location: Loughborough

PostPosted: Wed Aug 23, 2006 1:48 pm    Post subject:
 
Garry wrote:
Hi,

Is the below code correct ?

The cookie code part, if someone sent an email then wanted to send another one would that

allow it ?

Is there away to get the IP Address of the person ?
Garry,

Yes your code seems correct!

It would allow a second e-mail it so long as the input field specified to check is different from the first e-mail's same input field.

To make it show the IP change:

Code:

$EMAIL_MESSAGE = "
Name: {$_POST['realname']}
E-mail Address: {$_POST['email']}
Offer: {$_POST['offer']}
";


to

Code:

$EMAIL_MESSAGE = "
Name: {$_POST['realname']}
E-mail Address: {$_POST['email']}
IP Address: {$_SERVER['REMOTE_ADDR']}
Offer: {$_POST['offer']}
";


Ted wrote:
The next part of my project is to get some simple validation of input fields.

I don't want to get too ambitious at first: all I want to do for starters is to check that mandatory fields have some contents. What would be the easiest way of rejecting the post if one or more such fields have no data and returning the user to the form?


Ted,

Add this anywhere before the mail(".....); part (probably best right at the top):

Code:

/* count the number of characters in the input, if it's zero then send them back */
if (strlen($_POST['PUT_FIELD_INPUT_NAME_HERE']) == 0)
{
 header("location: {$_SERVER['HTTP_REFERER']}");
 exit();
 /* will return user to previous page */
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Garry Reply with quote
 NetHosted Customer

 

 Joined: 03 Oct 2005
 Posts: 263
 Location: Lincoln, UK

PostPosted: Wed Aug 23, 2006 2:09 pm    Post subject:
 
Hi,

One more question, about the required field, would I just add the same code again for another field, but change the name to the new one

Or would I just add the code

Code:

if (strlen($_POST['FIELD']) == 0)


directly under

Code:

if (strlen($_POST['email']) == 0)


Thanks for your help

_________________
Regards,
Garry
Happy NetHosted Customer
Back to top
View user's profile Send private message
Mike T Reply with quote
 Community Liason

 

 Joined: 26 Apr 2004
 Posts: 453
 Location: Loughborough

PostPosted: Wed Aug 23, 2006 2:13 pm    Post subject:
 
You would have to add entirely different IF statements... OR

Code:

if ( (strlen($_POST['FIELD_1']) == 0) || (strlen($_POST['FIELD_2']) == 0) )
{
/* that stuff i put to go here which i forgot :) */
}


Can be expanded to have as many as possible... the || represents 'OR'.

Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Ted Reply with quote
 NetHosted Customer

 

 Joined: 21 Aug 2006
 Posts: 13
 

PostPosted: Wed Aug 23, 2006 6:04 pm    Post subject:
 
Is the header("location: {xxx}"); command the only command that enables you to navigate between different html pages? The reason I ask is that I've had trouble using it because it will fail if I try to have any output (eg echo) prior to going to another page. I'd like to be able to display a message, but it messes up the subsequent header command.
Back to top
View user's profile Send private message
Mike T Reply with quote
 Community Liason

 

 Joined: 26 Apr 2004
 Posts: 453
 Location: Loughborough

PostPosted: Wed Aug 23, 2006 6:13 pm    Post subject:
 
The point of header is it changes the browser's header information BEFORE the page loads (so it's not simply loading a page and reloading, it just makes the browser go to entirely different page).

If you use a HTML or Javascript method of redirection, it will break the history process. If they hit the back button, it will send them straight back to the page they are currently on. Not a good thing for usability.

If you want, you can configure PHP to not output anything on the page until after the page has been processed, that way if there is anything to redirect to, it will do it before sending information regardless of where that information is...

To do this, at the top of your page put

Code:
<?PHP ob_start(); ?>


and at the bottom put

Code:
<?PHP ob_end_flush(); ?>


If you REALLY want to do the redirection in the browser instead of on the server (and I give you my utmost advice not to), then you can use this Javascript:

Code:
<script>location.href='http://www.address.to.go.to.com/';</script>


Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Ted Reply with quote
 NetHosted Customer

 

 Joined: 21 Aug 2006
 Posts: 13
 

PostPosted: Wed Aug 23, 2006 6:44 pm    Post subject:
 
Do the ob_start(); and ob_end_flush(); go into my html form or the php code? What I'm trying to do is to display an error message to the user if I detect a problem with an empty field.

Incidentally in grappling with php, I find it difficult selecting suitable functions for whatever task I'm trying to perform. Looking through http://php.net/,  it just lists all the functions in alphabetical order. So you seem to have to laboriously sequentially read what each one does until you (may) find one that performs the required task. There doesn't appear to be any search by keywords to narrow this task down.
Back to top
View user's profile Send private message
Mike T Reply with quote
 Community Liason

 

 Joined: 26 Apr 2004
 Posts: 453
 Location: Loughborough

PostPosted: Wed Aug 23, 2006 7:16 pm    Post subject:
 
The function itself is often a keyword, but if you're looking for something like that you might do better doing a Google search for it.

the ob_start(); and ob_end_flush(); are PHP functions, and so go in PHP tags, before and after the HTML.

Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Ted Reply with quote
 NetHosted Customer

 

 Joined: 21 Aug 2006
 Posts: 13
 

PostPosted: Mon Aug 28, 2006 12:20 pm    Post subject:
 
OK, I've now got an html page containing my form and a sendmail.php program. In the php code I have defined a function
function checkData()
It validates the form fields and if they pass it allows sending of the mail. If they do not pass, I build up an error message variable $message. If the check fails I want to display the variable $message on the html form page and invite the user to retry.

I can't see how to do this because if I
echo $message
it appears on a page by itself rather than on the form page. Also I get that problem with the header command not working after echo.

A further minor problem is that when I build up my string $message, I want to have a newline after each item. However the command:
$message = $message . "text \n"
seems to ignore my newline \n. What's going wrong here?
Back to top
View user's profile Send private message
Mike T Reply with quote
 Community Liason

 

 Joined: 26 Apr 2004
 Posts: 453
 Location: Loughborough

PostPosted: Mon Aug 28, 2006 2:24 pm    Post subject:
 
The newline '\n' will generate a new line, but for there to actually be a line break you need to 'echo' the HTML <br /> tag.

i.e.

Code:

$message .= "text <br />";


As for passing the $message variable back. You could either do it as a cookie, send it as formdata in itself, or send it as a GET variable back to the form. For these you will need to be parsing the form page in PHP aswell.

The W3C recommends you check if the data is valid BEFORE the form is submitted (using JavaScript), to avoid people having to submit, go back and fill in the form again.

Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Al Reply with quote
 NetHosted Customer

 

 Joined: 25 Sep 2006
 Posts: 1
 

PostPosted: Mon Sep 25, 2006 7:09 pm    Post subject:
 
Hi,
just to say thanks for some helpful posts - I've reused your code :-)
Al
Back to top
View user's profile Send private message
Post new topic   Reply to topic    NetHosted Community Index -> E-mail Support
Goto page Previous  1, 2
Page 2 of 2

User Permissions
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

 
Jump to: