Forum Moderators: coopster

Message Too Old, No Replies

Contact form not submitting

         

music_man

4:01 am on Oct 3, 2005 (gmt 0)

10+ Year Member



Hi

I am having trouble with my contact form not submitting - I would like it to error check and highlight the fields not filled in (keeping the ones that were filled in). I tried it on firefox once and it came up with a message saying that the png had an error in it - could be a local setting.

Here it is:

<?php

Header("Content-Type: image/png");

session_start();

if (isset($_POST[submit])) {

$fo = $_POST['for'];
$fn = $_POST['firstname'];
$ln = $_POST['lastname'];
$ea = $_POST['emailaddress'];
$qu = $_POST['question'];

$random = trim($random);

if (!$new_string == $random){

header("Location: contact.php?error=verification&errornote=TRUE");

}

elseif ($fn == "") {

header("Location: contact.php?error=firstname&errornote=TRUE");

}

elseif (($ea == "") ¦¦ (!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $ea))) {

header("Location: contact.php?error=emailaddress&errornote=TRUE");

}

elseif ($qu == "") {

header("Location: contact.php?error=question&errornote=TRUE");

}

else {

mail ("email@myemail.com", "$fo", "$question", "from: $ea");

header("Location: contact.php?note=thankyouverymuch");

}

}

elseif ($note==thankyouverymuch)

{

$page="contact"; require ("inc/top.inc.php");

echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";

echo "<h1>Thank you!</h1>";
echo "<br />";
echo "<h3>We will be in contact with you as soon as possible</h3>";

echo "</div>";

echo "</td>";
echo "</tr> ";
echo "</table>";
require ("inc/footer.inc.php");

}

else {

$page="contact"; require ("inc/top.inc.php");

$new_string;

session_register('new_string');

$im = ImageCreate(200, 40);

$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);

srand((double)microtime()*1000000);

$string = md5(rand(0,9999));

$new_string = substr($string, 17, 5);

ImageFill($im, 0, 0, $white);

ImageString($im, 4, 45, 19, $new_string, $black);

/* Directory inc/c/ is CHMODDed to 777 */
ImagePNG($im, "inc/c/verify.png");
ImageDestroy($im);

echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";

echo "<h1>Contact us</h1>";

echo "<br />All fields maked * are required";

if ($errornote=='TRUE') {

echo "<br /><br />Please fill in all fields marked <span style=\"color: red;\">RED</span>";

}

echo "<div id=\"contactform\">";
echo " <form action=\"contact.php\" method=post>";
echo "<label for=\"for\">For: *</label>";
echo "<select name=\"for\">";
echo "<option>Business";
echo "<option>Help";
echo "<option>Personal";
echo "</select><br />";
echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\"";

echo "name=\"firstname\"";

if ($error==firstname) {

echo " style=\"border: 1px solid red;\"><br />";
}

else {

echo "><br />";

}

echo "<label for=\"lastname\">Last name:</label>";
echo "<input type=\"text\" name=\"lastname\"";

if ($error==lastname) {

echo " style=\"border: 1px solid red;\"><br />";
}

else {

echo "><br />";

}

echo "<label for=\"emailaddress\">Email address: *</label>";
echo "<input type=\"text\" name=\"emailaddress\"";

if ($error==emailaddress) {

echo " style=\"border: 1px solid red;\"><br />";
}

else {

echo "><br />";

}

echo "<label for=\"question\">";

if ($error==question) {

echo "<span style=\"color: red;\">Question *</span></label>";

}

else {

echo "Question</label>";
}
echo "<textarea name=\"question\" rows=\"10\" cols=\"10\"></textarea><br />";
echo "<img src=\"inc/c/verify.png\">";
echo "<br />";
echo "Please type the contents of the image *";
echo "<br /><br />";
echo "<input name=\"random\" type=\"text\" value=\"\"";

if ($error==verification) {

echo "style=\"border: 1px solid red;\">";
}

else {

echo ">";

}

echo "<br /><br />";
echo "<input type=\"submit\" value=\"Send\">";
echo "</form>";

echo "</div> ";

echo "</td> ";
echo "</tr> ";
echo "</table> ";

echo "<h3>We respect your privacy and we will never sell your email address to any third party. The information submitted in this form will be sent directly to Erin Wheelan, managing director of Eyelights Ltd.</h3>";

require ("inc/footer.inc.php");

}

?>

mrnoisy

4:40 am on Oct 3, 2005 (gmt 0)

10+ Year Member



It works for me if I remove the line from the top:

Header("Content-Type: image/png");

music_man

4:56 am on Oct 3, 2005 (gmt 0)

10+ Year Member



Hi

Tried that and got:

Parse error: parse error, unexpected T_STRING in contact.php on line 27

mrnoisy

5:09 am on Oct 3, 2005 (gmt 0)

10+ Year Member



That just means there is an error in the way the code is written on line 27. If you can't find the error, post line 27 here.

music_man

7:54 am on Oct 3, 2005 (gmt 0)

10+ Year Member



I removed the faulty as such code from line 27 which was:

