1

I am creating a node progrmatically.

here is my code..

     $node = new stdClass();
      $node->type=$type;
      $node->status = 1;
      $node->uid = $uid;

        foreach($_POST as $field_name=>$field_value) {
          $node->$field_name=array('und'=>array(0=>array('value'=>$field_value)));

        }
node_save($node);

this is working fine. if we have a single value for each field.. Now i have a filed having select box with multiple select. How to save them.

Thanks

1

You just need to keep adding new values underneath the language array, for example:

foreach ($_POST as $field_name => $field_value) {
  $node->{$field_name}[LANGUAGE_NONE][]['value'] = $field_value;
}
  • [type] => test [status] => 1 [uid] => [field_name] => Array ( [und] => Array ( [0] => Array ( [value] => Array ( [0] => 1 [1] => 2 ) ) [1] => Array ( [value] => helo ) ) ) – Rashmi Sep 17 '13 at 10:22
  • i was expecting my post field name – Rashmi Sep 17 '13 at 10:22
  • Not sure what you mean, could you clarify? Does the above not work? If not could you edit the new code you're using into the question? – Clive Sep 17 '13 at 10:24
  • i am using advance rest console for posting parameter.. i need fields name what i posted – Rashmi Sep 17 '13 at 10:25
  • 1
    Ah ok, so just make that change and you'll be good to go – Clive Sep 17 '13 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.