Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Online dictionary creator

24

Comments

  • MarkMark Vanilla Staff
    edited August 2005
    $MyArray = new array(); $MyArray["id"] = $id; $MyArray["name"] = $name; $MyArray["value"] = $value;

    :D
  • edited August 2005
    You can make the name attributes of a form element part of an array with php.
    
    your html:
    
    <input type="text" name="defs[1][name]" value="definition name one" />
    <input type="text" name="defs[1][value]" value="definition value one" />
    
    <input type="text" name="defs[2][name]" value="definition name two" />
    <input type="text" name="defs[2][value]" value="definition value two" />
    
    ----
    server side:
    
    print_r($_POST['defs']);
    
    makes:
    
    Array (
        [defs] => Array
            (
                [1] => Array
                    (
                        [value] => definition value one
                        [name] => definition name one
                    )
    
                [2] => Array
                    (
                        [value] => definition value two
                        [name] => definition name two
                    )
    
            )
    )
    
  • well i'd figured that much, but how do i do that in a form? Like usually the name of an element would become a variable assigned with the value of the value of an element. That makes sense to me but is written dreadfully.
  • If you want to speed up Mark's way, lose the double quotes and use singles. Singles aren't checked for internal variables, so will parse faster.
    
    $MyArray = new array();
    $MyArray['id'] = $id;
    $MyArray['name'] = $name;
    $MyArray['value'] = $value;
    
    or even go for :
    
    $MyArray=array();
    array_push($MyArray, $id, $name, $value);
    
    if you don't need keys to be named.

    M.
  • hmm. got it. What if the id needs to be gotten from a variable? like would name="defs[$w][name]" work?
  • yes, so long as you escape things properly.
    
    $w='somevar';
    echo"
    <input type=\"text\" name=\"defs[$w][name]\" value=\"\" />
    ";
    
    
    M.
  • i cant believe i just asked that question. sorry, *gets back to coupling and coding.
  • haha never mind - we all have lapses! M.
  • edited August 2005
    Right, so say i have <input type='hidden' name='DefRef[0][name]' value='ThisLanguageName'> <input type='text' name='DefRef[0][value]' value='English'> How do i then read those values when the stuff has been posted?
  • Hold up, i'm being useless again.
  • Right, so i now have http://www.badassg.me.uk/lussumo/dictionary.php working to output http://www.badassg.me.uk/lussumo/Creation.txt God knows why it doesnt like 8-37. The rest looks ok though.
  • looking good mini! you might want to widen those inputs though :D
  • Yeah, how? Do i have to absolutely size them or can i make them grow depending on the contents?
  • CSS is your friend:
    
    input {
              width : 200px;
    }
    
    M ;-)
  • Cheers, i'll add that when i get home. What else needs doing?
  • Make sure that the attributes (name, value, title etc) are all enclosed in double quotes, not singles. <input type='text' name='foo' /> != good <input type="text" name="foo" /> == good M.
  • Does that matter? I've always used singles, force of habit i guess.
  • Yeah - it's invalid HTML. It'll take your browser longer to render, and won't make any pages validate. If possible it's better to write valid code, because it avoids silly bugs and makes cross-browser compliance a whole lot better. M.
  • fair enough, i'll sort that when i get back too. It'l make my code all messy and escaping-slashified though :(
  • in your php, change all double quotes to single, that will make everything within those quotes literal
This discussion has been closed.