Skip Navigation

[Resolved] How to update custom field value by current date with Toolset Form

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

Problem:
How to update custom field value by current date with Toolset Form

Solution:
You can use Toolset form hook cred_save_data in order to update the custom field value with current date.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/%E8%AB%8B%E5%95%8F%E8%AE%93%E5%89%8D%E5%8F%B0%E6%9C%83%E5%93%A1%E6%96%B0%E5%A2%9E%E8%A1%A8%E5%96%AE%E7%9A%84%E6%99%82%E5%80%99%EF%BC%8C%E8%A9%B2%E5%A6%82%E4%BD%95%E8%AE%93%E6%A1%88%E4%BB%B6%E7%B7%A8/#post-954351

Relevant Documentation:

This support ticket is created 6 years, 3 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 10 replies, has 3 voices.

Last updated by FuChan 6 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#952009

你好,

我有一個「申請案件管理」的帖子,後台客製欄位有「案件編號」是「數字」的格式,我要讓會員在前台填這個帖子的表單,但「案件編號」不給會員自已填寫,要讓會員填表單送出的時候,系統自動流水號產生,請問該如何製作,有沒有類似的文檔,謝謝

#952180

你好,

Toolset Form 插件默認是沒有你説的功能的,你可以采用下面的一個選項
1) 使用POST ID, 來做「案件編號」,它也是數字格式
hidden link

2) 創建一個新的數字自定義欄位,儅用戶提交Toolset Form的時候,使用"cred_save_data" 來設置數字欄位,這個方法需要使用PHP代碼,參考我們的文檔:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#954278

你好,

謝謝你的幫忙「案件編號」我用post_id處理掉了~

另外請教一個cred_save_data問題:

我完成以下這段程式碼,要在表單送出後,自動把「處理進度」的欄位變成「送件中」選項,但我不曉得要放在post form的哪個位置,請問是放在JS editor嗎?

另外我的「處理進度」的field slug是「processing-progress」,裡面的選項「送件中」為「1」,這段程式碼可以word嗎?

謝謝~

<?php

//送出申請表單後,讓「處理進度」變成「送件中」.
add_action('cred_save_data','func_custom_processing_progress',10,2);
function func_custom_processing_progress($post_id,$form_data) {
    if ($form_data['id']==9999) {
        $args = array('processing_progress' => '1');
        wp_update_post($args);
    }
}

?>
#954281

Minesh
Supporter

Languages: English (English )

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

Luo is on vacation. This is Minesh here and I will take care of this ticket and try to help you further but I can only understand English.

Could you please share your queries in English laugnage so I can guide you in right direction.

#954296
201807241449261.png

Hello ,

Thank you for your help, "case number" I processed with post_id~

Also ask a cred_save_data question:

I have completed the following code:

<?php
 
//After sending out the application form, let "Process Progress" become "Send In".
add_action('cred_save_data','func_custom_processing_progress',10,2);
function func_custom_processing_progress($post_id,$form_data) {
    if ($form_data['id']==9999) {
        $args = array('processing_progress' => '1');
        wp_update_post($args);
    }
}
 
?>

After the form is sent, I automatically change the "Processing Progress" field to the "Send in" option, but I don't know where to put it in the post form. Is it in the JS editor? ?

In addition, the field slug of my "processing progress" is "processing-progress". The option "Send in" option is "1". Can this code be work?

Thank you~

#954305

Minesh
Supporter

Languages: English (English )

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

Ok - As I understand you want to update the value of custom field "processing-progress" after user submit the form. Types custom field stored in postmeta table.

So you need to use the following code:

//After sending out the application form, let "Process Progress" become "Send In".
add_action('cred_save_data','func_custom_processing_progress',10,2);
function func_custom_processing_progress($post_id,$form_data) {
    if ($form_data['id']==9999) {
           update_post_meta($post_id,'wpcf-processing-progress',1);
    }
}

Where:
- Replace 9999 with your original form ID

#954319
201807241546052.png

Thank you. I get it and it is work.

Also ask:

If I want to update today's date to wpcf-date-delivery, can I use the following code?


//After sending out the application form, let "Process Progress" become "Send In".

add_action('cred_save_data','func_custom_processing_progress',10,2);
function func_custom_processing_progress($post_id,$form_data) {
    if ($form_data['id']==214) {
           update_post_meta($post_id,'wpcf-processing-progress',1);
           update_post_meta($post_id,'wpcf-date-delivery',today());
    }
}

#954351

Minesh
Supporter

Languages: English (English )

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

You should try to use following code to update the date field to current time value.

add_action('cred_save_data','func_custom_processing_progress',10,2);
function func_custom_processing_progress($post_id,$form_data) {
    if ($form_data['id']==214) {
           update_post_meta($post_id,'wpcf-processing-progress',1);
           update_post_meta($post_id,'wpcf-date-delivery',time());
    }
}
#954353

Thank you. It is working.

Also ask:
I have a registration form , Userid input phone number.
I have a custom field is "mobile".
I want to update userid to mobile,when user registration form subitted.
Is this code correct to what I want?

add_action('cred_save_data','userid_update_to_mobile',10,2);
function userid_update_to_mobile($post_id,$form_data) {
    if ($form_data['id']==9999) {
    	$user_id => get_userdata( $user_id )
        update_post_meta($post_id, 'wpcf-mobile', $user_id);
    }
}

Thank you.

#954356

Minesh
Supporter

Languages: English (English )

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

Well - we can not continue this way, as per our support policy we answer only one question per ticket as this will help other users searching on the forum and to write correct resolve ticket summary.

May I kindly ask you to open a new ticket with your each new question. This will help other users searching on the forum.

Even you can create a new ticket and assign it to me.

#954363

Thank you Minesh. I have created a new ticket. But I do not know how to assign it to you.