How to load and embed Entityform programatically in Drupal 7

I recently used Entityform module in a project and it was my first experience with this module. It was quite easy to create new entity type forms and add drupal fields to it but then i had a specific requirement of loading and embeding the entityform on a custom page.

Here is the code that I used to load and embed entityform programatically.

Loading the form

The first thing that I needed to do to render the form was to load an empty instance of the entityform using entityform_empty_load(). In this example, order_comments is the name of my form type.

$form = entityform_empty_load('order_comments');

Rendering the Form

Once the form was loaded, it was time to render the form.

//load entityform.admin.inc file
module_load_include('inc', 'entityform', 'entityform.admin');
$output = entityform_form_wrapper($form, 'submit', 'embedded');
echo render($output);

The first argument $form is the EntityForm object, the second argument is mode(default is submit) and the last argument is context(default is page).