Skip Navigation

[Resolved] Updating multiple posts with one form

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.

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)

This topic contains 4 replies, has 1 voice.

Last updated by davidL-7 2 weeks, 3 days ago.

Assisted by: Minesh.

Author
Posts
#2804500
Screenshot 2025-04-07 at 1.45.09 PM.png
Screenshot 2025-04-07 at 1.44.15 PM.png

Tell us what you are trying to do?

Hello, we're redeveloping an app originally built with ColdFusion with Toolset. In the original app, there's a screen that allows the user to update the total dollar amounts for a set of accounts (see Screenshot 2025-04-07 at 1.44.15PM).

In our Toolset build, the Accounts are a custom post type, and I've got a view that is looping through each of the posts and displaying the dollar amount (see Screenshot 2025-04-07 at 1.45.09PM).

My question is: Is it possible to develop this into a form, similar to the original, where each of those dollar amounts appears in an input field that can be edited, and then when submitted, somehow loop through each of the posts and update that field.

Is there any documentation that you are following?

No, not yet. Thus far, whenever I've created an interface for editing/updating a post, it's using the "edit" version of a post form, and the form operates on a single post only.

I'm guessing that to pull this off, I would not use an edit post form, but instead would markup the form in HTML, and then have the submit action trigger some custom code that would perform the update. But I'm not sure if this is technically possible, so I thought I'd ask. Please let me know.

Is there a similar example that we can see?

Yes, see screenshots below. If you'd like to access a dev copy of the original app, let me know and I can provide logins in a private post, but I think the screenshot will be sufficient.

What is the link to your site?

The page in progress is at hidden link (Minesh has login credentials, or I can provide then in a private post). I haven't begun trying to extend this page to include the form yet, because I'm not clear how to proceed or if it can be done.

Thanks!
David

#2804580

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

There is no such solution available but I can think of a workaround that may help but I'm not sure yet it will fully work or not.

As a workaround, I've created the following view:
- hidden link

And displaying the form field within view's loop for Total column:

<td>[types field='aid-amount' format='FIELD_VALUE'][/types]  === 
              
              <input type="hidden" id="hidden-[wpv-post-id]"  name="hidden-postids-aid-amount[]" value="[wpv-post-id]==[types field='aid-amount' format='FIELD_VALUE'][/types]" /> 
             <div class="form-group">
		<label for="%%FORM_ID%%_aid-amount">[cred_i18n name='aid-amount-label']Aid Amount[/cred_i18n]</label>
		[cred_field field='aid-amount' value="[types field='aid-amount' format='FIELD_VALUE'][/types]" force_type='field' class='form-control' output='bootstrap']
	</div>
              
            </td>

Then, I've created the following edit post form and added the above view to it
=> hidden link

[credform]

[cred_field field='form_messages' class='alert alert-warning']


[wpv-view name="toolest-test-show-view-in-form" view_display="layout" cached="off"]

	
	[cred_field field='form_submit' output='bootstrap' value='Update' class='btn btn-primary btn-lg']
[/credform]

So, with above edit form view will display all the filtered entried with the aid amount to edit.

I've created the following post (dummy post entry) that we are using with the edit form to edit the entry so it will not affect any other record:
=> hidden link

I've created the following page and added the view's filter as given under:
=> hidden link

[wpv-form-view name="toolest-test-show-view-in-form" target_id="self"]

After adding above fitler I've added the post edit form to edit the dummy post we created:

[cred_form form='edit-aid-yearly-total-amount-in-loop' post="39951"]

You can see that on the frontend:
- hidden link

#2804638

Wow, thanks Minesh, and nice work thinking outside the box! I'm going to study your work, so will keep this ticket open for the moment, and then follow up.

More to come,
David

#2804642

Hi Minesh,

Okay, I studied your work and have my next question.

