SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Did you name the input recipient or recipients? You mention both above, maybe you used the wrong plurality in your form.

  3. #3
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    You need to get rid of these lines first as they will do nothing:
    Code:
    <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':
    Code:
    <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 Code:
    <?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
    }
    "Don't you just love it when you solve a programming bug only to create another."

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi spence

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

    <form name="contactus" action="form_process.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='recipients' value="snoballdandd@q.com" /> <!-- change value to the recipient's email address //-->

    // 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.

  6. #6
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Australia
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by GRM47 View Post
    Hi spence

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

    <input type="hidden" name='recipients' value="snoballdandd@q.com" /> <!-- change value to the recipient's email address //-->
    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.

    HTML Code:
    <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:
    http://www.tectite.com/fmhowto/redir.php

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

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by russellr View Post
    Hi,



    That's now correct. It must be "recipients" with an "s", not "recipient".
    It's currently recipients and it will stay that way.
    Quote Originally Posted by russellr View Post
    Hi,
    Please don't add additional PHP code to FormMail. The above is not going to help you, so please remove it.
    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.

    Quote Originally Posted by russellr View Post
    HTML Code:
    <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.
    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.


    Quote Originally Posted by russellr View Post
    Make sure you have DEF_ALERT set inside FormMail so it can email you with detailed error messages. Test alerts with the "testalert" test.
    It is set it emails me and says "no_recipients"

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 .......

    <form name="contactus" action="form_process.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='recipients' value="snoballdandd@q.com" /> <!-- change value to the recipient's email address //-->
    <input type="hidden" name="good_url" value="http://skeinfb/outpages/thanku.html" />
    <input type="hidden" name="bad_url" value="http://skeinfb/outpages/error.html" />
    <input type="hidden" name="redirect" value="http://skeinfb/outpages/thanku.html" />

    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •