Fix for Fix for Fix for How to complete any webform submission via Ajax

  1. <?php # Place the following code in your webform under the
  2.            # Advanced Webform Settings Field group inside of
  3.            # Additional Processing...
  4.  global $submission;
  5.  if(!isset($submission) || !is_array($submission)){
  6.         $err_str = $submission.PHP_EOL;
  7.         $submission = array();
  8.  }
  9.  $enabled = TRUE;
  10.  $preview = FALSE;
  11.  $args = array('submission' => $submission, 'enabled' => true, 'preview' => false);
  12.  $temp = drupal_execute($form_state['values']['form_id'],$_POST,$args);
  13. ?>
  14.  
  15. The jquery below will work for sure, however there may be a better way to get this done...
  16.  
  17.     $("form#SOMEID").each(function(i, domForm){
  18.         var $submit = $(domForm);
  19.         $submit.submit(function(){return false;});
  20.         var $button = $(domForm).children('input[type="image"]'); /* This is my custom button */
  21.         var $entry = $(domForm).find('[type="text"]'); /* grab all the text fields you may to get others */
  22.         var $drupal = $(domForm).find(':hidden');  /* you need all of these for sure */
  23.         var $action = $(domForm).attr('action'); /* need this to know where to POST */
  24.         var $container = $(domForm);  /* for sending feedback because you're a jerk if you don't */
  25.         /* read up on http POST if you dont get this part */
  26.         var $boundary = '-----------------------------1626259126772';        /* note that this line has two more -- then the ajaxSetup line */
  27.         var $content_lead = '\nContent-Disposition: form-data;'
  28.         /* we don't want to actually submit the form... */
  29.         $button.unbind("click");
  30.         $(domForm).unbind("submit");
  31.         $button.click(function(){
  32.             var $entered = '';
  33.                 $entry.each(function(){
  34.                         var $blah = $(this).attr('name');
  35.                         var $blah2 = $(this).val();
  36.                         $entered += $boundary + $content_lead + ' name="' + $blah + '"\n\n' + $blah2+'\n';
  37.                 });
  38.                 $drupal.each(function(){
  39.                     var $blah = $(this).attr('name');
  40.                         var $blah2 = $(this).val();
  41.                         $entered += $boundary + $content_lead + ' name="' + $blah + '"\n\n' + $blah2+'\n';
  42.                 });
  43.                 $entered += $boundary + '\nContent-Disposition: form-data; name="op"\n\nSubmit\n'+$boundary +'--\n\n';
  44.                 $.ajaxSetup({contentType: 'multipart/form-data; boundary=---------------------------1626259126772', cache: false});
  45.                 $container.fadeOut("slow");
  46.                         $.post($action, $entered  , function(data){
  47.                                 var $temp = data;  /* I had some issues with the form submitting when this is not done not sure if it is needed */
  48.                                         $container.html('<p>Thank you for your interest!<br /></p>');
  49.                                         $container.fadeIn("normal");}
  50.                                 , "html");
  51.                 return false;
  52.             });
  53.     });

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.