elseif (($ea == "") ¦¦ (!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $ea))) {

and the form displayed but when I pushed submit the form stayed put. I think it didn't submit.

mrnoisy

9:45 am on Oct 3, 2005 (gmt 0)

10+ Year Member



Retype the pipe symbols ¦¦

This forum changes them.

music_man

7:14 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



Thanks

It still does not appear to submit.

<?php

session_start();

if (isset($_POST[submit])) {

$fo = $_POST['for'];
$fn = $_POST['firstname'];
$ln = $_POST['lastname'];
$ea = $_POST['emailaddress'];
$qu = $_POST['question'];

$random = trim($random);

if (!$new_string == $random){

header("Location: contact.php?error=verification&errornote=TRUE");

}

elseif ($fn == "") {

header("Location: contact.php?error=firstname&errornote=TRUE");

}

elseif (($ea == "") ¦¦ (!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $ea))) {

header("Location: contact.php?error=emailaddress&errornote=TRUE");

}

elseif ($qu == "") {

header("Location: contact.php?error=question&errornote=TRUE");

}

else {

mail ("email@myemail.com", "$fo", "$question", "from: $ea");

header("Location: contact.php?note=thankyouverymuch");

}

}

elseif ($note==thankyouverymuch)

{

$page="contact"; require ("inc/top.inc.php");

echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";

echo "<h1>Thank you!</h1>";
echo "<br />";
echo "<h3>We will be in contact with you as soon as possible</h3>";

echo "</div>";

echo "</td>";
echo "</tr> ";
echo "</table>";
require ("inc/footer.inc.php");

}

else {

$page="contact"; require ("inc/top.inc.php");

$new_string;

session_register('new_string');

$im = ImageCreate(200, 40);

$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);

srand((double)microtime()*1000000);

$string = md5(rand(0,9999));

$new_string = substr($string, 17, 5);

ImageFill($im, 0, 0, $white);

ImageString($im, 4, 45, 19, $new_string, $black);

/* Directory inc/c/ is CHMODDed to 777 */
ImagePNG($im, "inc/c/verify.png");
ImageDestroy($im);

echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"content\">";
echo "<tr>";
echo "<td valign=\"top\">";

echo "<h1>Contact us</h1>";

echo "<br />All fields maked * are required";

if ($errornote=='TRUE') {

echo "<br /><br />Please fill in all fields marked <span style=\"color: red;\">RED</span>";

}

echo "<div id=\"contactform\">";
echo " <form action=\"contact.php\" method=post>";
echo "<label for=\"for\">For: *</label>";
echo "<select name=\"for\">";
echo "<option>Business";
echo "<option>Help";
echo "<option>Personal";
echo "</select><br />";
echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\"";

echo "name=\"firstname\"";

if ($error==firstname) {

echo " style=\"border: 1px solid red;\"><br />";
}

else {

echo "><br />";

}

echo "<label for=\"lastname\">Last name:</label>";
echo "<input type=\"text\" name=\"lastname\"";

if ($error==lastname) {

echo " style=\"border: 1px solid red;\"><br />";
}

else {

echo "><br />";

}

echo "<label for=\"emailaddress\">Email address: *</label>";
echo "<input type=\"text\" name=\"emailaddress\"";

if ($error==emailaddress) {

echo " style=\"border: 1px solid red;\"><br />";
}

else {

echo "><br />";

}

echo "<label for=\"question\">";

if ($error==question) {

echo "<span style=\"color: red;\">Question *</span></label>";

}

else {

echo "Question</label>";
}
echo "<textarea name=\"question\" rows=\"10\" cols=\"10\"></textarea><br />";
echo "<img src=\"inc/c/verify.png\">";
echo "<br />";
echo "Please type the contents of the image *";
echo "<br /><br />";
echo "<input name=\"random\" type=\"text\" value=\"\"";

if ($error==verification) {

echo "style=\"border: 1px solid red;\">";
}

else {

echo ">";

}

echo "<br /><br />";
echo "<input type=\"submit\" value=\"Send\">";
echo "</form>";

echo "</div> ";

echo "</td> ";
echo "</tr> ";
echo "</table> ";

echo "<h3>We respect your privacy and we will never sell your email address to any third party. The information submitted in this form will be sent directly to person.</h3>";

require ("inc/footer.inc.php");

}

?>

mrnoisy

9:18 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



In order to process the following if statement

