WordPress.org

Support

Support » Plugins and Hacks » Easy Digital Downloads » [Resolved] Cart Form not sending array data (like checkboxes) to the purchase order history

[Resolved] Cart Form not sending array data (like checkboxes) to the purchase order history

  • aokeefe17

    @aokeefe17

    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/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Pippin Williamson

    @mordauk

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

    aokeefe17

    @aokeefe17

    `// <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>

    aokeefe17

    @aokeefe17

    Hope that’s better.

    Plugin Author Pippin Williamson

    @mordauk

    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?

    aokeefe17

    @aokeefe17

    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>
    aokeefe17

    @aokeefe17

    aokeefe17

    @aokeefe17

    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!

    Plugin Author Pippin Williamson

    @mordauk

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

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

    Also, the error messaging is working.

    Plugin Author Pippin Williamson

    @mordauk

    Does it show Array in the View Details popup?

    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.

    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!

    Plugin Author Pippin Williamson

    @mordauk

    Great!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] Cart Form not sending array data (like checkboxes) to the purchase order history’ is closed to new replies.
Skip to toolbar