Jump to content

Recommended Posts

My problem is that a form that previously worked fine (I used to recieve emails from it all the time, and it worked when I tested it) now just decided not to work anymore.

 

I always get the 'error' message telling me there is a field that needs to be filled in, even when all the fields are filled.

 

The php file:

<?php 
$recipient = "email@myemail.com";
$subject = "Feedback Form";
$stylesheet = "yes";
$stylesheet_url = "http://www.mywebsite.com/stylesheet.css";
$require1 = "$name";
$require2 = "$email";
$require3 = "$comments";

$error_msg = "Please fill in all the required fields. <a href=\"javascript:history.back(-1)\">Click here</a> to go back and complete the form.<br><br>";

$success_msg = "The following information was successfully sent to the webmaster:<br><br>";

if (empty($require1) || empty($require2) || empty($require3)) { 

?>
<title>Feedback</title>

<? 
if ($stylesheet == 'yes'){ ?>
<link rel="stylesheet" href="<?=$stylesheet_url?>" type="text/css">
<? } ?>

<h3>Form Error</h3>
<lil><?=$error_msg?></lil>

</body></html>


<?
} else {

$email_recipient = "$recipient";
$email_subject = "$subject";


$email_content = "Name:       \t$_POST[name]\n";
$email_content .= "Email:      \t$_POST[email]\n";
$email_content .= "Comments:   \t$_POST[comments]\n";
$email_content .= "IP Address: \t$REMOTE_ADDR\n";

$email_header = "From: $_POST[email]\n";
$email_header .= "Reply-To: $_POST[email]\n";

mail($email_recipient, $email_subject, $email_content, $email_header);

?>

<title>Feedback Form</title>

<? 
if ($stylesheet == 'yes'){ ?>
<link rel="stylesheet" href="<?=$stylesheet_url?>" type="text/css">
<? } ?>

<h3Success!</h3>
<lil><?=$success_msg?></lil>

<b>Name:</b> <?=$name?><br>
<b>Email:</b> <?=$email?><br>
<b>Comments:</b> <?=$comments?>

<br><br><a href="javascript: history.go(-1)">Back to the site</a>

</body></html>


<? } ?>

 

I literally didn't change anything and I am quite a n00b at PHP so any help would be appreciated. :)

Link to comment
https://forums.phpfreaks.com/topic/66837-php-form-error/
Share on other sites

It's likely that register_globals was switched off.  Try using these lines instead of what you have there:

 

$require1 = $_REQUEST['name'];
$require2 = $_REQUEST['email'];
$require3 = $_REQUEST['comments'];

 

If this IS the problem, you will also need to change other places where data comes from the form.  Looks like $recipient and $subject will need to be changed as well.

Link to comment
https://forums.phpfreaks.com/topic/66837-php-form-error/#findComment-335047
Share on other sites

Ahh, that worked, the form is submitting again. Thank you!

 

However, like you pointed out there is another problem. When the form has been submitted the data that shows up on the success page is just:

 

Name:

Email:

Comments:

 

But the field variables are not there. What would I need to change for $recipient and $subject?

 

Thanks again.

Link to comment
https://forums.phpfreaks.com/topic/66837-php-form-error/#findComment-335051
Share on other sites

These lines should be:

 

$email_recipient = $_REQUEST['recipient'];
$email_subject = $_REQUEST['subject'];


$email_content = "Name:       \t{$_POST['name']}\n";
$email_content .= "Email:      \t{$_POST['email']}\n";
$email_content .= "Comments:   \t{$_POST['comments']}\n";
$email_content .= "IP Address: \t{$_SERVER['REMOTE_ADDR']}\n";

 

Try that out..  I assume your form uses "method=post" ?  $_REQUEST contains everyithing in $_POST, as well as $_GET (and other stuff too)

Link to comment
https://forums.phpfreaks.com/topic/66837-php-form-error/#findComment-335053
Share on other sites

Strangely, when I changed the code to what you posted above it would go to the success page but would not actually send the submitted form. I changed it back to what I had before and it's sending all right. Also added this part:

 

<b>Name:</b> <?php echo $_POST["name"]; ?><br>
<b>Email:</b> <?php echo $_POST["email"]; ?><br>
<b>Comments:</b> <?php echo $_POST["comments"]; ?>

 

And it all seems to be working well now. Thanks for your help in fixing the first part, and it's all solved now.  ;D

Link to comment
https://forums.phpfreaks.com/topic/66837-php-form-error/#findComment-335062
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.