⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to insert custom CSS in forms?



tanver
  • profile picture
  • Member

Posted 07 December 2011 - 12:55 PM

I want to insert some Custom CSS element [e.g., to have two-col layout] in the default Add/Edit generated forms, would appreciate if anyone or the Admin can give me some pointers to achieve this.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 07 December 2011 - 19:09 PM

[quote name='tanver' timestamp='1323262518' post='99']
I want to insert some Custom CSS element [e.g., to have two-col layout] in the default Add/Edit generated forms, would appreciate if anyone or the Admin can give me some pointers to achieve this.
[/quote]
A simple way to do this is to use the getState method. You have to use it always after the render function. You can see an example at: http://www.grocerycr...n_name/getState . In your case you will do something like this:


.....
$crud->set_subject(....);
.....
$crud->...etc
$output = $crud->render();

$state = $crud->getState();

if($state == 'add')
{
$output->css_files[] = base_url().'assets/css/yourcustom.css';
$output->css_files[] = base_url().'assets/css/yourcustom2.css';
}
elseif($state == 'edit')
{
$output->css_files[] = base_url().'assets/css/yourcustom.css';
$output->css_files[] = base_url().'assets/css/yourcustom2.css';
}
$this->_example_output($output);
....


The same thing you can do it with javascript also. I have a solution to have it in the views. But because in every version something could change in javascript/css/views it is better to not change the core.

tanver
  • profile picture
  • Member

Posted 07 December 2011 - 19:34 PM

Thanks for the response and I am sorry if my question was not clear enough. I actually want to change the standard layout [like to have a 2-col layout] of the forms generated for adding and editing the contents, and want to insert separate div etc at different points. Or if possible can you guide me through how to have a two column layout for add/edit forms?