CI 3 - Form helper and hidden fields. Am I doing this right? |
[eluser]talkingnews[/eluser]
I'm using PyroCMS which is built on CI 3 (so it says) and following this guide, most stuff seems to work. But I'm having a hard time figuring out the array to use for hidden fields. form_hidden doesn't work for anything requiring more than a basic name and value. And I HAVE to have an id field in there, so in the form_data it goes, with the type=hidden value. I tried a two dimensional array first: Let's build up a small array: Code: $trackdata = array(); using Code: $theform = form_open('formtest2') . form_input($trackdata) . form_submit('submit', 'Update') . form_close(); gives me Quote:<form action="http://test.co.uk/formtest2" method="post" accept-charset="utf-8"> Whereas Code: $theform = form_open('formtest2') . form_input($trackdata[0]). form_input($trackdata[1]) . form_submit('submit', 'Update') . form_close(); gives me Code: <form action="http://test.co.uk/formtest2" method="post" accept-charset="utf-8"> Well, the latter is more like it. But the only way I could get my multiple fields was like this: Code: <?php Took me a while to figure out, and it works fine, but I have this sneaking suspicion there's a better/tidier/more proper way to be doing this? And, no, posting the hidden array as the third parameter ( Code: $hidden = array('username' => 'Joe', 'member_id' => '234');
[eluser]TWP Marketing[/eluser]
[quote author="talkingnews" date="1347728822"] Took me a while to figure out, and it works fine, but I have this sneaking suspicion there's a better/tidier/more proper way to be doing this? And, no, posting the hidden array as the third parameter ( Code: $hidden = array('username' => 'Joe', 'member_id' => '234'); This works fine for me under V 2.1.2 and I don't think it will be different under V 3.0 (not yet released) When you say "it doesn't work", do you mean the hidden vars are not output as source code?
[eluser]talkingnews[/eluser]
What I meant was that if I build an array of $hidden and put it in Code: form_open('email/send', '', $hidden) Code: <input type="hidden" name="0[type]" value="hidden" /> and if I put the array in form_hidden, then it produces something along the lines of Code: <input type="hidden" name="name1" value="hidden" id="name1" name="name2" value="hidden" id="name2" name="name2" value="hidden" id="name2" name="name2" value="hidden" id="name2"/> It's quite possible (though unlikely!) that I am doing in the correct way in my first post, it just seems a bit odd and unnecessary the way hidden fields are handled differently to input fields, when essential the only difference should be the "type=hidden" part.
[eluser]TWP Marketing[/eluser]
[quote author="talkingnews" date="1347741773"]What I meant was that if I build an array of $hidden and put it in Code: form_open('email/send', '', $hidden) Code: <input type="hidden" name="0[type]" value="hidden" /> and if I put the array in form_hidden, then it produces something along the lines of Code: <input type="hidden" name="name1" value="hidden" id="name1" name="name2" value="hidden" id="name2" name="name2" value="hidden" id="name2" name="name2" value="hidden" id="name2"/> It's quite possible (though unlikely!) that I am doing in the correct way in my first post, it just seems a bit odd and unnecessary the way hidden fields are handled differently to input fields, when essential the only difference should be the "type=hidden" part.[/quote] It's treating the two dimensional array as only one dimensional and creating a unique key for each value. You could build that array as a one D matrix and retrieve it using a similar process. Code: $i = 0 |
Welcome Guest, Not a member yet? Register Sign In |