SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation redirect script for form submit button

    feb 27 2005
    Needing to redirect to a thank you page as the submit button is clicked to send the form
    (php script does not redirect)
    The form is like this :

    ..........<form>
    <form method="post" action="?acao=enviar">
    .
    .
    .etc etc

    <!-- a couple of years ago I found a very simple script to be added to the line below that redirects to the thank you page -->

    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">



    </form>................



    Thank you very much for your reply.

  2. #2
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm unsure if this will help or not (because I'm kinda unsure about the situation), but you can redirect with php like this:

    PHP Code:
    header("Location: thankyou.php"); 
    Hope this helps

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello c1vineoflife
    I´ve searched for the answer through many PHP forums where people suppose I am not on a start ;
    I am feeling ashamed because I don´t know where to place header("Location: thankyou.php"); in the code ;
    I have exactly the following situation :



    <!-- this code is on form.php file -->


    <body>

    <?php

    if(@$acao=="enviar" && $_SERVER['REQUEST_METHOD']=="POST")
    {
    $Para="multi-media-mkt@uol.com.br";
    $Assunto="Formulário de email formmail.php";

    foreach($_POST as $indice=>$valor)
    {
    @$Mensagem=$Mensagem."$indice = $valor \r\n";
    }
    $email= $_POST["E-mail"];

    $Mensagem.="Usando : ".$_SERVER['HTTP_USER_AGENT']."\r\n";

    $Mensagem.="IP : ".$_SERVER['REMOTE_ADDR']."\r\n";

    $Mensagem.="Host: ".$_SERVER['HTTP_HOST']."\r\n";

    // echo nl2br($Mensagem);

    mail($Para,$Assunto,$Mensagem,"From:".$email );


    ?>

    <?php
    }else{
    ?>

    ..........<form>
    <form method="post" action="?acao=enviar">
    .
    .
    .etc etc



    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">



    </form>

    <?php
    }
    ?>


    </body>
    </html>

    .
    this script works since the email input field is correctly filled but as soon as the submit button is clicked
    the page becomes a blank , what makes the visitor unsure whether the form has been properly processed;
    it needs a redirect to a thankyoupage.htm where a message will confirm the form sending.
    Can you help me out with that ?
    thank you very much
    Cheers

  4. #4
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that is because in your if then statement you are asking for the $_SERVER['REQUEST_METHOD'] to be POST, when you are using a query string to obtain your variable values (which is the GET method). Change that line to this and see what happens:

    if ( @$acao == "enviar" && $_SERVER['REQUEST_METHOD'] == "GET" )

    William

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down

    Quote Originally Posted by c1vineoflife
    I think that is because in your if then statement you are asking for the $_SERVER['REQUEST_METHOD'] to be POST, when you are using a query string to obtain your variable values (which is the GET method). Change that line to this and see what happens:

    if ( @$acao == "enviar" && $_SERVER['REQUEST_METHOD'] == "GET" )

    William
    Hello William
    I changed the line as you suggested me and it seems it does not work.
    When submit is clicked the form seems to be processed but email is not sent ;
    I simply don´t manage to make this php form work

  6. #6
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is how I would write the script (keep in mind I don't speak spanish...so Im kinda guessing on context):

    Code:
    <html>
    <head>
    <title>
    
    </title>
    </head>
    <body>
    
    <?php
    
    $Para = "multi-media-mkt@uol.com.br";
    $Assunto = "Formulário de email formmail.php";
    
    $Mensagem = "";
    
    foreach($_POST as $indice => $valor) {
         @$Mensagem .= $Mensagem . "$indice = $valor \r\n";
    }
    
    $email = $_POST['E-mail'];
    $Mensagem .= "Usando : ".$_SERVER['HTTP_USER_AGENT']."\r\n";
    $Mensagem .= "IP : ".$_SERVER['REMOTE_ADDR']."\r\n";
    $Mensagem .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
    
    // echo nl2br($Mensagem);
    
    mail($Para, $Assunto, $Mensagem, "From: " . $email );
    ?>
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?acao=enviar" ?>">
    
    blah
    ...
    ...
    ...
    blah
    
    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">
    </form>
    
    </body>
    </html>
    Try that. If you are testing on your own computer it won't work (unless you have sendmail on your comp or something) If so, upload it to a server and then test it. But try that. and see if it works.

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello WIlliam
    As a matter of fact , that exotic language is not spanish , it is portuguese (I am in that silly country called Brazil unfortunattely ) , but it does not matter , your script works fine , as the form is submitted the page is returned with /contato.php?acao=enviar ;
    I am back to my original post , is there a simple way to redirect after submitting the form to a thank you page ? (I still need to give visitors the certainty that form has been properly processed)
    ps: I am not running the tests on my computer , so at every new test I have to upload the file to the server and test it on line ; I installed Apache but simply don´t manage to configure the http.conf ;
    by the way , how did you learn PHP :? Thank you very much for your support ;
    Cheers

  8. #8
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just wondering if this snippet is what your looking for:

    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00" onClick="location.href='yourpage.htm'">


    Hope this helps,

    SP

  9. #9
    SitePoint Enthusiast gunbound_boy's Avatar
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spacepoet
    Just wondering if this snippet is what your looking for:

    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00" onClick="location.href='yourpage.htm'">


    Hope this helps,

    SP
    I think if you use the above code, it will redirect to yourpage.htm, but if what the user submits is invalid, it still redirects to that page as well.
    I experienced that myself as well...

    For mi, my yourpage.htm is a php file which verifies that the information is correct and gives a thank you msg.

    Just my own thought
    SaintVida.com
    An online clothing store for the image conscious
    men and women of the modern era.

    http://www.saintvida.com.

  10. #10
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh...I don't know much about PHP; just thought that might work.

    I was worth a shot.

    Thanks,

    SP

  11. #11
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In order to redirect, you'd add something like:

    header("Location: yourpage.php");

    or something. Kind like this:

    Code:
    <html>
    <head>
    <title>
    
    </title>
    </head>
    <body>
    
    <?php
    
    $Para = "multi-media-mkt@uol.com.br";
    $Assunto = "Formulário de email formmail.php";
    
    $Mensagem = "";
    
    foreach($_POST as $indice => $valor) {
         @$Mensagem .= $Mensagem . "$indice = $valor \r\n";
    }
    
    $email = $_POST['E-mail'];
    $Mensagem .= "Usando : ".$_SERVER['HTTP_USER_AGENT']."\r\n";
    $Mensagem .= "IP : ".$_SERVER['REMOTE_ADDR']."\r\n";
    $Mensagem .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
    
    // echo nl2br($Mensagem);
    
    mail($Para, $Assunto, $Mensagem, "From: " . $email );
    ?>
    
    // The code is added below
    if ( $_GET['acao'] == "enviar" ) {
         header("Location: yourpage.php");
    }
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?acao=enviar" ?>">
    
    blah
    ...
    ...
    ...
    blah
    
    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">
    </form>
    
    </body>
    </html>
    Similarly, you could have something like this (where you wouldn't need to redirect to a thank you page):

    Code:
    <html>
    <head>
    <title>
    
    </title>
    </head>
    <body>
    
    <?php
    
    if ( $_GET['acao'] == "enviar" ) {
    
    
    // Thank you section
    
    echo "Thank you for blah blah blah kl saklkl al a."
    
    // END: Thank you section
    
    $Para = "multi-media-mkt@uol.com.br";
    $Assunto = "Formulário de email formmail.php";
    
    $Mensagem = "";
    
    foreach($_POST as $indice => $valor) {
         @$Mensagem .= $Mensagem . "$indice = $valor \r\n";
    }
    
    $email = $_POST['E-mail'];
    $Mensagem .= "Usando : ".$_SERVER['HTTP_USER_AGENT']."\r\n";
    $Mensagem .= "IP : ".$_SERVER['REMOTE_ADDR']."\r\n";
    $Mensagem .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
    
    // echo nl2br($Mensagem);
    
    mail($Para, $Assunto, $Mensagem, "From: " . $email );
    
    } else {
    ?>
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?acao=enviar" ?>">
    
    blah
    ...
    ...
    ...
    blah
    
    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">
    </form>
    
    
    <?php
    }
    ?>
    
    </body>
    </html>
    Oh, and I learned what little I know just by reading and practicing on my own, as I did with pretty much everything I know about web design.

    Hope this helps!

  12. #12
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ....... onClick="location.href='yourpage.htm'">
    I think this is not my luck night , despite the succesful submition no redirect occurred ;



    HI William

    // ...........................the header() ended up in the message below:
    if ( $_GET['acao'] == "enviar" ) {
    header("Location: yourpage.php");
    }

    Warning: Cannot modify header information - headers already sent by (output started at /home/wwwhead/public_html/contato.php:10) in /home/wwwhead/public_html/contato.php on line 69

    ...........and............

    The 2nd option:

    if ( $_GET['acao'] == "enviar" ) {


    // Thank you section

    echo "Thank you for blah blah blah kl saklkl al a."

    // END: Thank you section

    ..............................turned out the error message:

    Warning: Cannot modify header information - headers already sent by (output started at /home/wwwhead/public_html/contato.php:10) in /home/wwwhead/public_html/contato.php on line 69

    Thank you all for posting your replies.
    Cheers

  13. #13
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know PHP but in ASP you can't redirect once you have written ANYTHING to the document...I imagine it's the same.

    So that means that you have to process all that stuff, and have your redirect thingy BEFORE you even write <html>.

    Here's a shot (c1vineoflife's example rearranged):
    Code:
    <?php
    
    $Para = "multi-media-mkt@uol.com.br";
    $Assunto = "Formulário de email formmail.php";
    
    $Mensagem = "";
    
    foreach($_POST as $indice => $valor) {
         @$Mensagem .= $Mensagem . "$indice = $valor \r\n";
    }
    
    $email = $_POST['E-mail'];
    $Mensagem .= "Usando : ".$_SERVER['HTTP_USER_AGENT']."\r\n";
    $Mensagem .= "IP : ".$_SERVER['REMOTE_ADDR']."\r\n";
    $Mensagem .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
    
    // echo nl2br($Mensagem);
    
    mail($Para, $Assunto, $Mensagem, "From: " . $email );
    
    
    // The code is added below
    if ( $_GET['acao'] == "enviar" ) {
         header("Location: yourpage.php");
    }
    ?>
    <html>
    <head>
    <title>
    
    </title>
    </head>
    <body>
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?acao=enviar" ?>">
    
    blah
    ...
    ...
    ...
    blah
    
    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">
    </form>
    
    </body>
    </html>

  14. #14
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimfraser
    I don't know PHP but in ASP you can't redirect once you have written ANYTHING to the document...I imagine it's the same.

    So that means that you have to process all that stuff, and have your redirect thingy BEFORE you even write <html>.

    Here's a shot (c1vineoflife's example rearranged):
    Code:
    <?php
    
    $Para = "multi-media-mkt@uol.com.br";
    $Assunto = "Formulário de email formmail.php";
    
    $Mensagem = "";
    
    foreach($_POST as $indice => $valor) {
         @$Mensagem .= $Mensagem . "$indice = $valor \r\n";
    }
    
    $email = $_POST['E-mail'];
    $Mensagem .= "Usando : ".$_SERVER['HTTP_USER_AGENT']."\r\n";
    $Mensagem .= "IP : ".$_SERVER['REMOTE_ADDR']."\r\n";
    $Mensagem .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
    
    // echo nl2br($Mensagem);
    
    mail($Para, $Assunto, $Mensagem, "From: " . $email );
    
    
    // The code is added below
    if ( $_GET['acao'] == "enviar" ) {
         header("Location: yourpage.php");
    }
    ?>
    <html>
    <head>
    <title>
    
    </title>
    </head>
    <body>
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?acao=enviar" ?>">
    
    blah
    ...
    ...
    ...
    blah
    
    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">
    </form>
    
    </body>
    </html>

    That makes sense. It looks like it should work

  15. #15
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ha ha ! eureka , now it works ;
    so many thanks William for your support ;
    Cheers

  16. #16
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Welcome! Glad to help! And thanks to jimfraser for actually putting out code that works!

  17. #17
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that´s true , it was Jim who has alerted you concerning the location of code ;

    --todavia en tiempo : a Jimfraser , saludo a UD. y le agradezco por hecharme su mano-----------

    However I´ve been so naive in believing that all the troubles have been solved ;

    I submitted a form and I´ve got an absurd as follows :

    this is only a small fraction of the sent message:

    Empresa = company
    Empresa = company
    estado = AC-Acre
    Empresa = company
    Empresa = company
    estado = AC-Acre
    segmento_de_mercado_ = (selecione)
    .
    etc , etc , etc .......<!-- it has turned out a very long list of this rubish -->
    .

    Depto =
    codigo_area =
    telefone =
    E-mail = sender@email.com
    url_do_site =
    mensagem = message
    Submit = Enviar
    Usando : Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; FunWebProducts-MyWay)
    IP : 200.100.93.111
    Host: www.headlineassociados.com


    On my form I´ve got two <select name.... , several <input type...., some <input type="radio" ..... , and a text area ;
    I think it is necessary a more complex logic on the script in order for this to work properly ;
    what do you say about that?

  18. #18
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lets see your form then Ron...veamos tu formulario - y el codigo que le procesa.

  19. #19
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hola Jimfraser

    El formulário es algo muy sencillo , te lo envio abajo para que lo veas ; sigue también la pregunta : ? si ello requiere de un código PHP en específico para su procesamiento correcto ?

    (the form is something very simple , I will post it right below so that you can take a look at it ;
    this goes with a question :
    if it requires a specific PHP code for the correct submission ?)
    Could not comprehend the trouble I described on my last post ;
    Cheers
    RW
    ----------------------------------------------------------------------------
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?acao=enviar" ?>">
    <input type="text" name="Empresa" value="" maxlength="50" size="45" style class="formbg">

    <select name="estado" size="1" style class="formbg">
    <option value="value">( Selecione )</option>
    <option selected>AC-Acre</option>
    <option>AL-Alagoas</option>
    <option>AM-Amazonas</option>
    <option>AP-Amapá</option>
    <option>BA-Bahia</option>
    <option>CE-Ceará</option>
    <option>DF-Distrito Federal</option>
    <option>ES-Espírito Santo</option>
    <option>GO-Goiás</option>
    <option>MA-Maranhão</option>
    <option>MG-Minas Gerais</option>
    <option>MS-Mato Grosso do Sul</option>
    <option>MT-Mato Grosso</option>
    <option>PA-Pará</option>
    <option>PB-Paraíba</option>
    <option>PE-Pernambuco</option>
    <option>PI-Piauí</option>
    <option>PR-Paraná</option>
    <option>RJ-Rio de Janeiro</option>
    <option>RN-Rio Grande do Norte</option>
    <option>RS-Rio Grande do Sul</option>
    <option>RO-Rondônia</option>
    <option>RR-Roraima</option>
    <option>SC-Santa Catarina</option>
    <option>SE-Sergipe</option>
    <option>SP-São Paulo</option>
    <option>TO-Tocantins</option>
    </select>

    <select name="segmento de mercado " size="1" style class="formbg">
    <option selected>(selecione)</option>
    <option>Indústria</option>
    <option>Comércio</option>
    <option>outro</option>
    </select>

    <input type="text" name="nome _solicitante" maxlength="50" size="35" style class="formbg">
    <input type="text" name="cargo" size="20" maxlength="25" style class="formbg">
    <input type="text" name="Depto" size="20" maxlength="25" style class="formbg">
    <input type="text" name="codigo area" size="15" maxlength="5" style class="formbg">
    <input type="text" name="telefone" size="15" maxlength="15" style class="formbg">
    <input type="text" name="url do site" size="50" maxlength="50" style class="formbg">

    <input type="radio" value="sistema de gest&atilde;o" name="sistemagestao">
    ..... un total de cinco radio buttons .......
    <textarea name="mensagem" rows="10" cols="50" style class="formbg"></textarea>


    <input type="submit" name="Submit" value="Enviar" style="background-color: #ffcc00">

    </form>
    ----------------------------------------------------------------------------

  20. #20
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it would actually be easier to use a hidden form field to check if the user has submitted the form, because then they couldnt just type in ?acao=enviar. It would use post data, like this:

    PHP Code:
    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
    blah
    ...
    ...
    ...
    blah

    <input type="hidden" name="success" id="success" value="yes" />

    </form>

    <?php

    if ( isset($_POST['success']) ) {
         
    $success $_POST['success'];
    } else {
         
    $success "no";
    }

    if ( 
    $success == "yes" ) {

    // this is all the stuff you do to your form when it is submitted

    }

    ?>

  21. #21
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    somewhere over the rainbow
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    getting back to: <form method="maito:...."
    it´s a poor solution but at last it works


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
  •