Inserting a variable in an array

9 posts by 3 authors in: Forums > CMS Builder
Last Post: September 19, 2011   (RSS)

Hi All,

I’m selecting entries in a multi value list (checkbox) and trying to use them to populate an array (in the showHideFieldsForUsers plugin) with the checked values from the list, to get the following result:

'value1' => array('list_option_1','list_option_2', 'list_option_3','list_option_4'),

SO FAR
From a table called Subscriber Level Values and a multi-value checkbox list field called entry_level, I can generate a list of the list options in the correct format by using:
<?php $output = "'". join("', '", getListValues('subscriber_level_values', 'entry_level', $subscriber_level_valuesRecord['entry_level'])) ."'" ; ?>
And
<?php echo $output ; ?>
Which produces:
'list_option_1', 'list_option_2', 'list_option_3', 'list_option_4'
QUESTION
How can I add the list generating code to the array code, so that the values of that array are pulled from the checked values in the list?

(I've tried adding load records and a get records calls to the top of the plugin, defining the $output variable and changing the array code to 'value1' => array($output), but that didn’t work. )

Any suggestions?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Inserting a variable in an array

By Jason - August 25, 2011

Hi Jerry,

I'm a little confused as to what you're trying to accomplish. Are you trying to get an array of values of what was checked in the 'entry_level' field.

If you could provide some more clarification, we can see if we can make some suggestions.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Inserting a variable in an array

Hi Jason,

Thanks for looking at this.

Yes, with the values from the entry_level field.

I’m trying to populate the array that’s included in the showHideFieldsForUsers plugin with values pulled from the entry_level field, so that the client doesn’t have to call me to make changes.

The format of the array in the plugin is currently:
'value1' => array('list_option_1','list_option_2', 'list_option_3','list_option_4'),
As I mentioned above, the "$output" variable outputs the values in the correct format, I’m not sure how to incorporate that code into the array code to render a working array which includes those values.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Inserting a variable in an array

By Jason - August 25, 2011

Hi Jerry,

How about something like this:

'value1' => explode("\t", trim($subscriber_level_valuesRecord['entry_level'], "\t")),

That will assign an array of values selected in 'entry_level' to the array element 'value1'

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Inserting a variable in an array

By gkornbluth - August 25, 2011 - edited: August 25, 2011

Hi Jason,

I gave it a try and it didn’t throw any errors that broke the plugin, (there are other values that are hard coded into the plugin, and they work) but this one's not working and I can’t tell what that line is actually outputting.

Any way that I can display the output?

Thanks,

Jerry

Here’s the code from the plugin in context.
<?php
require_once "/server_path_to/cmsAdmin/lib/viewer_functions.php";

list($subscriber_level_valuesRecords, $subscriber_level_valuesMetaData) = getRecords(array(
'tableName' => 'subscriber_level_values',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$subscriber_level_valuesRecord = @$subscriber_level_valuesRecords[0]; // get first record

?>

<?php


// CAVEATS:
// - it is not currently possible to hide Separator fields.

// UPDATE THESE VALUES

$GLOBALS['BETA_USER_SKILL_FIELDS_SKILL_FIELD_NAME'] = 'allowedFolders';

// For each section, copy this block
$GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG']['master_subscription_pages'] = array(

// user's skill values and lists of fields to hide
'value1' => explode("\t", trim($subscriber_level_valuesRecord['entry_level_hide'], "\t"))

);

// DON'T UPDATE ANYTHING BELOW THIS LINE

// register hooks
addFilter('edit_buttonsRight', 'beta_user_skill_fields_edit_filter', null, 3);

// add javascript to edit pages
function beta_user_skill_fields_edit_filter($html, $tablename, $record) {
global $CURRENT_USER;
$hiddenFields = @$GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG'][$tablename][@$CURRENT_USER[$GLOBALS['BETA_USER_SKILL_FIELDS_SKILL_FIELD_NAME']]];
if (!$hiddenFields) { return $html; }

?>
<script>
$(function(){
<?php foreach($hiddenFields as $hiddenField): ?>
$('*[name="<?php echo $hiddenField; ?>"]').closest('TR').hide();
$('*[name^="<?php echo $hiddenField; ?>:"]').closest('TR').hide();
$('#<?php echo $hiddenField; ?>_iframe').closest('TR').hide();
<?php endforeach; ?>
});
</script>
<?php

return $html;
}

?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [robin] Inserting a variable in an array

Thanks Robin,

That really helped get things sorted out.

Your original suggestion actually worked, however, the array was only updated on new records and not on existing ones. So when I looked for changes in fields that showed in existing records, even after a save, there was no change and all fields continued to be shown, leading to much confusion on my part.

Anyway, it works now (for new records) and I can live with that, although I'm curious if there's a way for existing records to be updated as well.

Thanks again,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [robin] Inserting a variable in an array

By gkornbluth - September 16, 2011 - edited: September 19, 2011

Hi Robin,

My client pointed out a somewhat embarrassing issue.

It seems that when a new record is created using the normal "create" button, the showHideFieldsForUsers plugin restrictions are followed.

However, when the new record is created using the "Create Records Here" button created by Dave's createRecordsHere plugin, the showHideFieldsForUsers restrictions are ignored.

Any "quick fix" ideas?

Thanks,

Jerry Kornbluth

Both plugins are on the user submitted add on page, and are attached as well (the attached showHideFieldsforUsers is as modified as described above).
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Inserting a variable in an array

By Jason - September 19, 2011

Hi Jerry,

I took a look into this on my installation and was unable to re-create this issue.

So you're saying that if you click the normal "create" button, you only see the fields you're supposed to according to the show/hide field plugin. But if you click "Create Record Here", you see everything. Is that right?

Can you provide any more information on the issue (ie, CMS Version, etc).


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/