0

I have an integer field on a node which can take two values. The nodes are created by the users by submitting a form. I can't work out how to do this for a multiple field text value.

How do I set-up a textfield form element to take multiple values?
How do I then submit it into the node using an entity wrapper?

This is the form element.

function createnode_form($form, &$form_state){    
    $form['field_student_age'] = array(
      '#type' => 'textfield',
      '#title' => t('test'),
    ); .....

This is the code that creates the new node.

function postajob_form_submit($form, &$form_state) {

  $entity = entity_create('node', $values);
  $ewrapper = entity_metadata_wrapper('node', $entity);

  $ewrapper->field_salary->set($form_state['values']['field_salary']);

There is no multiple property for textfields. Do I need to open up a different path in the form variable (e.g. $form['field_student_age']['value1'])? I've tried various options but I can't work out what the path would be.

If I do that, can I then just submit it in the wrapper with the extended path?

1 Answer 1

0

I got the solution from Save a new value with entity_metadata_wrapper to an entity field which is an array.

I created two separate form fields.

function createnode_form($form, &$form_state){ 
  $form['field_student_age'] = array(
    '#type' => 'textfield',
    '#title' => t('test'),
  );

  $form['field_student_age2'] = array(
    '#type' => 'textfield',
    '#title' => t('test2'),
  );

Then I stored them using the first method in the post quoted above.

$ewrapper->field_student_age[] = $form_state['values']['field_student_age'];
$ewrapper->field_student_age[] = $form_state['values']['field_student_age2'];

Rather than using set as I'd done with single values, I created a new entry for each value using [] =.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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