1

I'm using Joomla 2.5 and have a problem while fooling aroung with my first component.

I use the following fieldset in a form:

<fieldset>      
    <field
        name="person_id"
        type="hidden"
    />
    <field
        name="person_email"
        type="text"
        label="Email"
        description="Email"
        size="40"
        class="inputbox"
        default=""
    />
    <field
        name="person_notification"
        type="text"
        label="Notification"
        description="Notification"
        class="checkbox"
    />
</fieldset>

The email field is working as expected and updates the database entry. The notification field is making me trouble. The value is not set.

I have read about this issue here and here. I tried to adapt the method 2 from the second link, but it didn't help me. The code I tried was:

<fieldset>      
    <field
        name="person_id"
        type="hidden"
    />
    <field
        name="person_email"
        type="text"
        label="Email"
        description="Email"
        size="40"
        class="inputbox"
        default=""
    />
    <input type="hidden" name="jform[person_notification]" value="0" />
    <input type="checkbox" name="person_notification" class="inputbox" />
</fieldset>

The checkbox is not visible at all in this case, because in my edit.php I use

<?php foreach($this->form->getFieldset() as $field): 
   if ($field->label!="") {
       echo '<li>'.$field->label.$field->input.'<br/></li>';
   } else {
       echo '<li>'.$field->input.'</li>';             
   }?>

So I think I have to adapt method 2 to use field tags, but I don't know how to do this. Can anybody tell me, how I have to define my filedset to get this working? I have read this SO question, but I am not sure, whether this is exactly the problem I am experiencing.

I am aware of the possibility to use radio buttons, but my requirements don't allow this workaround. Changing anything in the core joomla code or updating to version 3 is also no valid possibility in my case.

Community
  • 1
  • 1
LostAvatar
  • 795
  • 7
  • 20
  • I'm not sure if it will make a difference, but have you tried removing the white spaces? So try changing this : `name = "person_notification"` to this `name="person_notification"` – Lodder Aug 30 '13 at 11:44
  • @Lodder No, unfortunately this doesn't change anything. – LostAvatar Aug 30 '13 at 12:01
  • 1
    What about the solution suggested [here](http://stackoverflow.com/a/11613965/268093)? It uses a `` in the `XML` and overrides the model's `bind()` method to handle the case where the checkbox is unchecked. – MasterAM Aug 30 '13 at 15:10

1 Answers1

1

I can't see anything wrong.

Try replicating the functionality using the Joomla Component Creator http://www.component-creator.com and see what the difference is.

Søren Beck Jensen
  • 1,676
  • 1
  • 12
  • 22
  • @MasterAM I had tried this and it did not work. I tried a minimal example with the creator and it worked.. And it seems, it generated exactly what I tried before.. Must have made a mistake. Thanks to you both. Would have never tried this approach again on my own, because I thought it was wrong. – LostAvatar Aug 30 '13 at 16:29
  • 1
    the Joomla checkbox will only return a value if the checkbox is checked, and you need to work around this in your code; this is why so many extensions use type="list" with the options values set to 0 and 1. Try changing it to the list type, add two options and see if your code works as expected, this will be a quick workaround. – Riccardo Zorn Aug 31 '13 at 08:46