Update Value In Another Form Based On First Form

By: Oguz Atci | Asked: 08/20/2024
ForumsCategory: General questionsUpdate Value In Another Form Based On First Form
Oguz Atci asked 1 month ago
I have a Form A and i keep Product SKU and my stock inventory in this form.  I also have form B and this form is used for production order to the tecnicians. In this form i have several repeater fields and all repeater fields has SKU (as lookup field and auto populated from Form A's SKU column) and quantity fields (number field) inside. I want to reduce the stock quantity in form A regarding to the quantity in form B on submit.  Could you please advise?
2 Answers
Oguz Atci answered 1 month ago

Thank you dear Rob.. Actually i have already take a look on the knowledgebase.. The issues i have with this code are:   
1) I need to check my SKU field to match the products when updating from form A to Form B... But in the example it's checking the user id instead of product SKU..  
2) In this example it addresses two specific fields to get data from form A and write data to form B. Since i have several repeaters in form A how can i address each repeater sections SKU field and stock quantity fileds?    

SAMPLE CODE

add_action('frm_after_create_entry', 'link_fields', 30, 2); add_action('frm_after_update_entry', 'link_fields', 10, 2);
function link_fields($entry_id, $form_id){
if($form_id == 113){//Change 113 to the ID of the first form
global $wpdb;
$first_field = $_POST['item_meta'][25]; //change 25 to the ID of the field in your first form
$user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM ". $wpdb->prefix ."frm_items WHERE id=%d", $entry_id));
$entry_ids = $wpdb->get_col("Select id from ". $wpdb->prefix ."frm_items where form_id='112' and user_id=". $user);//Change 112 to the ID of the second form
foreach ($entry_ids as $e)
$wpdb->update( $wpdb->prefix .'frm_item_metas', array('meta_value' => $first_field), array('item_id' => $e, 'field_id' => '6422'));//Change 6422 to the ID of the field to be updated automatically in your second form
}
}

     

Rob LeVineRob LeVine replied 4 weeks ago

The sample code is meant as a starting point. You can put whatever code you want in the hooks. From the sound of it, you're not well-versed in customizing PHP code. I suggest you reach out to a developer for help. Otherwise, you can look at all the PHP examples and use trial and error to find out what you need. The one hint I'll offer is that repeater sections are their own "embedded" forms whose entries are linked back to the main form's entry. You can reach developers here - https://formidable-masterminds.com/developers-directory/

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right