My use case:
- Anonymous user submits information via an entityform.
- The form data ($_POST) is cached and a modal dialog box displays with a login form.
- The user authenticates, and the cached form data is retrieved and then submitted.
I've been able to do this with webforms, but I haven't been able to accomplish the same task for entityforms. I can get the form using the following code...
<?php $entityform = entityform_empty_load('my_eform_type'); $form = entityform_form_wrapper($entityform); ?>
What I've had trouble with is creating a $form_state array with the correct structure and values from the cached $_POST that I can then pass to drupal_form_submit(). My entityform has image, date, and checkbox fields, so that adds to the complexity.
I've been able to manually create and save an entityform submission using the following code...
<?php $values = array( 'type' => 'my_eform_type', 'uid' => $user->uid, 'created' => time(), 'changed' => time(), 'language' => LANGUAGE_NONE, ); // For brevity's sake, I don't show adding all the fields // from the cached $_POST to the $values array. $entityform = entityform_create($values); $entityform->save(); ?>
...but that doesn't provide the form validation and reload on error functionality. Errors such as the wrong size image being uploaded, which is caught during form submission.
When my entityform is submitted, there is also an entityform notification email sent and the user is redirected to the confirm page. I don't want those things to happen prior to the user authenticating.
There's some code in the d.o. handbook, but it doesn't talk about drupal_form_submit().
I'm using Entityform 1.1.