Formmail redirection problem

Hi all

I’ve built a form a friend. I’m using Formmail from tectite.com I’ve got it where it emails me right now like I have it configured to but the problem is when you click the Submit button I want it to redirect to either “thanku.html” or “error.html” both of which are in the same directory as the contact form.

Here are the first few lines of my form code

    <form name="contactus" action="formmail.php" method="POST">
    <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" />
    <input type="hidden" name="derive_fields" value="email=EmailAddr,realname=FullName" /> <!-- this derives (creates) "email" and "realname" special fields from the input fields -->
    <input type="hidden" name="mail_options" value="Exclude=email;realname" />  <!-- this excludes the "email" and "realname" special fields from the body of the email you receive -->
    <input type="hidden" name="subject" value="Web page general comments" />
    <input type="hidden" name='recipient' value="snoballdandd@q.com[/email]" /> <!-- change value to the recipient's email address //-->
    <input type="hidden" name="bad_url" value="error.html" />
    <input type="hidden" name="good_url" value="thanku.html" />

// end of pasted code

I’ve tried the absolute path vs the now relative path for both the “thanku.html” and “error.html” files with no change in the redirection. As it is now when you click Submit it takes you to the error page even if you have the Captcha code entered properly. When I take the good and bad_url lines out it it gives me this message in my browser …"An error occurred while processing the form .

The staff at snoballdandd.com have been alerted to the error .
snoballdandd.com apologizes for any inconvenience this error may have caused. " and it emails me this error .“Error=The form has an internal error - no valid recipients were specified.” Which I thought that this line in my form was supposed to fix > <input type=“hidden” name=‘recipients’ value="snoballdandd@q.com" /> I’m not sure what to try next. Can anybody give me a suiggestion?

It’s currently recipients and it will stay that way.

The code is not added to formmail.php it is it’s own file named form_process.php called in the form action=“form_process.php” with formmail.php included in the form_process.php file., I posted the error it gave me in my last post I’ll post it again…“I tried Submit and got this error…Warning: Cannot modify header information - headers already sent by (output started at /home/content/g/r/m/grm47/html/skeinfb/outpages/form_process.php:1) in /home/content/g/r/m/grm47/html/skeinfb/outpages/form_process.php on line 10”…it did not email me an error.

I’ve tried it with and without those lines and with the full URL and with just the filename but it made no difference. I also tried the line <input type=“hidden” name=“redirect” value=“http://domain.com/path/to/file” /> and it sent me to this error in my browser …“Warning: Cannot modify header information - headers already sent by (output started at /home/content/g/r/m/grm47/html/skeinfb/outpages/form_process.php:1) in /home/content/g/r/m/grm47/html/skeinfb/outpages/form_process.php on line 10”…it didn’t email me an error so this is all I have to go on.

It is set it emails me and says “no_recipients”

Hi spence

I got rid of the lines you noted now here’s my form HTML

    &lt;form name="contactus" action="form_process.php" method="POST"&gt;
    &lt;input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" /&gt;
    &lt;input type="hidden" name="derive_fields" value="email=EmailAddr,realname=FullName" /&gt; &lt;!-- this derives (creates) "email" and "realname" special fields from the input fields --&gt;
    &lt;input type="hidden" name="mail_options" value="Exclude=email;realname" /&gt;  &lt;!-- this excludes the "email" and "realname" special fields from the body of the email you receive --&gt;
    &lt;input type="hidden" name="subject" value="Web page general comments" /&gt;
    &lt;input type="hidden" name='recipients' value="snoballdandd@q.com" /&gt; &lt;!-- change value to the recipient's email address //--&gt;

// end

and I copied the php code you provided and pasted it into a new file and put what I hoped is the right php code for the “thanku.html” and “error.html” into it and saved it as form_process.php. I don’t know php welll yet but at the end of the code that you gave me shouldn’t there have been a ?> to end the file or did you leave that out on purpose? When you said to send the data using function pamas I didn’t know what that was so I tried it without it. Is function pamas something that’s usedf a lot?, if so I can google it. Here’s my form_process.php code

<?php
if(!empty($_POST[‘subject’]) && !empty($_POST[‘recipient’]))
{
header(‘Location:thanku.html’);//thank you message or redirect the thank you page

include(‘formmail.php’); //include the formmail.php and send the data by using function pamas
}
else
{
header(‘Location:error.html’);//display error message(s) or redirect to the error page
}

?>

