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 9 of 9
  1. #1
    New Coder
    Join Date
    Sep 2002
    Location
    Australia
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variables and Values

    Hi,
    This is my first attempt at php, I have a form where the user selects colors on page 1 those colors are printed on the second page as hidden fields that works fine but how do I pass those values onto the select fields?

    When I use the below form it returns

    col1 instead of #A6A6A6

    I have tried changing the select values to $col1 and $_GET[col1]
    But I am obviously looking at this the wrong way

    Any help much appreciated


    Code:
    <FORM ACTION="" METHOD="GET" TARGET="<?php $PHP_SELF ?>" >
    <input type="hidden" name="col0" id="col0" value="#808080" />
    <input type="hidden" name="col1" id="col1" value="#A6A6A6" />
    <input type="hidden" name="col2" id="col2" value="#CCCCCC" />
    <input type="hidden" name="col3" id="col3" value="#7F7F7F" />
    <input type="hidden" name="col4" id="col4" value="#A6A6A6" />
    <input type="hidden" name="col5" id="col5" value="#CCCCCC" />
    <input type="hidden" name="col6" id="col6" value="#7F7F7F" />
    <input type="hidden" name="col7" id="col7" value="#7F7F7F" />
    <input type="hidden" name="col8" id="col8" value="#000000" />
    <select name="body[color]">
    				<option value="">None</option>
    				<option value="col0">1</option>
    				<option value="col1">2</option>
    				<option value="col2">3</option>
    				<option value="col3">4</option>
                                       <option value="col4">5</option>
                                       <option value="col5">6</option>
    				<option value="col6">7</option>
    				<option value="col7">8</option>
    				<option value="col8">9</option>
    			</select>
                             <select name="div[color]">
    				<option value="">None</option>
    				<option value="col0">1</option>
    				<option value="col1">2</option>
    				<option value="col2">3</option>
    				<option value="col3">4</option>
                                       <option value="col4">5</option>
                                       <option value="col5">6</option>
    				<option value="col6">7</option>
    				<option value="col7">8</option>
    				<option value="col8">9</option>
    			</select>
    <INPUT TYPE="SUBMIT" NAME="" VALUE="submit"></form>
       
       <?php
       
    
       echo("$body[color]");
        echo("$div[color]");
    
    
    ?>

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    PHP Code:
    <?
    echo $_REQUEST['body']['color']; //or $_GET
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Sep 2002
    Location
    Australia
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks,
    but using either request or get still output the same value ie col1 not the hex code from the hidden fields.

    this returns the correct value
    Code:
    <?
    
    
    
    
    if ( $_GET['body']['color'] == 'col0' ) {
    echo $_GET['col0'];
    }
    
    ?>
    But with around 100 fields using the hidden color fields that would be ugly code

    Any other sugestions?

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    echo $_GET[$_GET['body']['color']];


    just 1 comment unless you plan on having multiple colors for body u really don't need that body array.

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    Quote Originally Posted by oztinks
    But with around 100 fields using the hidden color fields that would be ugly code Any other sugestions?

    <option value="#FFFFFF">1</option>

    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New Coder
    Join Date
    Sep 2002
    Location
    Australia
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <option value="#FFFFFF">1</option>
    Life would be simpler but so much more boring

    Thanks Garadon that has done the trick but.... why is there always a but?
    The body array has other values some using the hidden fields others from normal user input and I was going to use foreach to display all the values but now those values are empty

    this is the return from this form with bold selected for font-weight
    Code:
    color : #7F7F7F ;
    background-color : #A6A6A6 ;
    font-weight : ;
    a bigger bit of the form looks like this

    Code:
    <FORM ACTION="" METHOD="POST" TARGET="<?php $PHP_SELF ?>" >
    <input type="hidden" name="col0" id="col0" value="#808080" />
    <input type="hidden" name="col1" id="col1" value="#A6A6A6" />
    <input type="hidden" name="col2" id="col2" value="#CCCCCC" />
    <input type="hidden" name="col3" id="col3" value="#7F7F7F" />
    <input type="hidden" name="col4" id="col4" value="#A6A6A6" />
    <input type="hidden" name="col5" id="col5" value="#CCCCCC" />
    <input type="hidden" name="col6" id="col6" value="#7F7F7F" />
    <input type="hidden" name="col7" id="col7" value="#7F7F7F" />
    <input type="hidden" name="col8" id="col8" value="#000000" />
    <select name="body[color]">
    				<option value="">None</option>
    				<option value="col0">1</option>
    				<option value="col1">2</option>
    				<option value="col2">3</option>
    				<option value="col3">4</option>
                                       <option value="col4">5</option>
                                       <option value="col5">6</option>
    				<option value="col6">7</option>
    				<option value="col7">8</option>
    				<option value="col8">9</option>
    			</select><select name="body[background-color]">
    				<option value="">None</option>
    				<option value="col0">1</option>
    				<option value="col1">2</option>
    				<option value="col2">3</option>
    				<option value="col3">4</option>
                                       <option value="col4">5</option>
                                       <option value="col5">6</option>
    				<option value="col6">7</option>
    				<option value="col7">8</option>
    				<option value="col8">9</option>
    			</select>
    
    			<select name="body[font-weight]'">
    				<option value="">Normal</option>
    				<option value="bold">Bold</option>
    			</select>
    
                   <INPUT TYPE="SUBMIT" NAME="" VALUE="submit"></form>
    
     <?php
    
      $p = &$_POST;
     $body = '';
      foreach($p['body'] as $key => $value) {
    $body .=  $key . ' : ' .  $p[$value] . " ;<br />";
    
    }
    
    echo $body ;
    ?>
    Am I going about this the wrong way?

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    Quote Originally Posted by oztinks
    Life would be simpler but so much more boring
    sorry I should be more verbose ... I mean

    PHP Code:
    <?
    $cols 
    =array('#808080','#A6A6A6','#CCCCCC','#7F7F7F','#A6A6A6','#CCCCCC','#7F7F7F','#7F7F7F','#000000');
    ?>
    <select name="body[color]">
        <option value="">None</option>
        <?foreach($cols as $k=>$v){?>
        <option value="<?=$v;?>">col<?=$k.' ('.$v.')';?></option>
       <?}?>
    </select>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    New Coder
    Join Date
    Sep 2002
    Location
    Australia
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by firepages
    sorry I should be more verbose
    No need to apologise, I am finding php pretty confusing but I got a good laugh imagining my form with a single color option "white"


    Thanks for the code I have changed my hidden elements to an array and it works fine when I drop the code into my page, but I have a function to write the color selection and I cant get that to work I guess it is about making my array global but after 5 hours I am still no closer to figuring out how to make it work

    the broken function is
    PHP Code:
    function colorselect($tag)
    {
    echo 
    '<select name="' $tag '">
        <option value="">None</option>'
    ;
           foreach(
    $cols as $k=>$v){
    echo 
    '<option value="'.$v.'">col'.$k.' ('.$v.')</option> </select>';

      }
      } 

  • #9
    New Coder
    Join Date
    Sep 2002
    Location
    Australia
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    DUHHHH...


    Quote Originally Posted by oztinks
    I guess it is about making my array global
    Guess I knew what to do all along
    PHP Code:
    global $cols
    Now it works


  •  

    Posting Permissions

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