How to submit Entityform programatically in Drupal 7

While working with the Entityform module in a project, i had a specific requirement of creating Entityform submission programatically in a custom module. 

Here is the code that I used to create entityform submission programatically.

global $user;

//'my_entityform_type' is an Entityform type machine name (admin/structure/entityform_types)

$entityform_data = array(
    'type' => 'my_entityform_type',
    'created' => time(),
    'changed' => time(),
    'language' => LANGUAGE_NONE,
    'uid' => $user->uid
));

$entityform = entity_create('entityform', $entityform_data);

//using Entity API to load entityform wrapper
$wrapper = entity_metadata_wrapper('entityform', $entityform);

// And then finally set the fields.
$wrapper->field_title = 'Test';
$wrapper->field_keywords = 'Test';
$wrapper->save();

Add new comment