Skip to content

Instantly share code, notes, and snippets.

@Sam152
Created March 15, 2014 08:33
Show Gist options
  • Save Sam152/9563500 to your computer and use it in GitHub Desktop.
Save Sam152/9563500 to your computer and use it in GitHub Desktop.
This allows you to turn an HTML form into a PHP POST array to make submitting forms in the context of Drupal tests easier.
javascript:var $=jQuery;var str="";var nl="\n";$.each($("form"),function(e,t){str+="$"+$(t).attr("id").split("-").join("_")+" = array("+nl;$.each($(t).find("input, select, textarea"),function(e,t){var n=$(t).attr("name");var r=$(t).val().split("'").join("\\'");if(n=="op"||n==""||n=="form_build_id"||n=="form_token"||n=="form_id"){return}str+=" '"+n+"' => '"+r+"',"+nl});str+=");"+nl+nl});console.log(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment