Skip Navigation

[Resolved] $form_data[‘container_id’] – Undefined Index

This thread is resolved. Here is a description of the problem and solution.

Problem:
$form_data['container_id'] - Undefined Index when using cred_form_validate hook

Solution:
You should try to use the global post to get the current post ID.

You can find the proposed solution, in this case with the following reply:
=> https://toolset.com/forums/topic/form_datacontainer_id-undefined-index/#post-1216803

Relevant Documentation:

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by MattI4840 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1216530

I am trying to write a validation function for an edit form, in order to do so I am using '$post_id = $form_data['container_id'];' to get the post_id to then get the values for two fields (wpcf-parcel-totes, wpcf-parcel-bags), but I'm getting an error that 'container_id' has an undefined index. I'm confused as I'm using the same syntax in other non-validation functions, and that code works as expected.

I've commented the code below as best as possible to show what I am attempting to do, please let me know where I am falling short here.

function ylstracking_validate_parcel_edit ($field_data, $form_data) {
 
    list($fields,$errors)=$field_data;
 	
 	
    //Check to ensure correct from is being used
    if ( 437 == $form_data['id']) {


    	if ($_POST['wpcf-product-type']==1) { //check to ensure correct product type
     		
    		$post_id = $form_data['container_id']; //get post id

     		//get current value of totes/bags for selected parcel (aka values to be restocked)
     		$parcel_totes = get_post_meta($post_id, 'wpcf-parcel-totes', true);
    		$parcel_bags = get_post_meta($post_id, 'wpcf-parcel-bags', true);

	      	//get id of parent warehouse post
	        $parent_warehouse = $_POST['@warehouse-parcel_parent'];
	        //get value of bags/totes-left fields from parent post
	         $warehouse_bags = get_post_meta($parent_warehouse,'wpcf-warehouse-dt80-bags', true);
	         $warehouse_totes = get_post_meta($parent_warehouse,'wpcf-warehouse-dt80-totes', true);

	         //get id of parent transaction (aka po/purchase order)
	         $parent_po = $_POST['@transaction-parcel_parent'];
	         //get value of bags/totes-left fields from parent transaction
	         $po_bags = get_post_meta($parent_po,'wpcf-trans-dt80-bags', true);
	         $po_totes = get_post_meta($parent_po,'wpcf-trans-dt80-totes', true);

	         //double parent warehouse for comparison
	         $transaction_warehouse = toolset_get_related_post( $parent_po, 'warehouse-transaction' );

	         //add the current values for totes/bags to what is currently in the warehouse
	         $warehouse_available_bags = $parcel_bags + $warehouse_bags;
	         $warehouse_available_totes = $parcel_totes + $warehouse_totes;

	         //add the current values for totes/bags to what is currently in the original po
	         $po_available_bags = $parcel_bags + $po_bags;
	         $po_available_totes = $parcel_totes + $po_totes;

	         
	        //ensure the correct warehouse was selected on the edit form            
	        if ($parent_warehouse != $transaction_warehouse) {
	   
	            $errors['wpcf-parcel-totes'] = 'The PO you selected is no located in the Warehouse you selected';
	      } //ensure bags being shipped out does not exceed what is in the warehouse + restocked values
	        if ($_POST['wpcf-parcel-bags'] > $warehouse_available_bags) {
	   
	            $errors['wpcf-parcel-bags'] = 'The warehouse you selected does not have enough DT80 bags';
	      }
	      		//ensure totes being shipped out does not exceed what is in the warehouse + restocked values
	      	 if ($_POST['wpcf-parcel-totes'] > $warehouse_available_totes) {
	   
	            $errors['wpcf-parcel-totes'] = 'The warehouse you selected does not have enough DT80 totes';
	      }
	      	//ensure bags being shipped out does not exceed what is in the po + restocked values
	      	if ($_POST['wpcf-parcel-bags'] > $po_available_bags) {
	   
	            $errors['wpcf-parcel-bags'] = 'The PO you selected does not have enough DT80 bags';
	      }
	      	//ensure totes being shipped out does not exceed what is in the po + restocked values
	      	 if ($_POST['wpcf-parcel-totes'] > $po_available_totes) {
	   
	            $errors['wpcf-parcel-totes'] = 'The PO you selected does not have enough DT80 totes';
	      }
       }
     }
}

Thanks in advance.
Matt

#1216745

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I see the issue and I've escalated it to our next level support. Please hold on for further update.

#1216803

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I just checked with our next level support and we found that container_id is not supported with "cred_form_validate" hook.

You should try to use the following alternative way - instead of using container_id use the global $post:

global $post;
$post_id =  $post->ID; //get post id
 
    //get current value of totes/bags for selected parcel (aka values to be restocked)
    $parcel_totes = get_post_meta($post_id, 'wpcf-parcel-totes', true);
    $parcel_bags = get_post_meta($post_id, 'wpcf-parcel-bags', true);
 
#1216992

My issue is resolved now. Thank you!