PDA

View Full Version : $_GET and $_POST variables are not recognized?!


pianoman993
01-03-2009, 01:52 AM
Hello there Vbulletin experts I have a bit of a problem. I have a page that has $_GET variables in the URL. The problem is that Vbulletin is not recognizing that there are variables there so for instance if my script says print $_GET['variable'] I get nothing. Here's what I got.

I have a custom template named SOUND_SEARCH


<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'SOUND_SEARCH'); // change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(

);

// get special data templates from the datastore
$specialtemplates = array(

);

// pre-cache templates used by all actions
$globaltemplates = array(
'TEST',
);

// pre-cache templates used by specific actions
$actiontemplates = array(

);

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################

$navbits = array();
$navbits[$parent] = 'Sound Search';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('SOUND_SEARCH') . '");');

?>


A form that submits data


<div style="border:1px solid #333;padding:15px;">
<form name="search" method="get" action="soundsearch.php">
<input type="text" style="width:110px;" name="search_value" /> in
<Select name="category">
<Option value="songs">Songs</option>
<Option value="artists">Artists</option>
</Select>
<input type="submit" name="search" value="search" />
</form>
</div>


A page that receives that data ( the page that will not read the $_GET data )


<?php
echo $_GET['search'];
?>


So basically if my url was www.mysite.com/index.php?variable=helloworld

and I had a template that included a php page that had this:


<?php echo $_GET['search']; ?>


I would get nothing instead of helloworld...

Anybody have any ideas?

Any help would be greatly appreciated, thanks!

- pianoman993

Lynne
01-03-2009, 02:29 AM
You don't have a variable named "search" in your form. You should probably go read up on forms and php. Also, you can't put php in a template like your line of code above.

pianoman993
01-03-2009, 02:41 AM
I'm not putting the php code directly in a template file. I am using a plugin to include the php file externally.

Lynne
01-03-2009, 02:54 AM
Well, my first comment remains.... the only two things you defined in the forum are named "search_value" and "category"

pianoman993
01-03-2009, 03:01 AM
Alrighty, so here are the two pages I'm having trouble with.

Here is the original PHP page that has this code:


<?php
echo $_GET['category'];
?>

Sorry, the search page is currently under construction...


Here is the link...

As you can see, everything is working as it is supposed to be.

---------

This page has a simulated form request as you can tell by the present $_GET variables in the URL.

But this time to information was grabbed from the URL.

Do you know why this might be? I took you up on your variable suggestion by changing the variable to category.

- Pianoman993

Lynne
01-03-2009, 03:21 AM
Try putting something like:

$myvar = $_GET['category'];

in soundsearch.php prior to evaling the template. Then, in the template, put $myvar somewhere. Does that work?

pianoman993
01-03-2009, 03:32 AM
Ahhh! I believe we have an answer. I prepped the plugin variable with a $_GET['category'] variable. Vbulletin was now aware of that and parsed the value. Woot!

Thank you for all your help :-D

Lynne
01-03-2009, 03:38 AM
It also exists as $myvar in the php page soundsearch.php. Isn't that the script you wanted to use it in?

pianoman993
01-03-2009, 03:43 AM
Ah, I wasn't aware of that! Now we have two methods.

BlueChipEarth
02-25-2010, 02:51 PM
I've got a similar problem:

http://www.lawnsite.com
http://www.lawnsite.com/forumdisplay.php?f=123

That's one BB with an internal style set to one of the forums, so you get a "Lawnsite" style and "LHDB Site" style.

I've set up the search in the LHDB style to search only within that forum (and child forums). The problem is, when you search, it sets the style back to Lawnsite's style, but only shows results from LHDB Site (forum). What I wanted to do was set another $_POST variable (forumstyle) that would be picked up in the "style_fetch" hook, and set the style to LHDB site (so that people don't get confused, and so when they search again they'll again be searching LHDB... basically making them seem like two separate websites).

I then tried to use a cookie, but it seems to work intermittently...

I'd much rather go with the $_POST method, but I can't seem to get the variable back in the style_fetch hook... Is there some way I can get ahold of this variable without actually editing the search.php file?

--------------- Added 1267122981 at 1267122981 ---------------

Well, I went with a cookie that expires in 5 seconds... if anyone has a suggestion that's better than this, please let me know!!! I'm still curious as to how we can get ahold of $_POST data through hooks after a search... and still use this information to change the style with style_fetch.

vBulletin is such a massive beast... ><