Error message doesn't print

Hi could really use some help I am not understanding as to why the error message won’t print.
If I submit the form empty, the feedback page is blank, if I only enter one thing the feedback is still blank (I understand that because I have set up an array). could some one please help as to why no error message?

I changed my feedback form since my last post with the same error.
feedback form code:

<?php #script 2.5 handle_form.php #4 //print the submitted information: if ( !empty($_POST['name']) && !empty ($_POST['comments']) && !empty ($_POST['email']) ) { echo "

Thank you, {$_POST['name']}, for the following comments:
{$_POST['comments']}

We will reply to you at {$_POST['email']}.

\n"; } else { echo '

Please go back and fill out the form again.

'; } ?>

form code:

Enter your information in the form below

Name:

Email address:

Gender: Male Female

Age: Under 30 Between 30 and 60 Over 60

Comments:

you are sending the info to this page:
and the receiving page is called: handle_form.php so it looks like this page is not getting any info because your sending it elsewhere…

Hi Redscouse

Thanks I did correct that but still have the same problem. If I leave the form blank and submit my formfeed back is still empty. If I fill out the form I get all the correct information on the form feedback. I am not understanding what I am doing wrong?

thanks
unhappy

here ya go, i fixed it for you:
[php]

<?php #script 2.5 handle_form.php #4 //print the submitted information: if (isset($_POST['submit'])) { if(!empty($_POST['name']) && !empty ($_POST['comments']) && !empty ($_POST['email']) ) { echo "

Thank you, {$_POST['name']}, for the following comments:
{$_POST['comments']}

We will reply to you at {$_POST['email']}.

\n"; } else { echo '

Please go back and fill out the form again.

'; } } else { // leave php and display the form using html?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<fieldset><legend>Enter your information in the form below</legend>
<p><b>Name:</b><input type="text" name="name" size="20" maxlength="40" /></p>
<p><b>Email address:</b> <input type="text" name="email" size="40" maxlength="60" /></p>
<p><b>Gender:</b> <input type="radio" name="gender" value="M" />Male
<input type="radio" name="gender" value="F" /> Female</p>
<p><b>Age:</b> <select name="age"><!---select tag starts the pull down menue--->
<option value="0-29">Under 30 </option>
<option value="30-60">Between 30 and 60 </option>
<option value="60+">Over 60 </option>
</select></p>

<p><b>Comments:</b> <textarea name="comments" rows="3" cols="40"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit My Information" /> </div>
</form>
<?php

} // back to php to close things off
?>[/php]
:wink:

Morning Redscouse

Thank you for helping me. I tried this and I still don’t get the error messages if I submit the form blank. Is it my system? I am running the file right off the server of website.

thanks
unhappyhttp://www.phphelp.com/forum/Smileys/solosmileys/sad.gif

can you post the URL here for me to go look :o
the code below works so i’m thinking it may be something to do with your server/setup etc…

Hi you bet

http://feliciasdomain.com/php6_practice/html/formandfeedback.php

You are the best thank you so much for helping me try to learn this.

thanks
happy

[s]i’m assuming you haven’t altered anything i wrote in the script (as i can’t see the php on the site - only the HTML)
change this bit: /php6_practice/html/formandfeedback.php

to: <?php echo $_SERVER['PHP_SELF']; ?>

Let me know what happens ;)[/s]

my bad, just checked my script below and thats exactly whats there…
I’m not sure whats goin on there as i know the script below works coz i tested it ?

I’ve just been looking at your page again trying to figure this out for you…

can you post here for me the entire contents of: formandfeedback.php :exactly the way you have it written on your webpage please… :wink:

Morning Redscouse

You bet here is the complete page

Form and Feedback <?php #script 2.5 handle_form.php #4 //print the submitted information: if (isset($_POST['submit'])) { if(!empty($_POST['name']) && !empty ($_POST['comments']) && !empty ($_POST['email']) ) { echo "

