Hi all,
Forgive my limited PHP experience, I'm more of a database guy but have made this work so far.
I have a working form (as far as display is concerned), but am having some issues with my form_submit function. First, my form code:
function contacts_groups_form ($uid) {
$form['name'] = array (
'#type' => 'textfield',
'#title' => t('Group name'),
'#size' => 50,
'#maxlength' => 100,
'#required' => TRUE,
);
$form['description'] = array (
'#type' => 'textfield',
'#title' => t('Description'),
'#size' => 50,
'#maxlength' => 250,
);
$options = array();
$sql = "SELECT firstname, lastname, cid FROM {contacts} WHERE uid =%d and active = 1 ORDER BY firstname ASC";
$r = db_query($sql, $uid);
while ($row = db_fetch_array($r)) {
$options[$row['firstname'] . ' ' . $row['lastname']] = $row['firstname'] . ' ' . $row['lastname'];
}
$form['contacts'] = array (
'#type' => 'checkboxes',
'#desctiption' => t('Select contacts to add to this group.'),
'#options' => $options,
);
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('Create Group'),
);
return $form;
}This form allows a user to create a group, and assign contacts to that group from the database (part of another form that works). This form will display checkboxes of the first and last name (works fine), and then on submit I would like run an INSERT into my contacts_groups_memberships table. The issue I'm running into is i need to insert the CID into my contacts_groups_memberships table relative to the contacts boxes that are checked when the form is submitted. My $form['contacts'] is the combined first and last name, so I'm not sure I can use that to perform a reverse cid lookup in my submit function. Make enough sense for anyone to get me going in the right direction? My function contacts_groups_form_submit is a mess, but if it helps to post that I will.
Thanks!
Comments
Options could be an array of
Options could be an array of key => value pairs. The value is shown in the selection field and the key is returned. This way you can save the CID as key and get it back from the form.
Regards
Werner
Werner, Thanks for the
Werner,
Thanks for the reply. My limited PHP knowledge is getting the best of me, and I don't know where to start with the key value pairs. I've done many forum and Google searches, and still am coming up empty. Would it be possible to give me a bit more of a nudge?
Thanks,
Colin
Look at this
This is an example from a self-written module where I needed a similar approach as you. I wanted the node ID back, while showing the title.
This is a code snippet:
Change the query according to your needs. Hope this helps.
Regards
Werner
Worked like a charm, thanks
Worked like a charm, thanks a bunch!