⚠ 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

Additional arguments for change_field_type()



Elnur Akhundov
  • profile picture
  • Member

Posted 03 September 2012 - 07:21 AM

Good day!

I'm new to GCRUD, so maybe somebody more experienced can help me.

Let say we have tables `htp_items`, there is column `category_ids` which is varchar (255)

When I use:



$crud->change_field_type('category_ids','set', array('banana' => 'banan value','orange','apple','lemon'));



Question 1: It's inserts/updates with the option name not with it's value. How can I change the behaivor of updating?

I need to be like this:
<option value="banana_value">Banana</option>
<option value="orange_value">Orange</option>

So update data should contain: "banana_value" not "Banana"


Question 2: Is is possible to add suffix/prefix to the data which will insert/update?
Example: When I add a new record I need to add prefix "," and the same suffix "," to data.

Let say we update the same "category_ids" as I mentioned below and update should be like this:


UPDATE `htp_items` SET `category_ids` = "[b],[/b]banana_value,orange_value[b],[/b]" WHERE `id` = 1

Elnur Akhundov
  • profile picture
  • Member

Posted 03 September 2012 - 07:29 AM

UPD:
IMHO there is solution to the second question is to use [b]callback_after_update()[/b]

First question is still open.

noskov.biz
  • profile picture
  • Member

Posted 03 September 2012 - 09:26 AM

Hi, Elnur Akhundov and welcome to the forum!
Please, see the following topics: this one and also this one. I hope that will help you.

Elnur Akhundov
  • profile picture
  • Member

Posted 03 September 2012 - 12:28 PM

Thank you for your reply. I've make a few tweaks myself.

File: grocery_crud.php
Line: 2089...2092


foreach($options_array as $key => $option)
{
$selected = !empty($value) && in_array($key,$selected_values) ? "selected='selected'" : '';
$input .= "<option value='$key' $selected >$option</option>";
}

noskov.biz
  • profile picture
  • Member

Posted 04 September 2012 - 06:28 AM

Thanks for sharing the code :)