WordPress.org

Ready to get started?Download WordPress

Forums

Easy Digital Downloads
[resolved] Cart Form not sending array data (like checkboxes) to the purchase order history (15 posts)

  1. aokeefe17
    Member
    Posted 1 year ago #

    I have a problem with capturing all of the form data from the custom form I built on the checkout page of the purchase process. Essentially, I receive all the text box data, however, data in an array type field, like checkboxes, does not come through. I need a little advise on how to get it to come through.

    Ex.

    <p><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="January 10 2012 1.5" <?php
    				if ($_POST && in_array('January 10, 2012 1.5', $_POST['edd_meetings'])) {
    				  echo 'checked';
    				} ?>>
          January 10, 2012</p>
    
    <p><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="April 10 2012 1.5" <?php
    				if ($_POST && in_array('April 10, 2012 1.5', $_POST['edd_meetings'])) {
    				  echo 'checked';
    				} ?>>
          April 10, 2012</p>
    // store the custom field data in the payment meta
    function pippin_edd_store_custom_fields($payment_meta) {
    	$payment_meta['meetings'] =  isset($_POST['edd_meetings']) ? $_POST['edd_meetings'] : '';	
    
    // show the custom fields in the "View Order Details" popup
    function pippin_edd_purchase_details($payment_meta, $user_info) {
    	$meetings = isset($payment_meta['meetings']) ? $payment_meta['meetings'] : 'none';	
    
    <li><?php echo __('Meetings attended:', 'pippin') . '' . $meetings; ?></li>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your posted code may now have been permanently damaged/corrupted by the forum's parser.]

    http://wordpress.org/extend/plugins/easy-digital-downloads/

  2. It looks like your code got corrupted. Can you repaste it using the code tags (as noted by the moderator)?

  3. aokeefe17
    Member
    Posted 1 year ago #

    `// <p><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="January 10 2012 1.5" <?php
    if ($_POST && in_array('January 10, 2012 1.5', $_POST['edd_meetings'])) {
    echo 'checked';
    } ?>>
    January 10, 2012</p>

    <p><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="April 10 2012 1.5" <?php
    if ($_POST && in_array('April 10, 2012 1.5', $_POST['edd_meetings'])) {
    echo 'checked';
    } ?>>
    April 10, 2012</p>
    // store the custom field data in the payment meta
    function pippin_edd_store_custom_fields($payment_meta) {
    $payment_meta['meetings'] = isset($_POST['edd_meetings']) ? $_POST['edd_meetings'] : '';

    // show the custom fields in the "View Order Details" popup
    function pippin_edd_purchase_details($payment_meta, $user_info) {
    $meetings = isset($payment_meta['meetings']) ? $payment_meta['meetings'] : 'none';

    <li><?php echo __('Meetings attended:', 'pippin') . '' . $meetings; ?></li>

  4. aokeefe17
    Member
    Posted 1 year ago #

    Hope that's better.

  5. It's still really mal-formatted and looks to be missing parts. Can you go ahead and paste it into pastebin.com and share the link?

  6. aokeefe17
    Member
    Posted 1 year ago #

    I think I forgot the end bracket. Sorry, I'm new to this. :)

    <p><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="January 10 2012 1.5" <?php
    if ($_POST && in_array('January 10, 2012 1.5', $_POST['edd_meetings'])) {
    echo 'checked';
    } ?>>
    January 10, 2012</p>
    
    <p><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="April 10 2012 1.5" <?php
    if ($_POST && in_array('April 10, 2012 1.5', $_POST['edd_meetings'])) {
    echo 'checked';
    } ?>>
    April 10, 2012</p>
    // store the custom field data in the payment meta
    function pippin_edd_store_custom_fields($payment_meta) {
    $payment_meta['meetings'] = isset($_POST['edd_meetings']) ? $_POST['edd_meetings'] : '';
    
    // show the custom fields in the "View Order Details" popup
    function pippin_edd_purchase_details($payment_meta, $user_info) {
    $meetings = isset($payment_meta['meetings']) ? $payment_meta['meetings'] : 'none';
    
    <li><?php echo __('Meetings attended:', 'pippin') . '' . $meetings; ?></li>
  7. aokeefe17
    Member
    Posted 1 year ago #

  8. aokeefe17
    Member
    Posted 1 year ago #

    While we're at it, how do I get the error message to appear? The required fields are highlighted, but I'm not seeing the error messages.

    I took over this form from someone with no instruction whatsoever, so your help is greatly appreciated. Thanks!

  9. At first glance the code looks correct. Do any of your fields save?

  10. aokeefe17
    Member
    Posted 1 year ago #

    Yes, all fields accept checkbox or array based data. All I get back is array.

  11. aokeefe17
    Member
    Posted 1 year ago #

    Also, the error messaging is working.

  12. Does it show Array in the View Details popup?

  13. aokeefe17
    Member
    Posted 1 year ago #

    Yes. it shows Meetings attended: Arrayin the payment history, but not the array data. I believe this is because there is no code to handle such an event. An example of the type of code I'm talking about is something like:

    //print data for edd-meeting array
    if(is_array ($_POST['edd_meetings'])) {
    	foreach ($_POST['edd_meetings'] as $meeting)
    	print $meeting;
    }

    or something that prints out the array, which does capture the data on Post, but there is a problem. When I incorporate that code above, I get the data from the array on submit, problem is it's a blank page with the data at the top! I think it comes down to a matter of being able to integrate that type of code with your payment_meta code. I'm just not sure how to integrate that with your code.

  14. aokeefe17
    Member
    Posted 1 year ago #

    I got it!

    So, what's needed in a case like this is to have an implode function to write the data.

    So, when you write the checkbox data to the form you add:

    <li><?php echo __('Meetings attended:', 'pippin') . ' '.implode( ', ',$meetings); ?></li>

    and presto! The checkbox data appears!

  15. Great!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic