Support » Plugin: PHP code snippets (Insert PHP) » redirect code

  • hi
    i want to have a redirection after a test .
    in my page :

    <form action="" method="post">
       <input type="checkbox" name="prenom[]" value="adriana" />Adriana<br>
       <input type="checkbox" name="prenom[]" value="alessandra" />Alessandra<br>
       <input type="checkbox" name="prenom[]" value="candice" />Candice<br>
       <input type="checkbox" name="prenom[]" value="lili" />Lili<br>
       <input type="submit" value="Envoyer" />
    </form>
    
    [wbcr_php_snippet id="352"]

    and the code of my snippet

    foreach($_POST['prenom'] as $valeur)
    {
          header('Location: https://www.test.ojjo.ca/inscription/ ');
    }

    for the test when i submit, i want to change the page. But i come back to the same page .

    do you know what wrong ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author webcraftic

    (@webcraftic)

    Hi,
    Create a snippet with this code, you can modify it for yourself:

    
    function wbcr_prenom_redirect()
    {
    	if( isset($_POST['prenom']) ) {
    		wp_redirect('https://www.test.ojjo.ca/inscription/');
    		die();
    	}
    }
    
    add_action('template_redirect', 'wbcr_prenom_redirect');
    

    This snippet should be run everywhere.

    Best regards, Alex

    • This reply was modified 1 month, 3 weeks ago by  webcraftic.

    hi
    thank you very much
    but i have now a select option

    <form action="" method="post">
    
    "Inscription poussin né en 2014"<select name=poussin[]> 
    <option selected> 0 
    <option> 1 
    </select> 
    
    "Inscription enfant né en 2015 et +"<select name=enfants[]> 
    <option selected> 0 
    <option> 1 
    <option >2
    </select> 
       <input type="submit" value="Valider" />
    </form>

    and i want to have a redirection with 2 conditions.
    code of my snippet

     
    if(($_POST['poussin'] == "1") and ($_POST['enfants'] == "0")){
    
      header('Location: https://www.inscriptionsoccervg.ojjo.ca/inscription-un-poussin/');
    }

    But it doesn’t work !!
    could you help me please

    thanks

    ok thank you it works

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.