$_GET in a function in functions.php (4 posts)

  1. sam_beckett
    Posted 4 years ago #


    In my comments.php I inserted a form :

    <form name="myForm" action="" method="GET" style="float:right" >
    		<SELECT NAME="format">
    <OPTION>Test 1
    <OPTION>Test 2
    		<SELECT NAME="ordre">
    <OPTION>Example 1
    <OPTION>Example 2
    	<input type="submit" name="submit" value="Trier">

    I want to store the selected value in a cookie, so I added this function to my functions.php :

    function set_navi_cookie() {
    $sc_ordre = $_REQUEST['ordre'];
    setcookie('naviga',$sc_ordre,time()+60, COOKIEPATH, COOKIE_DOMAIN, false);
    add_action( 'init', 'set_navi_cookie');

    but $sc_ordre is null. I tried $_REQUEST['ordre']; but it's always null.

    What I did wrong ?

  2. Peter Wilson
    Posted 4 years ago #

    Does it work if you change the select to:

    <SELECT NAME="ordre">
    <OPTION value="Example 1">Example 1</OPTION>
    <OPTION value="Example 1">Example 2</OPTION>
  3. sam_beckett
    Posted 4 years ago #

    Thanks for your help, but no, it doesn't work. I think that </option> is not needed in this example.

    I can catch the passing variables in single.php for exemple but not in functions.php where I need it.

  4. Mark / t31os

    Posted 4 years ago #

    It's invalid not to have closing tags for options, so yes they are required if you want to write valid code.

    $sc_ordre will be null outside the function because it only has scope inside the function.

    About variable scope

Topic Closed

This topic has been closed to new replies.

About this Topic