Disabled Fields - Still Pass though non-disabled data - CAKEPHP 2
I have a form which has many fields, I need to display some of them as
read only / disabled for staff level users while admin level users can
save or modify all fields.
I have setup the following javascript which shows the fields as read only
however it doesn't pass any of the data though to the model,
$this->request->data is a blank array with this javascript on.
<?php if ($this->Session->read('Auth.User.group_id') == 3) { ?>
<script type="text/javascript">
$(function () {
$('.adminOnlyField').attr("readonly","true");
$('.checkbox.adminOnlyField').attr("onclick","return false");
$('.checkbox.adminOnlyField').attr("onkeydown","return false");
$('.adminOnlyField').removeClass('required');
$('.adminOnlyField').removeClass('date_picker');
$('.adminOnlyField').prop('disabled', 'disabled');
});
</script>
<?php } ?>
I need the staff users to be able to see the data but not change it for
these fields with the class of adminOnlyField, the rest they should be
able to edit / update.
Thanks
I then though maybe when the submit button is hit I could remove the
readonly and disabled with jquery such as follows:
$('.clear_ready_only').click(function(e)
{
e.preventDefault();
$('.adminOnlyField').removeAttr('disabled');
$('.adminOnlyField').removeAttr('readonly');
$('#CardModifysaleForm').submit();
});
It doesn't seem to work though?
No comments:
Post a Comment