I am trying to send a post form to salesforce as below:
//send email
wp_mail($idata_email, $request_name, $our_message, $headers );
//submit form to salesforce
jQuery("#myform1").submit();
or
document.myform1.submit();
//form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" id="myform1" method="post" >
</form>
Code:
if( $insert_lead == 1 )
{
switch( strtolower($request_name) )
{
case 'table of contents':
case 'report synopsis':
case 'report pricing':
echo '<form action="https://www.google.com/servlet/servlet.WebToLead?encoding=UTF-8" id="myform1" name="myform1" method="post" >'.
'<input type="hidden" name="oid" value="fake">'.
'<input type="hidden" name="retURL" value="fake">'.
'<input type="hidden" id="first_name" name="first_name" value="'. $wp_session['first_name'] .'">'.
'<input type="hidden" id="last_name" name="last_name" value="'. $wp_session['last_name'] .'">'.
'<input type="hidden" id="email" name="email" value="'. $wp_session['email'] .'">'.
'</form>';
?>
<script>
jQuery("#myform1").submit();
</script>
<?php
wp_mail($idata_email, $request_name, $our_message, $headers );
wp_mail($email, $request_name , $client_message, $headers );
break;
case 'executive summary':
echo "<script>
jQuery(\".wp-cart-button-form\").submit();
</script>";
break;
}
}
ps: when I comment the send email method, the form is posted in all browsers, but I need to send e email and do the post.
Anyone know what is happening? and how to solve?
Thank you
Just a guess here. But have you tried reordering the code to such an order?
<?php
wp_mail($idata_email, $request_name, $our_message, $headers );
wp_mail($email, $request_name , $client_message, $headers );
?>
<script>
jQuery("#myform1").submit();
</script>
I suspect when you submit the form before the function wp_mail run the page already stop loading/processing the codes below the submit() portion.