Skip Navigation

[Resolved] Using CPT entries in CRED registration form – select field

This support ticket is created 7 years 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 24 replies, has 2 voices.

Last updated by filipV-3 7 years ago.

Assisted by: Luo Yang.

Author
Posts
#581940

It's unfortunately not working for me Luo. As form ID, i took the one of the initial registration (but isn't it needed to also do this for id of the 'edit' cred form?)
user field slug: here was none prepared yet, so i just did. But how exactly is the right format here? I should choose 'select' field since on the cred forms it's a select field, i presume? What then with all those conditional groups: i should recreate all possible conditions and update it every time here as well, if a new entry comes in. In that case I wouldnt mind not using this field in 'user fields' at all.
So that leaves us that by registering that field is still not registered /jde-user-registration/, as in the edit cred form it remains empty.... /jde-shop/my-account/my-brands/
Thank you!

#581978

I have done below modifications in your website:
1) create a custom single line user field "billing-addresses"
hidden link
Types plugin will prepend "wpcf-" before the field slug, so in database the field meta key is "wpcf-billing-addresses"
Use it to store the post ID value

2) Modify the PHP codes as below:

add_action('cred_save_data', 'update_user_field_func',10,2);
function update_user_field_func($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==800){
		$t2 = $_POST['t2'];
		$user_id = $post_id;
		update_user_meta($user_id, 'wpcf-billing-addresses', $t2);
    }
}

You can test result in the page:
hidden link
After submit the CRED form, there will be a new user, edit that user, you will see the field "Billing Addresses" value is value you setup in the views.

It is only an example, you will need to customize it to what you want.

#581987

hi Luo,
"After submit the CRED form, there will be a new user, edit that user, you will see the field "Billing Addresses" value is value you setup in the views."
--> not so. At registering i input the address from the select list, and when i look in 'edit users' in admin, the value says '866'.
And furthermore, the value in the 'cred edit user form' field remain empty...

ps please be so kind and edit the main url out of your last reply, thanks! 😉

#581992

As you request, I have modified the post to hide your domain name:
https://toolset.com/forums/topic/using-cpt-entries-in-cred-registration-form-select-field/page/2/#post-581978

For the new question:
https://toolset.com/forums/topic/using-cpt-entries-in-cred-registration-form-select-field/page/2/#post-581987
not so. At registering i input the address from the select list, and when i look in 'edit users' in admin, the value says '866'.

Yes, as I mentioned above, this custom field will be able to store the post ID value, which is outputted form the view:
hidden link

See my post:
https://toolset.com/forums/topic/using-cpt-entries-in-cred-registration-form-select-field/#post-580946

"value":"[wpv-post-id]"
 

And it is only an example code for showing how to save a generic field value into database with CRED action hook cred_save_data, you will need to customize the codes according to your website settings.
For your reference.

#582000

ok i understand.
But the most important issue is that the 'cred edit user' form field remains empty. Isn't it supposed to pick up the value from the cred register form directly?
Thank you

#582258

I have done below modification in your website:
1) Modify the view "Billing Address View":
hidden link
section "Loop Output Editor", change the codes as below:

[hide-it][wpv-layout-start][/hide-it]
	[wpv-items-found]
{"value":"","label":"--- Select ---"}
	<!-- wpv-loop-start -->
	<wpv-loop>
            , {"value":"[wpv-post-id]","label":"[wpv-post-title] | [types field='billing-fields-types-number'][/types] | [types field='billing-field-types-address'][/types] | [types field='billing-fields-types-postcode'][/types] | [types field='billing-field-types-city'][/types] | [types field='billing-field-types-phone'][/types] | [types field='billing-field-types-vat'][/types]"}
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[hide-it][wpv-layout-end][/hide-it]

It will display the option "--- Select ---"

2) Edit the CRED form "Account details":
hidden link
Change the generic shortcode to:

[cred_generic_field field="t2" type="select" class="" urlparam=""]
{
"required":1,
"validate_format":1,
"persist":1,
"default":["[wpv-user field="wpcf-billing-addresses"]"],
"options":[[wpv-view name="Billing Address View"]]
}
[/cred_generic_field]

It will be able to setup current user's field value as the default option

3) Edit the CRED form "Registration Form":
hidden link
Change the generic shortcode to:

[cred_generic_field field="t2" type="select" class="" urlparam=""]
{
"required":1,
"validate_format":1,
"persist":1,
"default":[""],
"options":[[wpv-view name="Billing Address View"]]
}
[/cred_generic_field]

setup the default option as empty

4) Create a page to test the edit form:
hidden link

Please check if it is what you want. and please create new thread for the new questions, that will help other users to find the answers,

#582378

Hi Luo,
thanks, now the entry is saved and visibly seen in the 'edit cred' form ( /account-details/ )
However, it's not possible to edit the entry in that same form afterwards. I change the choice, press 'submit', and while it gives a success popup, the entry is still the same old one...
(that's not a new question 😉 )

If that could still be repaired, than we close the issue surely.
Kind regards

#582468

Hi Luo, in addition to above last reply of me:
(below is not a new question but rather continuing of the actual issue)

I have now added 3 views instead of the one you were editing; one per region (and more will follow)
I edited the cred reg and cred edit user forms, works well, except from what i wrote in the reply before this one.

But now i need to ask: you wrote following code for functions.php :
add_action('cred_save_data', 'update_user_field_func',10,2);
function update_user_field_func($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==800){
$t2 = $_POST['t2'];
$user_id = $post_id;
update_user_meta($user_id, 'wpcf-billing-addresses', $t2);
}
}

--> this is no longer usable since we're no longer working with just 1 "t2" ID, but with an ID per regio (as seen in cred forms)
So how should be the updated version of this code in functions.php now? (let's say we have t2, t3, t4)
OR do we just need to keep all of those named 't2'?

Thanks a lot Luo!

#582543

Hi filip,

As I mentioned above, it is only a demo, you will need to customize it.
The original post of this thread is a CRED form for creating post, now the new questions is about CRED form for editing post and other CRED forms and other CRED generic fields, so the question is different.

For the new questions:
Q1) However, it's not possible to edit the entry in that same form afterwards. I change the choice, press 'submit', and while it gives a success popup, the entry is still the same old one...
The PHP codes only works for CRED form(id 800), if you need to apply same function to other CRED form, for example: you will need to modify the PHP codes, from:

if ($form_data['id']==800){

To:

if (in_array($form_data['id'], array(800, 838))){ // here you can add more CRED form ID into the array

More help:
hidden link

Q2) this is no longer usable since we're no longer working with just 1 "t2" ID, but with an ID per regio (as seen in cred forms)
1) It needs new custom fields setup with Types plugin, see post:
https://toolset.com/forums/topic/using-cpt-entries-in-cred-registration-form-select-field/page/2/#post-581978
step 1) create a custom single line user field "billing-addresses"
You will need to create other custom user fields for new generic fields

2) Then modify the PHP codes to add new fields, for example:

$t3 = $_POST['t3'];
$user_id = $post_id;
update_user_meta($user_id, 'wpcf-t3', $t3);

Again, it is only a exapmle, you will need to customize it, please create new thread for the new questions, that will help other users to find the answers,

#582545

ok thanks Luo, i implement this in the morning, and if anything, will open a new thread.

Kind regards