...

View Full Version : Code help



Chames
12-28-2005, 07:40 PM
Hello,
I am new to PHP coding, and I need help with a code.


<?
if ($HTTP_POST_VARS['check']) {

$box=$HTTP_POST_VARS['box1']; //as a normal var
$box_count=count($box); // count how many values in array

foreach ($box as $dear) {
echo $dear."<br>";
}
echo "<hr>";
}
?>
<form name="hede" method="POST" action="">
<input type="checkbox" name="box1[]" value="

&lt;Effect name="ARMY Change Name"&lt;
&lt;Param name="SrcArmy" dispName="$$22348$$Army" VarType="group"&lt;default&lt;/Param&lt;
&lt;Param name="NewName" dispName="$$23784$$Name" varType="stringid"&lt;Name&lt;/Param&lt;
&lt;Command&lt;trArmySelect("%SrcArmy%");&lt;/Command&lt;
&lt;Command&lt;trUnitChangeName("%NewName%");&lt;/Command&lt;
&lt;/Effect&lt;

"> Army change name <br>

<input type="checkbox" name="box1[]" value="
&lt;Effect name="ARMY Damage"&lt;
&lt;Param name="SrcArmy" dispName="$$22348$$Army" VarType="group"&lt;default&lt;/Param&lt;
&lt;Param name="DamageAmt" dispName="$$23762$$DamagePct" varType="float"&lt;1&lt;/Param&lt;
&lt;Command&lt;trArmySelect("%SrcArmy%");&lt;/Command&lt;
&lt;Command&lt;trDamageUnit(%DamageAmt%);&lt;/Command&lt;
&lt;/Effect&lt;

">Army damage<br>

<input type="submit" name="check" value="SEND">

</form>

In the "value" area, I changed the "<" to "&lt; I assumed that this would work, but it isn't. Also, there are many more options in the final, but to save space I didn't put them all here. Here is what I want to happen, the user selects the boxs, and when he presses submit, the code will appear on top, but I just can't get it to work!Some help would be greatly appreciated, whats wrong with it?

devinemke
12-28-2005, 08:52 PM
the quotes are screwing up your HTML output. rather than passing all of that rather unwieldly code in your form why not just pass a pointer to an array. something like this:


<?php
$boxes = array(

1 => '&lt;Effect name="ARMY Change Name"&lt;
&lt;Param name="SrcArmy" dispName="$$22348$$Army" VarType="group"&lt;default&lt;/Param&lt;
&lt;Param name="NewName" dispName="$$23784$$Name" varType="stringid"&lt;Name&lt;/Param&lt;
&lt;Command&lt;trArmySelect("%SrcArmy%");&lt;/Command&lt;
&lt;Command&lt;trUnitChangeName("%NewName%");&lt;/Command&lt;
&lt;/Effect&lt;',

2 => '&lt;Effect name="ARMY Damage"&lt;
&lt;Param name="SrcArmy" dispName="$$22348$$Army" VarType="group"&lt;default&lt;/Param&lt;
&lt;Param name="DamageAmt" dispName="$$23762$$DamagePct" varType="float"&lt;1&lt;/Param&lt;
&lt;Command&lt;trArmySelect("%SrcArmy%");&lt;/Command&lt;
&lt;Command&lt;trDamageUnit(%DamageAmt%);&lt;/Command&lt;
&lt;/Effect&lt;'

);

if (isset($_POST['box']))
{
foreach ($_POST['box'] as $value) {echo $boxes[$value] . '<br>';}
echo '<hr>';
}
?>

<form action="" method="POST">
<input type="checkbox" name="box[]" value="1">Army change name<br>
<input type="checkbox" name="box[]" value="2">Army damage<br>
<input type="submit" name="check" value="SEND">
</form>

Chames
12-28-2005, 09:55 PM
Thank you very much, it works!

Chames
12-29-2005, 08:07 PM
I can't get the "check all" and "uncheck all" script to work with this code, any help? Also can I have a "group select" button. Example:

([]=checkbox) ([button])


[check all]
[uncheck all]

[]Select all army
[] army...
[] army...
[] army...
[] army...

[]Select all QV
[] QV...
[] QV...
[] QV...

Thats the basic layout I want. Thanks for all the help!

devinemke
12-29-2005, 08:17 PM
that is a javascript question. this is a PHP forum. post that question in the appropriate forum.

Chames
12-29-2005, 10:00 PM
Oh, right. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum