Search

Backend:

SubSection Manager

Frontend:

Front End

What I'm trying to accomplish is a front-end form that allows members to update their phone numbers on file. Phone numbers are stored in their own section and attached to a member record via subsection manager in the backend.

See also, StackExchange Thread


Symphony 2.3.6 Subsection Manager 3.5.1

Attachments:
Screen Shot 2014-02-26 at 11.29.11 AM.png and Screen Shot 2014-02-26 at 11.29.41 AM.png

Check one:

  • [ ] Yes
  • [ ] No
  • [ ] Not sure
  • [ ] Maybe
  • [ ] I need a beer

It's possible.

It should be relatively simple if you just have to update existing data: you have to create a frontend form that saves to the subsection directly, using the entry ids provided by the subsection field.

But keep in mind that if you are only storing key/value pairs, Brendan's Metakeys extension might be the better field choice.

Tell me if I'm on the right track here

Pseudocode

1. Identify new phone numbers
2. Create New Entry Objects for each number
3. Create array of entry objects that includes 
    3.1 existent numbers being edited
    3.2 new numbers being added
4. Update all numbers with new/edited values
5. Commit Numbers Entries to the Phone Number Section in DB
6. Update the Member entry to reflect the ID of the new phone number
7. Commit the Member Entry to the Members Section in the DB

I have this bit working which saves new phone numbers to the Phone Number Section (PseudoCode #s 1-5; I'm not worrying about editing existing numbers just yet):

foreach($_POST['fields']['phone-numbers-new'] as $hash => $field)
{
    $data = array();
    $data[$ids['phoneNumbers']['fields']['type']]['handle'] = General::createHandle($field['type']);
    $data[$ids['phoneNumbers']['fields']['type']]['value'] = $field['type'];
    $data[$ids['phoneNumbers']['fields']['number']]['handle'] = General::createHandle($field['number']);
    $data[$ids['phoneNumbers']['fields']['number']]['value'] = $field['number'];
    $data[$ids['phoneNumbers']['fields']['added_by']]['author_id'] = "1";
    $data[$ids['phoneNumbers']['fields']['active']]['value'] = "yes";


    $newPNs = EntryManager::create();
    $newPNs->set('section_id', "{$ids['phoneNumbers']['sectionID']}");
    $newPNs->setDataFromPost($data);
    $newPNs->setData($ids['phoneNumbers']['fields']['type'],$data[$ids['phoneNumbers']['fields']['type']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['number'],$data[$ids['phoneNumbers']['fields']['number']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['added_by'],$data[$ids['phoneNumbers']['fields']['added_by']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['active'],$data[$ids['phoneNumbers']['fields']['active']]);

    $ids['newPNs'][] = $newPNs->get('id');

    $newPNs->commit(); //adds the new phone number to the Phone Number Section

}

I then update the Member Entry with the new phone numbers:

$entries = EntryManager::fetch($ids['entry']);
$member = $entries[0];

$data = array(); // reset data array

$data[$ids['phoneNumbers']['fieldID']] = $member->getData($ids['phoneNumbers']['fieldID']);
for($i = 0; $i < count($ids['newPNs']); $i++)
{
    $index = count($data[$ids['phoneNumbers']['fieldID']]['relation_id']) + $i;
    $data[$ids['phoneNumbers']['fieldID']]['relation_id'][$index] = "{$ids['newPNs'][$i]}";
}
$member->setData($ids['phoneNumbers']['fieldID'],$data[$ids['phoneNumbers']['fieldID']]['relation_id']);
$member->commit();

However, the $member->commit(); runs I get a DB error:

Symphony Fatal Database Error: Unknown column '0' in 'field list'

An error occurred while attempting to execute the following query

INSERT INTO `smec_entries_data_103` (`entry_id`, `0`, `1`, `2`) VALUES ('404', '1225', '1226', '1283')

Anybody, especially $Übermensch->Nils know what I'm missing here?

Please let me know if I can provide more code or context to the code above. Your help is appreciated greatly.

Is there a reason why you don't use default events created by the editor in the backend?

Are your members sharing phone data? If not why are you using a subsection and not a simpler field like metakeys?

Just saw the bug in the above code:

$member->setData($ids['phoneNumbers']['fieldID'],$data[$ids['phoneNumbers']['fieldID']]['relation_id']);

should be

$member->setData($ids['phoneNumbers']['fieldID'],$data[$ids['phoneNumbers']['fieldID']]);

When I do that all posts and associates correctly. Whoo hoo!

Nils, you're the best. Thanks for answering the post.

I would love to have used the default events. Apparently, I don't know how to use them correctly for subsection manager data in a section. Is there an example, documentation or tutorial that might look at to learn how? I just assumed that because the SSM was not part of the core (and that I couldn't get things working) that the default events didn't support SSM data. Glad to be wrong.

Is there an example, documentation or tutorial that might look at to learn how?

Nothing Subsection Manager specific I am aware of. But any tutorial explaining how to work with SBL and events will work with SSM data as well. Maybe this is useful: https://gist.github.com/brendo/901476

Thank you Nils. Reading it now.

Brendo's approach is MUCH simpler and doesn't reinvent the wheel. Thanks, Nils, for pointing me to the better path...

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details