if (isset($_POST[submit])) {

The submit button needs to be named:

echo "<input type=\"submit\" name='submit' value=\"Send\">";

music_man

9:36 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



Fantastic! Now it submits. Do you know how I can get the fields that were filled in correctly to display again when the error shows so they don't have to retype it? Is it value=\"$_POST['firstname'];\" or somesuch?

Thanks for your help!

mrnoisy

9:50 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



Yes that should work.

You're welcome, I'm glad I could help. I have received invaluable help from this forum over the years.

music_man

10:20 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



I tried:

...

echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\"";
echo "value=\"";
$_POST['firstname'];
echo "\"";
echo "name=\"firstname\"";

if ($error==firstname) {

...

And it didn't work. Any ideas?

mrnoisy

9:44 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Try this:

...

echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\" value=\"$fn\" name=\"firstname\"";

if ($error==firstname) {

...

music_man

10:19 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Hi

echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\" value=\"$fn\" name=\"firstname\"";
echo "\"";
echo "name=\"firstname\"";

Does not work unfortunately.

I was also wondering how to incorporate nl2br to $qu

nl2br($qu)

?

music_man

10:43 am on Oct 6, 2005 (gmt 0)

10+ Year Member



Any ideas?

jatar_k

3:38 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try what mrnoisy posted explicitly, what you posted in your response doesn't match it

view source to see where your html might be messed up as well

music_man

10:31 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



Hi

I followed it (copied and pasted it) and it still did not come up. I wonder why? The $fn variable should have the information...

echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\" value=\"$fn\" name=\"firstname\"";

if ($error==firstname) {

jatar_k

10:42 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when you view source is the missing value of $fn the only issue?

music_man

12:01 am on Oct 7, 2005 (gmt 0)

10+ Year Member



Hi

No that is not the issue - the issue is that the field is not filled in when they have to fix an error.

Say "firstname" and "email address" are required fields and I fill in firstname only. I am shown an error message that shows I must fill in the email address as well. The firstname that I entered is remembered so I don't have to fill it in again.

Hence the reason why I have the value=\"fn\" so that it will remember the fields I filled in correctly.

The source code should reflect this.

jatar_k

12:06 am on Oct 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> the issue is that the field is not filled in when they have to fix an error.

I realize this but what I am asking is if the value is showing in the source from the browser and possibly misformatted html so that it isn't in the field

if the value doesn't show at all then the issue is with assigning the value to $fn

I am just offering a way to diagnose your issue

music_man

12:34 am on Oct 7, 2005 (gmt 0)

10+ Year Member



Good idea. For some obscure reason it won't allow me to view the source! I right click and even go into View in IE and it won't open the file in notepad - the weird thing is that it allows it on the other pages.

Thanks

[edited by: jatar_k at 2:21 am (utc) on Oct. 7, 2005]
[edit reason] no urls thanks [/edit]

mrnoisy

1:14 am on Oct 7, 2005 (gmt 0)

10+ Year Member



Use Firefox [mozilla.org].

music_man

1:30 am on Oct 7, 2005 (gmt 0)

10+ Year Member



I do - only I at the moment I am on a computer with IE. I am also fond of Opera.

Even though IE 6.0 is buggy and does not support web standards I don't know why it doesn't allow me to view the source for this one page.

jatar_k

2:25 am on Oct 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



from what I see your $fn var is not being set or maybe passed

that is where the problem presently lies

music_man

2:38 am on Oct 7, 2005 (gmt 0)

10+ Year Member



Is it not being parsed at the top?

$fn = $_POST['firstname'];

?

jatar_k

2:43 am on Oct 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe it isn't being passed

try this

$fn = $_POST['firstname'];
echo '<p>POST[firstname]: ', $_POST['firstname'];
echo '<p>fn: ', $fn;

music_man

2:52 am on Oct 7, 2005 (gmt 0)

10+ Year Member



I put it in this context

$fn = $_POST['firstname'];
echo '<p>POST[firstname]: ', $_POST['firstname'];
echo '<p>fn: ', $fn;

echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\" value=\"$fn\" name=\"firstname\"";

if ($error==firstname) {

and when I pushed "submit" it didn't show the firstname.

AlexK

11:14 am on Oct 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You will find that you can put the whole array into a double-quoted string and it will print out right:

echo "<p>\$_POST['firstname']: $_POST['firstname']</p>";

The back-slash stops the first array from being evaluated as a variable, whilst the second array is evaluated as a variable and will substitute it's value into the echo statement. The trick with printing array-variables like this is not to put any spaces in. As an example:

works:

echo "$_POST['firstname']";

does not work:

echo "$_POST[ 'firstname' ]";

music_man

12:04 am on Oct 8, 2005 (gmt 0)

10+ Year Member



Thanks for your reply.

I have this:

echo "<label for=\"firstname\">First name: *</label>";
echo "<input type=\"text\" value=";

echo "$_POST['firstname']";

echo " name=\"firstname\"";

if ($error==firstname) {

And get:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in file.php on line 123

AlexK

1:05 am on Oct 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, sorry about that. It seems that there is a bug in the parsing.

works:

echo "$atozArray['fixedstringorvariable']";

does not work:
echo "$_atozArray['fixedstringorvariable']";

That error message is the one that you get if a space is included within the [] array brackets. In this case, it sees the under-score as a space.

music_man

1:23 am on Oct 8, 2005 (gmt 0)

10+ Year Member



Hi

I don't get this bit sorry:

echo "<input type=\"text\" value=";

echo "$atozArray['firstname']";

echo " name=\"firstname\"";

if ($error==firstname) {

?

Where do I put the $_POST is it the "$_" which is the problem?

This 39 message thread spans 2 pages: 39