What do the results look like when you submit the form? If the options all have the same name, they will come through as an array based on the 'name' in the form.
If the page posts to itself, you can put a snippet at the top with this code:
echo print_r($_POST['nameOfField']); It will be empty when the form loads, but it should display the user's choices on submission. If it does, I think the hook will have a reference to the user object, so this should work:
$profile = $user->getOne('Profile'); if ($profile) { $extended = $profile->get('extended'); $variableFromForm = $hook->getValue('variableFromForm'); $extended['somefield'] = implode(',', $variableFromForm); $extended->save(); }
<select name="workregion[]" multiple="multiple" size="5" tabindex="13"> <option value="SouthWest">South West</option> <option value="London">London</option> </select>
1
Array ( [0] => SouthWest [1] => London ) 1
Try adding this to the end of the hook:
return true;
Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 52' at line 1 )
$user = $hook->getValue('register.user'); $profile = $user->getOne('Profile'); if ($profile) { $extended = $profile->get('extended'); $variableFromForm = $hook->getValue('variableFromForm'); $extended['somefield'] = implode(',', $variableFromForm); $extended->save(); } return true;
See if this does it:
$user = $hook->getValue('register.user'); $profile = $user->getOne('Profile'); if ($profile) { $extended = $profile->get('extended'); $variableFromForm = $hook->getValue('variableFromForm'); $extended['somefield'] = implode(',', $variableFromForm); $extended->save(); } return true;
Array ( [0] => SouthWest [1] => London ) 1
[2015-09-27 12:03:56] (ERROR @ public_html/core/cache/includes/elements/modsnippet/64.include.cache.php : 8) PHP warning: implode(): Invalid arguments passed
Did you replace 'variableFromForm' in the getValue() call with the actual field name? The error means that that variable is empty or not an array.
<?php $user = $hook->getValue('register.user'); $profile = $user->getOne('Profile'); if ($profile) { $extended = $profile->get('extended'); $variableFromForm = $hook->getValue('variableFromForm'); $extended['workregion'] = implode(',', $variableFromForm); $extended->save(); } return true;
<?php $user = $hook->getValue('register.user'); $profile = $user->getOne('Profile'); if ($profile) { $extended = $profile->get('extended'); $variableFromForm = $hook->getValue('workregion'); $extended['workregion'] = implode(',', $variableFromForm); $extended->save(); } return true;