I was getting the message "The Toolset Form edit-aid-yearly-total-amount-in-loop does not exist" on hidden link. I checked the list of forms and the only new one was named "hidden link", so I guessed that you had changed the name somewhere along the line.

I didn't want to write over any of your work, so I duplicated the page, updated the form name in the [cred_form] tag, and it worked. I filtered it to use year "1", which displays your test Aid Yearly Totals post (hidden link), updated the amount, and the udpate was successful!

So the next challenge is to get it working for multiple years.

Here's a URL to the duplicated page filtered for 2025: hidden link

It has this code:

[wpv-form-view name="toolest-test-show-view-in-form" target_id="self"]
[cred_form form='multi-edit-aid-yearly-total-amount' post="39951"]

...and the update doesn't work for multiple years yet, but I suspect that's because the [cred_form] is only operating on post 39951. I experimented to see what would happen if I removed the post attribute, but that produced the message "Form type and post type do not match".

My question is: How do we need to edit this to attempt running the update on each of the posts in the loop?

I also wanted to let you know that this is a development site and I will be re-importing the live data periodically, so it's okay to experiment with existing values and change them.

Thanks!
David

#2804897

Minesh
Supporter

Languages: English (English )

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

Well - somehow I'm able to find the way that you can filter the results as well as update all related aid-amount.

With the view, I've added the aid field within view's loop as given under:
=> hidden link

<input type="text" id="cred_form_39934_1_1_aid-amount_[wpv-post-id]" name="wpcf-aid-amount[[wpv-post-id]]" value="[types field='aid-amount' format='FIELD_VALUE'][/types]" class="form-control wpt-form-textfield form-textfield textfield js-wpt-validate" output="bootstrap"  data-wpt-validate="{"required":{"args":{"1":true},"message":"This field is required."},"number":{"args":{"1":true},"message":"Please enter numeric data."}}" data-wpt-field-title="Aid Amount" data-parsley-required="true" data-parsley-required-message="This field is required." data-parsley-credfilesize="314572800" data-parsley-type="number" data-parsley-error-message="Please enter numeric data." data-wpt-type="textfield" data-wpt-id="cred_form_39934_1_1_cred_form_39934_1_1_[wpv-post-id]" data-wpt-name="wpcf-aid-amount">

I've added the following code to "Custom Code" section offered by Toolset with the code snnipet namely "toolset-custom-code":

add_filter( 'wpv_view_settings', 'prefix_hide_filter_form_on_edit_form',30,2);
 function prefix_hide_filter_form_on_edit_form($view_settings, $view_id) {
if ( $view_id == 39945 ) {  
global $WP_Views;
  
   $shortcode_atts = $WP_Views->view_shortcode_attributes[0];
   if(isset($shortcode_atts['view_display']) and $shortcode_atts['view_display']=='layout'){
     
     	$view_settings['filter_meta_html'] = '';	
   
   }
  
}
  
return $view_settings;
}

add_action('cred_save_data','func_update_aid_amount_for_multiple_posts',10,2);
function func_update_aid_amount_for_multiple_posts($post_id,$form_data ) {
    $field_slug = 'aid-amount';
     
  if ($form_data['id']==39934) {
          
      if(isset($_POST['wpcf-'.$field_slug]) and !empty($_POST['wpcf-'.$field_slug]) ) {
        
             
      $all_aid_amount =  $_POST['wpcf-'.$field_slug];
      foreach($all_aid_amount as $k=>$v):
            update_post_meta($k,'wpcf-'.$field_slug,$v);
     endforeach;
         
      
      }
       
    }
}


Can you please check now and see if it works as expected and you can able to edit multiple items with one update button.
- hidden link

#2804949

Wow Minesh, incredible work! I tested for several years, theb ported it to the production page at hidden link, tested it again, and am thrilled to report that it works!

This is really amazing, and I hope it contributes to the Toolset community, demonstrating how you figured out how to do something that we weren't sure was possible.

Amazing, thank you!