Thank you, {$_POST['name']}, for the following comments:
{$_POST['comments']}

We will reply to you at {$_POST['email']}.

\n"; } else { echo '

Please go back and fill out the form again.

'; } } else { // leave php and display the form using html?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<fieldset><legend>Enter your information in the form below</legend>
<p><b>Name:</b><input type="text" name="name" size="20" maxlength="40" /></p>
<p><b>Email address:</b> <input type="text" name="email" size="40" maxlength="60" /></p>
<p><b>Gender:</b> <input type="radio" name="gender" value="M" />Male
<input type="radio" name="gender" value="F" /> Female</p>
<p><b>Age:</b> <select name="age"><!---select tag starts the pull down menue--->
<option value="0-29">Under 30 </option>
<option value="30-60">Between 30 and 60 </option>
<option value="60+">Over 60 </option>
</select></p>

<p><b>Comments:</b> <textarea name="comments" rows="3" cols="40"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit My Information" /> </div>
</form>
<?php

} // back to php to close things off
?>

I use this off the server I believe its a unix server and I have viewed this in Safari, Opera, Firefox and explorer and no error messages. Yet it I fill the form out completely I get the information that I put in and the messages. Just a blank screen if I enter nothing or even one bit of information.

thank you for helping me with this.
Happy

Mmm, now that is strange…

…the script works on both my test server and my live server…

below is an upgraded version of the script, it checks each value is set and if so it will email you the details (remember to put your email address and website in the script)
if it fails it should tell you exactly what value is missing…

it also performs a little cleanup on each value to help combat naughty people who will try to violate your site with dodgy code…
[php]

Form and Feedback <?php #script 2.5 handle_form.php #4 //print the submitted information: if (isset($_POST['submit'])) { // initialise an array for any errors. $errors = array(); // do some cleaning. if(!empty($_POST['name'])) { $name = trim(stripslashes($_POST['name'])); } else { $name = false; $errors[] = 'Please enter your name'; } // do some cleaning. if(!empty($_POST['email'])) { $email = trim(stripslashes($_POST['email'])); } else { $email = false; $errors[] = 'Please enter your email'; } // do some cleaning. if(!empty($_POST['comments'])) { $comments = trim(stripslashes($_POST['comments'])); } else { $comments = false; $errors[] = 'Please enter a comment'; } if(isset($_POST['gender'])) { $gender = $_POST['gender']; } else{ $gender = false; $errors[] = 'Please enter your gender'; } if(isset($_POST['age'])) { $age = $_POST['age']; } else { $age = false; $errors[] = 'Please enter your age'; } // check the errors array is empty (no errors) if(empty($errors)) { // create an email to myself. (from my website) $to = '[email protected]'; $from = 'From: [email protected]'; $subject = 'You have been contacted via the form online'; $message = "You have been sent a message from:\n"; $message .= "Name: $name\n"; $message .= "Email: $email\n"; $message .= "Gender: $gender\n"; $message .= "Age: $age\n"; $message .= "Comments: $comments\n"; // send the message. mail($to, $subject, $message, $from); echo "

Thank you, $name, for the following comments:
$comments

We will reply to you at $email.

\n"; } else // there was an error somewhere.. { echo '

Please go back and correct the following:

'; // loop through the errors array and print them out. foreach($errors as $error) { echo '

' . $error . '

'; } } } else { // leave php and display the form using html ?> Enter your information in the form below

Name:

Email address:

Gender: Male Female

Age: Under 30 Between 30 and 60 Over 60

Comments:

<?php } // back to php to close things off ?> [/php]

replace the entire contents of your page with this script and let me know how you get on.

Red :wink:

Afternoon Redscouse;

AWESOME!! it works if I leave anything out I get the error message. Upon submit I get it in my email. THANK YOU so very MUCH!! You are beautiful to go through all that to help me, your great.

thank you
happy :wink:

Your very welcome, glad i could help get it working :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service