2
Answers
Vote up!
0
Vote down!

How to insert a werform in a checkout pane (or page ?)

Hi,
I want to insert an existing webform to a pane in a custom checkout page.

I try several things to load my webform and attach it to the checkout without success :

<?php
function BASE_checkout_form($form, &$form_state, $checkout_pane,
$order) {
   
$webform_nid = 38;

   
// option #1
   
$webform = entity_load('node', array($webform_nid));
       
   
// or option #2
   
$webform_node = node_load($webform_nid);    // see Note below
   
$webform = node_view($webform_node);

   
$pane_form = array('#parents' => array(
       
$checkout_pane['pane_id']
    ));

   
field_attach_form('node', $webform, $pane_form, $form_state);

    return
$pane_form;
}
?>

Note : without node_view(), it displays the webform 'edit form' (with the title, the summary ans the body like at node/%/edit).

In all cases, I have this error :
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids()

Can somebody help me ?

Regards,

Asked by: daveH
on March 14, 2013

2 Answers

Vote up!
1
Vote down!

As said in my response to medden, I found a solution to my problem (certainly not the best but...) :

<?php
function BASE_checkout_form($form, &$form_state, $checkout_pane,
$order) {
   
$webform_nid = 38;
   
$webform_node = node_load($webform_nid);
   
$webform_components = $webform_node->webform['components'];

   
// Render each component as a form field using Webform function
    //      webform_component_invoke(TYPE, CALLBACK[, ARGS])
    //      @see webform/components/TYPE.inc function _webform_CALLBACK_TYPE()
   
foreach ($webform_components as $key => $component) {
       
$pane_form[$component['form_key']] = webform_component_invoke($component['type'], 'render', $component);
    }

    return
$pane_form;
}
?>

Hope this can help somebody.

Answer by: daveH
Posted: Mar 15, 2013
Vote up!
1
Vote down!

This wouldn't integrate the webform directly into your checkout form, but can't you enable the webform as a block, and display the block on the checkout page?

Failing that can a custom rule redirect you to your webform page mid-checkout, and retrun you afterwards.

Sorry that neither solution is very specific to your problem, just what I might try first.

Answer by: medden
Posted: Mar 14, 2013

Comments

Hi medden,

Thanks for your interest.

I've tried your suggestion but a problem is the submission of the forms :

  • the webform block displays a submit button. When I click on it, I go to the next page of the checkout form without validation (even if I don't complete a required field) ;
  • same thong if I click on the Continue to next step button

However, while waiting for a better solution (?), i found one : see my next post.

- daveH on March 15, 2013

Hi daveH,

What's the better solution you mentioned? I have the same desire here. Looking forward your answer. Thanks

- zliu95 on November 26, 2013