I tried Submit and got this error…Warning: Cannot modify header information - headers already sent by (output started at /home/content/g/r/m/grm47/html/skeinfb/outpages/form_process.php:1) in /home/content/g/r/m/grm47/html/skeinfb/outpages/form_process.php on line 10…it looks like my calling up that page is generating that error am I right? And when I try the word recipient instead of recipients in the form it gives me that same header error and emails me with no_recipient.

Thinking I might have needlessly over complicated the matter I overwrote the formmail.php I was using with a copy of formmail.php and renamed it to formmail.php to start fresh in case I accidently changed something I shouldn’t have in my formmail script and here is head of my form …

    &lt;form name="contactus" action="form_process.php" method="POST"&gt;
    &lt;input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" /&gt;
    &lt;input type="hidden" name="derive_fields" value="email=EmailAddr,realname=FullName" /&gt; &lt;!-- this derives (creates) "email" and "realname" special fields from the input fields --&gt;
    &lt;input type="hidden" name="mail_options" value="Exclude=email;realname" /&gt;  &lt;!-- this excludes the "email" and "realname" special fields from the body of the email you receive --&gt;
    &lt;input type="hidden" name="subject" value="Web page general comments" /&gt;
    &lt;input type="hidden" name='recipients' value="snoballdandd@q.com" /&gt; &lt;!-- change value to the recipient's email address //--&gt;
    &lt;input type="hidden" name="good_url" value="http://skeinfb/outpages/thanku.html" /&gt;
    &lt;input type="hidden" name="bad_url" value="http://skeinfb/outpages/error.html" /&gt;
    &lt;input type="hidden" name="redirect" value="http://skeinfb/outpages/thanku.html" /&gt; 

I click Submit and it takes me to my thanku.html page which is making headway but the problem is it takes me there even if I got the Captcha code wrong or even neglected to fill it out at all. I’ve taken out the redirect line with no change, the good_url line with no change and the bad_url line with no change. I didn’t get an error yet but the godaddy mail server is so slow sometimes it takes 20 minutes to email me.

You need to get rid of these lines first as they will do nothing:


<input type="hidden" name="bad_url" value="error.html" />
        <input type="hidden" name="good_url" value="thanku.html" />

What you need is to tell the form to process another page say ‘form_process.php’:


<form name="contactus" action="form_process.php" method="POST">

Inside the form process file you will then need to check all the form fields have been sent and not empty, have the correct data to process. If everything has passed then the thankyou page (or you could have the message on the same page) can be opened and formmail.php can be run. If thats not the case then the error page can be opened up (or you could have the error messages within the process page itself).

Example:


<?php
if(!empty($_POST['subject']) && !empty($_POST['recipient']))
{
   //thank you message or redirect the thank you page
   //include the formmail.php and send the data by using function pamas
}else{
  //display error message(s) or redirect to the error page
}

Did you name the input recipient or recipients? You mention both above, maybe you used the wrong plurality in your form.

Hi,

That’s now correct. It must be “recipients” with an “s”, not “recipient”.

and I copied the php code you provided and pasted it into a new file and put what I hoped is the right php code for the “thanku.html” and “error.html” into it and saved it as form_process.php. I don’t know php welll yet but at the end of the code that you gave me shouldn’t there have been a ?> to end the file or did you leave that out on purpose? When you said to send the data using function pamas I didn’t know what that was so I tried it without it. Is function pamas something that’s usedf a lot?, if so I can google it. Here’s my form_process.php code

<?php
if(!empty($_POST[‘subject’]) && !empty($_POST[‘recipient’]))
{
header(‘Location:thanku.html’);//thank you message or redirect the thank you page

include(‘formmail.php’); //include the formmail.php and send the data by using function pamas
}
else
{
header(‘Location:error.html’);//display error message(s) or redirect to the error page
}

?>

Please don’t add additional PHP code to FormMail. The above is not going to help you, so please remove it.


<input type="hidden" name="bad_url" value="error.html" />
<input type="hidden" name="good_url" value="thanku.html" />

This is correct and FormMail will redirect according to those instructions.

However, it only redirects to “good_url” when there are no errors! Otherwise it will redirect to “bad_url”.

I always recommend that you put in a full URL (e.g. “http://…/page.html”) otherwise you’re dependent on what the browser currently has in its address bar.

If you’re getting an error, please post the error message. Error messages are the key to solving all problems.

Make sure you have DEF_ALERT set inside FormMail so it can email you with detailed error messages. Test alerts with the “testalert” test.

The full HOW TO guide for redirecting is here:


Russell Robinson (http:://www.tectite.com/)
Author of Tectite FormMail

Hi Dan

I tried recipient in my form when I had one email address for a value and I used recipients when I had two. Trying to see if that did anything it didn’t really except when I tried spence’s reply after I heard from you.