⚠ 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

Is there any way to divide the inputs



xxaxxo
  • profile picture
  • Member

Posted 10 April 2012 - 10:24 AM

Here is the thing - I have a db with around 25 - 30 fields, 10 of them are "required" , i'd like when the user presses add - to view only the required fields, and i'd like to add a custom action button - if the user needs to add more info - to be able to add more from it.
So - is there any way to divide the add - fields - other than changing the add fields with "if" like:

if($required_fields=="") {
$crud->fields('required_field','required_field','required_field','required_field');
} else {
$crud->fields('additional_info_field','additional_info_field','additional_info_field');
}


Thanks

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

Posted 10 April 2012 - 19:30 PM

An easy way to do it is by using a parameter to your URL to be more specific you can simply have something like this:

function offices_management($more = null, $operation = null)
{
//This will simply redirect you from /demo/offices_management/1 to /demo/offices_management
if($more == "1" && $operation != "edit" && $operation != 'update')
redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__));

$crud = new grocery_CRUD();

$crud->set_table('offices');
...
if($more == '1')
$crud->fields('field_1','field2','field3',...);
else
$crud->fields('field_1','field2','field3',...);

$crud->add_action('More Details', '/images/more_details.png', 'demo/offices_management/1/edit');

$output = $crud->render();

$this->_example_output($output);
}



Ok I know when you will first see this hack you will say: "What the ....". So let me explain :

The :

$crud->add_action('More Details', '/images/more_details.png', 'demo/offices_management/1/edit');

is easy to understand that you will have urls like this: demo/offices_management/1/edit/345, demo/offices_management/1/edit/356, demo/offices_management/1/edit/357, ....e.t.c.
I really tried hard to make grocery CRUD work as a simple library so if you add for example: "demo/offices_management/1/edit/345" or "demo/offices_management/1/whatever/78/edit/345" or "demo/offices_management/1/89/78/edit/345" grocery CRUD auto-recognize that the only info that it is needed for the library is the "edit/345" . This is really useful to add parameters to the url as normal.

The most clever part is that grocery CRUD take all the parameters to the URL and follows you to all the operations. You can see a live example at: http://www.grocerycr.../full_example/1 (I just add a 1 at the end of the URL), you will see that the 1 is been followed everywhere. To the add, to the edit , to the delete ...e.t.c. So that's why you will also need the:


if($more == "1" && $operation != "edit" && $operation != 'update')
redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__));


I hope I didn't make it complicated for you. Even if the answer is yes , you can simply copy-paste the code that I post to you :P

xxaxxo
  • profile picture
  • Member

Posted 11 April 2012 - 06:32 AM

Nah , everything is fine - I got it , thank's for the reply.