calebm12 Posted October 11, 2009 Share Posted October 11, 2009 I am using the following code to amend a value entered in a field prior to inserting in a database. i am wondering how to change it so that if the field has multiple values (separted with comma or space) it will amend each value and not just the last one. function citizenspeak_nodeapi(&$node, $op) { switch ($op) { case 'presave': $node->email_recipients = $node->email_recipients.'@metrofax.com'; } } Link to comment https://forums.phpfreaks.com/topic/177260-change-code-to-account-for-multiple-values-in-field/ Share on other sites More sharing options...
jon23d Posted October 11, 2009 Share Posted October 11, 2009 explode will change a string to an array, then use foreach. Link to comment https://forums.phpfreaks.com/topic/177260-change-code-to-account-for-multiple-values-in-field/#findComment-934803 Share on other sites More sharing options...
calebm12 Posted October 11, 2009 Author Share Posted October 11, 2009 Sorry for my ignorance. very green. not sure how to mix that into the code $pieces = explode(" ", $node->email_recipients); foreach ($pieces as $node->email_recipients); function citizenspeak_nodeapi(&$node, $op) { switch ($op) { case 'presave': $node->email_recipients = $node->email_recipients.'@metrofax.com'; } } Link to comment https://forums.phpfreaks.com/topic/177260-change-code-to-account-for-multiple-values-in-field/#findComment-934984 Share on other sites More sharing options...
jon23d Posted October 11, 2009 Share Posted October 11, 2009 Define your function outside the foreach loop. Link to comment https://forums.phpfreaks.com/topic/177260-change-code-to-account-for-multiple-values-in-field/#findComment-935000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.