Skip Navigation

[Resolved] Split: Post form for unsubscribe – multiple email and display form field with url param value

This support ticket is created 5 years, 7 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.

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 5 replies, has 2 voices.

Last updated by Minesh 5 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1283951

One last question,

Is it possible to fill the mail field from urlparam?

Just adding the urlparam="" to cred field?

And another one, do this check the checkbox on all custom posts agent? If someone add his email 2 times (two posts) it will be nice, tu unsubscribe him on both posts...

#1283955

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Yes - Toolset form's shortcode [cred_field] supports the attribute urlparam :
=> https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

So, yes, you should add the attribute urlparam to the [cred_field] shortcode:
For example:

[cred_field field='email-agent' force_type='field' class='form-control' output='bootstrap' urlparam="url-param-name"]

Where:
Replace the url-param-name with original url param name.

For now, we wrote the code for one post. If you want to have multiple post, you should adjust the code I shared.

#1287817

So I should use

foreach

function to use it for all posts?

#1288367

Minesh
Supporter

Languages: English (English )

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

Sorry - Can you please elaborate more where exactly you want to use the foreach?

#1288475

In this snippet:

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_action('cred_save_data', 'func_check_sub_email',10,2);
function func_check_sub_email($post_id, $form_data){
  
  
  		
    // if a specific form
    if ($form_data['id']==687){
      update_post_meta($post_id, 'wpcf-email-agent','');
      
      $args   =   array(
					'posts_per_page'   => -1,
					'post_type'     => 'agent',
					'meta_query'    => array(
    							array(
        						'key'       => 'wpcf-email-agent',
        						'value'     => $_POST['wpcf-email-agent'],
        						))
                     );
			$query = new WP_Query($args);
      		
            if ( $query->have_posts() ) {
             	if(metadata_exists('post', $query->post->ID, 'wpcf-odhlaseni'))
              		update_post_meta($query->post->ID, 'wpcf-odhlaseni', 1);
                else
                  add_post_meta($query->post->ID, 'wpcf-odhlaseni', 1);
                  
              
            }else{
              	update_post_meta($query->post->ID, 'wpcf-odhlaseni', 0);
            } 
        
    }
}

I need it to look at all DB entries, if there is the mail adress multiple times, to check the chekbox for all. of them.

#1288511

Minesh
Supporter

Languages: English (English )

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

Yes - you need to use foreach and adjust the code accordingly if needed.