I have switched over to using the power of jQuery for many things now and will start posting those solutions.
Here is a teaser. I use the following lines of code, placed in the header.php file to turn some fields off or make them read only. Works really well. I place it just above the </head> tag. This way I can just have certain fields showing based upon the group. The example below just allows the admin to see all the fields. It turns some off or disables them based upon group. You can do it many ways. (I have left my field names in for ease of explanation)
I echo the lines to get them to work within the php script. I also put in the full word jQuery for ease of understanding. You could use the short form as seen a few lines above this in the header file if you look at your header.php file. Here is the line in the header.php file which gives you the variable to use to call jQuery in the short form. <script>var $j = jQuery.noConflict();</script>. It is what Ahmed has set for the noConflict option in jQuery.It should work but would not for me and I did not have time to figure out why.
What I do is wrap it in a php statement as following:
Code: Select all
<?php
if(getLoggedGroupID() != 2){
echo "<script>jQuery(document).ready(function(){ jQuery('#paid0, #paid1, #paid2').attr('disabled', true);});</script>";
echo "<script>jQuery(document).ready(function(){ jQuery('#datestopped').hide();});</script>";
echo "<script>jQuery(document).ready(function(){ jQuery('#confirmed1, #confirmed2, #confirmed3, #confirmed4').attr('disabled', true);});</script>";
}
?>
if(getLoggedGroupID() != 2){ - this line gets the group number of the person logged in and if not group 2 (two) executes the code below. It does this by calling the getLoggedGroupID() function.
echo "<script>jQuery(document).ready(function(){ jQuery('#paid0, #paid1, #paid2').attr('disabled', true);});</script>"; - this line calls jQuery and then when the document is ready - very important - it then finds fields paid0, paid1, paid2 and disables them. By only disabling them the end user can see them but not change their setting. Only someone with the correct permissions can change the setting (in this case a radio button). But is is important for the end user to see the setting.
echo "<script>jQuery(document).ready(function(){ jQuery('#datestopped').hide();});</script>"; - This line does the same thing but instead of disabling it hides the datestopped field from being seen.
The third line above is the same as the first.
A couple of points:
The only way I could get jQuery to run as a script was to echo it out of the php function. Works but I think there may be a better way.
Next it is very important how you put in the quotes. Notice where I have the double and single quotes. Would not work any other way.
Yes the code can be shorter and my real example is. I have combined multiple lines into one but felt this example was a better way to show it.I will be using the power of jQuery more and will post more examples and methods as I go along.
I did not try this as a hook as it worked so well in the header.php file.
Enjoy
As usual any questions just ask.
Alan