Sending Simplecart data via email: A working solution here

After reading all of this, and working it out, I thought it would be helpful to summarize what I learned.
  1. If there is a javascript error in your checkout code, you may get directed to paypal, even if you specified sendform as your checkout method, and then you will see a paypal error page
  2. To get extra form elements into the checkout, all you really need is to bind to beforeCheckout, like this:
<script>
simpleCart.bind( 'beforeCheckout' , function( data ){
data.email_from = document.getElementById("email_from").value;
});
 </script>

note: add below code in page sendjs.php 

You don't need to use the extra_data tag in checkout for adding form fields. You just need to add the form field HTML to the page, and add the beforeCheckout handler, and the extra data will be included in the post. The form field HTML is like this:

    <input type="email" name="email_from" placeholder="yourname@domain.com" title="Enter your e-mail address" class="required email" id="email_from">
  1. To get the extra data in PHP, you just need to access the POST variables. In most of the examples, POST is set to a content variable, so you would do this:
    $content = $_POST;
    $body = '';
    $body .= "Email: ".$content['email_from']."\n";
the rest of the data gets posted as fields in the format item_name_number, etc.
 

Post a Comment