Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Code help

  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post

    Unhappy Code help

    Hello,
    I am new to PHP coding, and I need help with a code.

    PHP 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?
    Last edited by Chames; 12-28-2005 at 07:45 PM.

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    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 Code:
    <?php
    $boxes 
    = array(

    => '&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;'
    ,

    => '&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>

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thank you very much, it works!

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    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])
    Code:
    [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!

  • #5
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    that is a javascript question. this is a PHP forum. post that question in the appropriate forum.

  • #6
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    Oh, right. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •