Fix for Fix for Fix for Creating imagefield content programatically

  1. function sti_migrate_form_submit($form, &$form_state) {
  2.   $form_state = array();
  3.   module_load_include('inc', 'node', 'node.pages');
  4.   $node = array('type' => 'tell_your_story');
  5.   $form_state['values']['title'] = 'My node';
  6.   $form_state['values']['field_email'][0]['email'] = 'mai@pmail.com';
  7.   $form_state['values']['locations'][0]['postal_code'] = '01060';
  8.   $form_state['values']['field_story_title'][0]['value'] = "My story's title";
  9.   $image = "/Users/akahn/Desktop/Untitled-1-not-sharp.jpg";
  10.   $form_state['values']['field_story_image'][0] = array(
  11.     'fid' => 'upload',
  12.     'title' => basename($image),
  13.     'filename' => basename($image),
  14.     'description' => basename($image),
  15.     'filepath' => $image,
  16.     'filesize' => filesize($image),
  17.   );
  18.   $form_state['values']['body'] = 'This is the body text!';
  19.   $form_state['values']['name'] = 'robo-user';
  20.   $form_state['values']['op'] = t('Save');
  21.   drupal_execute('tell_your_story_node_form', $form_state, $node);
  22. }
AttachmentSize
Winter.jpg103.07 KB

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.