I have a frontend module with this php file under tmpl folder. It fills with joomla's published categories and shows a checkbox for each one, based on current registered user preferences from a table:
<div class="userfavcats<?php echo $moduleclass_sfx ?>">
<div class="row-striped">
<?php foreach ($list as $item) : ?>
<div class="row-fluid">
<div class="span6">
<strong class="row-title">
<?php echo $item->name; ?>
</strong>
</div>
<div class="span3">
<input type="checkbox" name="data" value="<?php echo $item->id; ?>" <?php if($item->selected) echo(" checked ");?>/>
</div>
</div>
<?php endforeach; ?>
<input type="submit" value="Save" />
</div>
The idea is to allow the user to check/uncheck categories and send that new selection to the module and save it back to the DB. I haves the following code in my mod_userfavcats module, based on helloworld com_ajax sample. The problem is that don´t know how to obtain each checked value as an array, for example.
(function ($) {
$(document).on('click', 'input[type=submit]', function () {
var value = $('input[name=data]').val(),
request = {
'option' : 'com_ajax',
'module' : 'userfavcats',
'data' : value,
'format' : 'raw'
};
$.ajax({
type : 'POST',
data : request,
success: function (response) {
$('.status').html(response);
}
});
return false;
});
})(jQuery)
thank you very much !