Support » Plugins » Hacks » $_GET in a function in functions.php

  • Hello,

    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 ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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>

    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.

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘$_GET in a function in functions.php’ is closed to new replies.