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?
Disabled fields do not pass thru
POST
, you are doing:which makes it
readonly
, and it can pass thruPOST
, but at end you disable the same field again by doing:this line makes it
disabled
due to which it does not getPOST
'ed. So if you want to make it pass thruPOST
, make itreadonly
, and remove the following line: