Membership: how to inject form data into CMSB database - more advanced than readme.txt offers

By Codee - February 18, 2013

Hi group,

I am using the membership plugin and have been following the readme.txt for creating a set of radio button options for injecting a choice into the accounts section of the database. BUT because in my accounts section I have a field called "team" that corresponds to a section called "Teams" and is an auto filled dropdown. So, obviously when I follow these instructions in building the html form:

"<tr>
   <td valign="top">Team</td>
   <td>
     <?php $fieldname = 'team'; ?>
     <?php $idCounter = 0; ?>
     <?php foreach (getListOptions($GLOBALS['WSM_ACCOUNTS_TABLE'], $fieldname) as $value => $label): ?>
       <?php $id = "$fieldname." . ++$idCounter; ?>
       <input type="radio" name="<?php echo $fieldname ?>" id="<?php echo $id ?>"
             value="<?php echo htmlspecialchars($value) ?>" <?php checkedIf(@$_REQUEST[$fieldname], $value) ?> />
       <label for="<?php echo $id ?>"><?php echo htmlspecialchars($value) ?></label><br/>

     <?php endforeach ?>
   </td>
  </tr>
"
The injected field for "team" into the Accounts table is only the number.  I'm thinking there's probably a couple of ways to work with this, but I don't fully understand how to do any of them, so I am asking for help.

Possibility 1) I tried using a variety of methods for using the :label pseudofield since it's a php coded form, but was unsuccessful. Is there an easy way to make that work?

Possibility 2) Is there a way to set the getListOptions to the TEAMS table instead of the ACCOUNTS table but still inject the field into the accounts table at the @$_REQUEST point? I was unsuccessful with these attempts to. and,

Possibility 3) Is there a better way?

By gregThomas - February 19, 2013 - edited: February 19, 2013

Hi Equinox,

I think your going about this the right way, I would create radio buttons like this:

<?php  $options = getListOptions('category', 'userNum'); ?>

<?php foreach($options as $key => $value): ?>

<label><input type="radio" name="team" value="<?php echo $key; ?>" /><?php echo $value; ?></label><br>

<?php endforeach; ?>

<input type="submit" name="submit" value="Submit" />

</form

You shouldn't need to get the options from the teams table directly, as the getListOptions Function should retrieve the options from that table automatically.

You shouldn't need to use a meta field like label, the $value should contain the label field. If you echo $value, the label field should be displayed as in the example I've given above.

Are you having trouble saving the value to the users record when they submit the form?

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com