publicly populate a list field

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 23, 2009   (RSS)

Re: [Shore] publicly populate a list field

By Chris - November 20, 2009

Hi Shore,

I'm having trouble figuring out exactly what it is you're trying to accomplish. Can you please attach the complete PHP source code for the page (or pages) you're working on so I can take a closer look?
All the best,
Chris

Re: [chris] publicly populate a list field

By Shore - November 20, 2009

Hi Chris,

Attached is my php.

In CMS Builder, organization.activity is a list field that pulls it's values from another table called activities using num as the value and title as the label.

Between lines 273-275

<select multiple name="activity[]" id="activity" style="margin-left: 280px;"><?php foreach ($activitiesRecords as $recordActivity): ?>
<option value="<?php echo $recordActivity['title'] ?>"><?php echo $recordActivity['title'] ?></option><?php endforeach; ?>
</select>


I'm attempting to post it's array value and insert it into the organization.activity list field.

Appreciate any help. Let me know if you have any questions.

Thanks

Re: [Shore] publicly populate a list field

By Chris - November 23, 2009

Hi Shore,

Multi-value fields are stored in CMS Builder's databases as a tab-separated list of values, with extra tabs on both ends to facilitate easy searching.

When submitting a form with a <select multiple> with an "array name" (eg. activity[]), PHP should be giving you an array of values. Since you said above that "$num is the value", you'll want to make sure that your <option values> are record "nums":

<select multiple name="activity[]" id="activity" style="margin-left: 280px;"><?php foreach ($activitiesRecords as $recordActivity): ?>
<option value="<?php echo $recordActivity['num'] ?>"><?php echo $recordActivity['title'] ?></option><?php endforeach; ?>
</select>

To convert the array of values to a tab-padded, tab-separated list, you can use the following code:

activity = '\t".mysql_real_escape_string( join("\t", $_REQUEST['activity'] ) )."\t',

I hope this helps! Please let me know if you have any questions.
All the best,
Chris