PDA

View Full Version : Echoing A Variable?


paul41598
11-16-2006, 09:02 PM
Im doing something very basic and Im stumped for whatever reason.

Basically in the showthread template I have a text line called

<input type="text" name="testme" value="$testme" size="12">

When I click the perform action button it should echo whats in the variable "a.k.a" a string.

In postings.php Im trying to echo $testme;

No luck. Make sense?

Antivirus
11-16-2006, 09:20 PM
i think you need to place your var within "" like


echo "$testme";

paul41598
11-16-2006, 10:27 PM
naw that didnt work either. Hmm...


In postings.php I have


if ($_POST['do'] == 'test')
{
echo "$testme";
}

in the showthread template I have:

<div><label for="ao_cct"><input type="radio" name="do" id="ao_cct" value="outputit" />OutPut It!</label></div>

<input type="text" name="testme" value="$testme" size="12">

That code is right beneath all the other admin functions like Split Thread, Move Thread, etc. So when you hit Perform action, it should post that variable back.


I'm not even sure if Im doing this right...



Ok I did a

if (isset($testme)) {
echo "$testme";
}
else {
echo "crap";
}


and I saw the word crap, which means the variable isnt being passed or SET

Guest190829
11-17-2006, 06:42 PM
Where are you setting $testme?

paul41598
11-17-2006, 06:48 PM
in a text box, value="$testme"

and the text box is actually under one of the radio buttons in the threadadmin manage. see below

Guest190829
11-17-2006, 06:52 PM
in a text box, value="$testme"

and the text box is actually under one of the radio buttons in the threadadmin manage. see below

The variable will be in the $_POST array, but you would use vBulletin's built in sanitizing array:

$vbulletin->input->clean_gpc('p', 'testme', TYPE_NOHTML));

The new variable would be:

$vbulletin->GPC['testme']

paul41598
11-17-2006, 07:03 PM
wow that worked! Thankyou so much, I'm sure I'll have more questions later to be asked now that I got past this part. Thanks again Danny

what about a checkbox variable sir? How do I pass that on?

Guest190829
11-17-2006, 07:39 PM
wow that worked! Thankyou so much, I'm sure I'll have more questions later to be asked now that I got past this part. Thanks again Danny

what about a checkbox variable sir? How do I pass that on?

Checkboxes are held in arrays so it would be something like:


<input type="checkbox" name="options[]" value="x">

<input type="checkbox" name="options[]" value="y">

<input type="checkbox" name="options[]" value="y">
The php code would be:


$vbulletin->input->clean_gpc('p', 'options', TYPE_ARRAY));
And $vbulletin->GPC['options'] would be an array of all the values that were checked.

paul41598
11-17-2006, 08:12 PM
Thanks Danny, seems to be working so far!

Guest190829
11-17-2006, 08:45 PM
I'm glad everything is working. Get into the habit of sanitizing all of your variables, as it is a security risk if you don't.

If you need more information on it, there is documentation inside the file at

includes/class_core.php

:)

paul41598
11-18-2006, 12:11 AM
b.t.w, what do I do if I need to add two more case statements to pre-existing code already in postings.php?

case 'stylizethread': for example.

I tried to make a hook outta it, but it doesnt work.

<plugin active="1">
<title>Thread Cosmetics (Add To Switch)</title>
<hookname>threadmanage_action_switch</hookname>
<phpcode><![CDATA[
switch ($_REQUEST['do'])
{
case 'stylizethread':
}
]]></phpcode>
</plugin>