473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create mail/contact form

I tried to create an email/contact form but i'am stuck. (i'am a php-newbie)
Let me explain (sorry for my bad english, it's not my native language)

I have a form with the required fields and the necessary php-code.
There's also some code to validate if a field is empty or there's an invalid
email address.
But how can i display error messages (e.g. empty field), in this (same)
form. (e.g. at the top of the page)
I searching fore several day's but can't find an example.

I appreciate some help or example if possible,

Stephanie
Jul 18 '05 #1
18 2285
On Mon, 18 Jul 2005 13:58:11 +0200, Stephanie wrote:
I appreciate some help or example if possible,


http://www.rent-a-tutor.com/tools/

try the contact form generator to create a PHP-File with your contact
form.

Marian

--
Barrierefreie Online-Kurse: HTML, PHP, MySQL, Word, Excel
http://www.lernpilot.de/wbt/
Jul 18 '05 #2
Stephanie wrote:
I tried to create an email/contact form but i'am stuck. (i'am a php-newbie)
Let me explain (sorry for my bad english, it's not my native language)

I have a form with the required fields and the necessary php-code.
There's also some code to validate if a field is empty or there's an invalid
email address.
But how can i display error messages (e.g. empty field), in this (same)
form. (e.g. at the top of the page)
I searching fore several day's but can't find an example.

Something like:

<?php

$display_form = true;

function validate_data()
{
// Here is the code that validates
// all the data from post and if
// there are some errors, then it proper
// error messages and/or other error flags.
// It returns true if data is valid and
// false if not.
}

if (!empty($_POST['go']) && validate_data())
{
// Do data processing (eg. send mail).
// If something goes wrong, then set proper
// error messages and/or error flags and.
// If everything is OK, then set $display_form
// to false, display some confirmation message
// and/or redirect to page which confirms
// finishing the process.
}

if ($display_form)
{
// Here show error messages if are set.
// And show the form (you can use some error
// flags to point the fields which are not
// filled properly). Use data from $_POST
// (or $_GET) to fill the "value" attributes
// of <input>, to display the data which
// the user allready filled in.
// Put some hidden value named "go", or use
// this name on "submit" button in the form
// so the expression "empty($_POST['go'])"
// above would evaluate to "true" when the
// form is submited (or resubmited).
}

?>

You can split the file above and use "include".
Jul 18 '05 #3
Creates a nice form but without the wanted error message in the same form.
Jul 18 '05 #4
I noticed that Message-ID:
<c6***************************@news.versatel.nl> from Stephanie
contained the following:
I appreciate some help or example if possible,


www.ckdog.co.uk/phmail_lite

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Jul 18 '05 #5
I'am looking for an example that uses one form or reports errors to the main
form.
All these examples use at least two forms an they don't report errors to the
main form.

Stephanie
Jul 21 '05 #6
I noticed that Message-ID:
<42***************************@news.versatel.nl> from Stephanie
contained the following:
I'am looking for an example that uses one form or reports errors to the main
form.
All these examples use at least two forms an they don't report errors to the
main form.


Ah. Like this?
http://www.ckdog.co.uk/php/form.php
(mail sent from this form is not read)

Code for the above
http://www.ckdog.co.uk/php/form.zip
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Jul 21 '05 #7
You're great Geoff.

This is exact what i need. I go study this example.

Stephanie

"There are 10 kind of people. Those who understand binary and those who
don't."
Jul 21 '05 #8
I tried to add some e-mail vallidation but is fails.

if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/")){
$missing[]=$req_email;
$red[1]=" class=\"red\"";

It only validates if the field is not empty, but not for a valid email
address.

Stephanie
Jul 21 '05 #9
I noticed that Message-ID:
<25***************************@news.versatel.nl> from Stephanie
contained the following:
I tried to add some e-mail vallidation but is fails.

if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/")){
$missing[]=$req_email;
$red[1]=" class=\"red\"";

It only validates if the field is not empty, but not for a valid email
address.


Validate this: me@privacy.net
Validate this: bl@cldog.co.uk
Validate this: bi**@microsoft.com

The first one is a black hole, the second is a typo, the third is not
mine. All would pass as valid with a regex checker. None are valid (in
that you won't get a reply from any of them)

I think it's a bit pointless really. Some forms ask for the email
address to be typed twice then compare the two which /may/ help prevent
typos. But the only way to check if an email address is valid is to
send mail to it, and see if you get a response.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Jul 21 '05 #10
> I think it's a bit pointless really. Some forms ask for the email
address to be typed twice then compare the two which /may/ help prevent
typos. But the only way to check if an email address is valid is to
send mail to it, and see if you get a response.


Or check mx-records.
But can you explain why it doesn't work :-))

I adapted the code to use it with my own page layout. I use the form within
a fieldset.
The warning messages appears a the top af the page, how can i let them
appear within my fieldset.

(it's an instructive day :-)) )

Stephanie
Jul 21 '05 #11

Stephanie wrote:
But how can i display error messages (e.g. empty field), in this (same)
form. (e.g. at the top of the page)


Depends on how your PHP code is arranged, but here is one way to
achieve this - a simple form with only one field:

<?php

$strError = ''; // assume no errors
$strName = '';

if( isset( $_POST[ 'Name' ] ) )
{
// validate 'Name'...
$strName = $_POST[ 'Name' ];
if( strlen( $strName ) < 10 )
{
$strError = 'ERROR: Name must be at least 10 characters<br
/>';
}
if( $strName == 'Steve' )
{
$strError = 'ERROR: Your name is Steve<br />';
}
// ... etc ...
}
else
{
// nothing filled in yet...
$strError = 'Please fill in all of the following values<br />';
}

if( $strError == '' )
{
// ... all ok, process the form ...
}
else
{
// print the form (again) with any user-supplied values filled
in...
// include error report above the form...

?>

<form method="post" action="...">
<?php print $strError; ?>
Name: <input name="Name" type="text" value="<?php print $strName; ?>"
/>
<input name="Save" type="submit" value=" Save " />
</form>

<?php

}

?>

---
Steve

Jul 21 '05 #12
Warning messages now within fieldset. (fixed)

Still interested in validating email address (not validating if it exists,
but if it's a valid syntax)

Stephanie
Jul 21 '05 #13

Stephanie wrote:
I tried to add some e-mail vallidation but is fails. if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/")){


You should be getting "PHP Warning: Wrong parameter count for ereg()"
for this snippet, as you have not specified the string to be matched!

---
Steve

Jul 21 '05 #14
>> if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/")){

You should be getting "PHP Warning: Wrong parameter count for ereg()"
for this snippet, as you have not specified the string to be matched!


I already changed it this way:
if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/",
$_POST['email'])==TRUE){

and tried this:

if(!$_POST['email']&&$req_email&&ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/",
$_POST['email'])==TRUE){

And this:

if(!$_POST['email']&&$req_email){
$missing[]=$req_email;
$red[1]=" class=\"red\"";
}
if
($_POST['email']&&ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/",
$_POST['email'])==TRUE){
$missing[]="Use a valid email address";
$red[1]=" class=\"red\"";
}

But now way.

Jul 21 '05 #15
I already changed it this way: .... and tried this: .... And this: ....
if ($_POST['email']&&ereg("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST['email'])==TRUE){


Ah, I just noticed - you are using PERL compatible RE syntax with
ereg(). If you use this syntax you must use preg_match() not ereg(). I
still think the RE itself stinks, though 8-)

---
Steve

Jul 21 '05 #16
I noticed that Message-ID:
<19***************************@news.versatel.nl> from Stephanie
contained the following:
I think it's a bit pointless really. Some forms ask for the email
address to be typed twice then compare the two which /may/ help prevent
typos. But the only way to check if an email address is valid is to
send mail to it, and see if you get a response.
Or check mx-records.


Well even that won't ensure the address is read.But can you explain why it doesn't work :-))


Nope, hopeless at regex.

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Jul 21 '05 #17
Stephanie wrote:
Warning messages now within fieldset. (fixed)

Still interested in validating email address (not validating if it exists,
but if it's a valid syntax)


$email=eregi_replace("[^a-z0-9@\.\-_]*","",$email);
//replace any non valid characters with ""

if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo $beginhtml,"e-mail ($email) is not a valid address, please correct
it or make sure it is blank.",$endhtml;
exit;

HTH

--
TK
http://www.wejuggle2.com/
Still Having a Ball
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?


..

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 21 '05 #18
Thx Terry.
Jul 21 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Web Master | last post by:
Hi, I am having a little issue with Jacks Form mail php script. I have installed it and configured the form to get it to work, but for some bizarre reason I have 2 issues I can't seem to debug....
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
2
by: Wayne | last post by:
Hi, I have recently added tried to update the feedback form on my page to be sent in HTML format. Problem is that when its submitted, I get the mail without the variable input, just the...
7
by: kandi111777 | last post by:
I have a form that includes a drop down box. I can get all of the other values to show up in an e-mail except for the drop down box values. Can someone please help? -- I know the HTML isn't the...
1
by: jikdur | last post by:
Overview: I have a form screen where users input criteria into different text boxes to limit a contact table. This is then fed into a query that limits the list returned. The returned list is in a...
5
by: TanBrae | last post by:
Hi all, I'm fairly new to creating web pages. My current site has a form that has not been working for some time. I've had several people try to fix it, but it still won't work. (long story,...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
3
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
5
by: Joker7 | last post by:
Hi, I use the script below to send a email from a contact form but it would be nice if the conformed sent page showed what was sent.Question how can I do this ? Thanks Chris <?php $mailto...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.