Forums

Checkbox and Input field link

gresham 26 Nov, 2009
Hi There,

I am creating a quotation form with check boxes and input fields for the quantity.
My problem is that if the user selects checkbox 1 and 3 and enters the quantity for these items then when the posting is done this is my result.

$_POST Array: Array ( [text_name] => Myname [text_email] => test@test.com [text_number] => 0988 [text_0] => Array ( [0] => 12 [1] => [2] => 34 ) [check0] => Array ( [0] => Shirt1 [1] => Shirt3 ) [text_1] => Array ( [0] => [1] => ) [text_2] => Array ( [0] => [1] => 123 [2] => [3] => ) [check2] => Array ( [0] => Shoe2 ) [button_11] => Submit [1fdf275d75ded6d29c01ef6c329508a7] => 1 [1cf1] => 


As you can see TEXT_0 has values
[0] => 12
[1] =>
[2] => 34

But the CHECK0 has
[0] => Shirt1
[1] => Shirt3
* [1] is supposed to be empty same as TEXT_0 and [2] is supposed to have value "Shirt3"

How can i make sure that the checkboxes return corresponding values as my input box so that i dont get only 2 values but all 3 even if the second checkbox is NOT selected ?

below is my partial code for the form
foreach ($t_rows2 as $itemnames) { 
$tloop = $tloop + 1;
?>    
      <td width=300 NOWRAP align=left> <?php echo "$itemnames"; ?> </td>
      <td width=50 NOWRAP align=left> <input class="cf_inputbox" maxlength="5" size="3" title="" id=<?php echo '"text_'.$checkb.'[]"'; ?> name=<?php echo '"text_'.$checkb.'[]"'; ?> </td>
      <td width=25 NOWRAP align=left> <input value=<?php echo '"'.$itemnames.'"' ; ?> title="" class="radio" id=<?php echo '"'.$catnames.$tloop.'"' ?> name=<?php echo '"check'.$checkb.'[]"'; ?> type="checkbox" /> </td>
</tr>
<?php } 


Thanks
GreyHead 26 Nov, 2009
Hi gresham,

Not sure I understand your question. Checkboxes only return values if they are selected (otherwise you can't tell if they are selected or not).

If I need to know what isn't selected then I compare the values returned with an array of the possible names.

Bob
gresham 26 Nov, 2009
Hi Bob, thanks for a quick response.

well this is the setup

________________________________________
ITEM QTY Checkbox
________________________________________
Shirt1 |__| (Ticked/Not ticked)
Shirt2 |__| (Ticked/Not ticked)
Shirt3 |__| (Ticked/Not ticked)

So i would like to send an email with what the user has ticked.
Eg if user selects Shirt1 and Shirt3, then an email should send the QTY for shirt1 and shirt3. But because the checkboxes do not store "unchecked" values i am getting
[text_0] => Array ( [0] => 12 [1] => [2] => 34 ) <---- Quantity for Shirts
[check0] => Array ( [0] => Shirt1 [1] => Shirt3 ) <---- Items that have been ticked

Now if i run a loop to produce a table layout of this in the email i will use
Text_0[0], Text_[2]
Check0[0], Check0[2]
But since Check0[2] does not even exist i am getting incorrect output.

I think that if there is a way to have a default value for the unselected checkboxes, then that should work.

I think my problem relates exactly to this post
http://www.chronoengine.com/forums.html?cont=posts&f=5&t=15903&p=40726&hilit=checkbox+string+replace#p40726
However i also do not understand how to use the string substitution. An eg would be great.

TIA
nml375 26 Nov, 2009
Hi,
I read this thread rather quickly, so I apologize if I'm off-topic..

I gathered that you are using several array-type inputs, and wish for the indexes to correlate between the inputs. For thi to work reliably, you'äl need to include the desired index in the input name (unfortunately, most, if not all, browsers have no clue as to keping this correlation betwen the inputs...).

Considder something like this:
<input type="text" name="text_1[1]" /><input type="checkbox" name="check_1[1]" /><br />
<input type="text" name="text_1[2]" /><input type="checkbox" name="check_1[2]" />...


/Fredrik
gresham 27 Nov, 2009
Hi all,

thank you for all your suggestions and comments.
I have managed to solve my problem using the following method (perhaps not the best or prettiest but it works)

i added a hidden field with the same name and a default value and after this i added the checkbox. This means that even if the checkbox is not selected i still have the field name that i can query against.

Remember im using array checkbox :

<input type="hidden" name="checkbx[0]" value="0" />
<input value="item1" title="" class="radio" id="chkb" name="checkbx[0]" type="checkbox" />


Hope this helps anyone else looking for a similar solution. :wink:
Max_admin 29 Nov, 2009
gresham, great solution, always used in this situation!😉

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.