Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 10 of 10

Thread: Form Redirect problem

  1. #1

    Form Redirect problem

    Hi all

    Like 'olicourse' i'm trying to get my form to redirect to a webpage (http://www.kirupa.com/forum/showthread.php?t=337218).

    I want to redirect to here:
    http://www.communityspiritacupunctur...k/formcomplete

    but no matter what I try it's not working. I really don't know what i'm doing wrong.

    The form works fine otherwise (thanks v. much for the great tutorial )

    code:
    --

    <?php

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


    $to = "info@communityspiritacupuncture.co.uk";
    $subject = "Website Query";
    $name_field = htmlspecialchars($_POST['name']);
    $email_field = htmlspecialchars($_POST['email']);
    $message = htmlspecialchars($_POST['message']);

    foreach($_POST['check'] as $value) {

    $check_msg .= "Checked: $value\n";

    }

    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

    $header="From: $email_field\r\n";

    mail($to, $subject, $body);

    header("Location:formcomplete.phtml");

    } else {

    echo "blarg!";

    }
    ?>



    any help would be much appreciated.
    Andy

  2. #2
    like the reply for the other thread, you need to set the mail function to have the from field:

    PHP Code:
    mail($to$subject$body$header); 

  3. #3

    Hope this helps

    Quote Originally Posted by selenium View Post
    Hi all

    Like 'olicourse' i'm trying to get my form to redirect to a webpage (http://www.kirupa.com/forum/showthread.php?t=337218).

    I want to redirect to here:
    http://www.communityspiritacupunctur...k/formcomplete

    but no matter what I try it's not working. I really don't know what i'm doing wrong.

    The form works fine otherwise (thanks v. much for the great tutorial )

    code:
    --

    <?php

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


    $to = "info@communityspiritacupuncture.co.uk";
    $subject = "Website Query";
    $name_field = htmlspecialchars($_POST['name']);
    $email_field = htmlspecialchars($_POST['email']);
    $message = htmlspecialchars($_POST['message']);

    foreach($_POST['check'] as $value) {

    $check_msg .= "Checked: $value\n";

    }

    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

    $header="From: $email_field\r\n";

    mail($to, $subject, $body);

    header("Location:formcomplete.phtml");

    } else {

    echo "blarg!";

    }
    ?>



    any help would be much appreciated.
    Andy


    PHP Code:
    if(mail($to$subject$body))
     {
      
     echo 
    "<script language=\"JavaScript\"> alert (\"You are already logged in. If it is not you, Please log out of this account.\");
                             window.location=\"formcomplete.phtml\";
                             </script>"
    ;
     }
     else
     {
      echo 
    "Form couldnot be submitted,";
     } 
    hope this helps.

  4. #4
    Quote Originally Posted by utsav View Post
    PHP Code:
    if(mail($to$subject$body))
     {
      
     echo 
    "<script language=\"JavaScript\"> alert (\"You are already logged in. If it is not you, Please log out of this account.\");
                             window.location=\"formcomplete.phtml\";
                             </script>"
    ;
     }
     else
     {
      echo 
    "Form couldnot be submitted,";
     } 
    hope this helps.
    oh wow ... no ... that's a terrible solution.

    selenium, what does the form do? is it submitting, or is it returning the "Can not modify header information" which is the most common error for people and redirects.
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    well Simplistick i know using JS is not good but i thought it might help him for the time being. And yes with this i need to ask why is it considered bad practice? I really dont know the reason though i know it is bad.

  6. #6
    Quote Originally Posted by utsav View Post
    well Simplistick i know using JS is not good but i thought it might help him for the time being. And yes with this i need to ask why is it considered bad practice? I really dont know the reason though i know it is bad.
    Well it's a cheap hackish work around really. PHP already provides a way to natively redirect a page. Also, it's dependent on javascript being enabled on your visitors' browser. Which of course like 90% of all people have js enabled, but you still want to make it as functional across the board as you can, and the PHP method works 100% of the time. Oh and not to mention
    HTML Code:
    <script language="JavaScript">
    is outdated markup
    HTML Code:
    <script type="text/javascript">
    is the proper way
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  7. #7
    Thanks for your replies looinspain, simplistik and ustav.

    the form is sending information, but the browser just directs to the blank page www....co.uk/mailer.php.

    Even with the modification to the line looinspain suggested:

    -----

    <?php

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


    $to = "info@communityspiritacupuncture.co.uk";
    $subject = "Website Query";
    $name_field = htmlspecialchars($_POST['name']);
    $email_field = htmlspecialchars($_POST['email']);
    $message = htmlspecialchars($_POST['message']);

    foreach($_POST['check'] as $value) {

    $check_msg .= "Checked: $value\n";

    }

    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

    $header="From: $email_field\r\n";

    mail($to, $subject, $body, $header);

    header("Location:formcomplete.phtml");

    } else {

    echo "blarg!";

    ---


  8. #8
    try this:
    PHP Code:
    $redirecturl "http://www.communityspiritacupuncture.co.uk/formcomplete.phtml";

    header("Location: $redirecturl"); 

  9. #9
    Quote Originally Posted by LooInSpain View Post
    try this:
    PHP Code:
    $redirecturl "http://www.communityspiritacupuncture.co.uk/formcomplete.phtml";

    header("Location: $redirecturl"); 
    not any different from the way he had his header, also he already fixed the problem
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  10. #10
    thanks all for your help, i ended up modifying oilcorse's code to suit my form. not sure why his worked and mine didn't, but anyway, sorted now..

    thanks again

    andy

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012