Skip Navigation

[Resolved] set value in a CRED field

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

Problem:
How to set value in a CRED field

Solution:

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/set-value-in-a-cred-field/#post-841202

Relevant Documentation:

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 1 reply, has 2 voices.

Last updated by Minesh 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#840401

Hello, I explain my problem:

I have this input form:

[credform class='cred-form cred-keep-original']
<div class="form-group">
<label>Universidad Popular que contrata</label>
[cred_field field='_wpcf_belongs_universidad-popular_id' value='[id_univ_usuario]' required='true' class='form-control' output='bootstrap']
</div>
[/credform]

I want to auto select the field. The shortcode [id_univ_usuario] return the ID of the custom field that I want to auto select, but the field display "not-select".

My shortcode code is:

// Get 'CPT Universidad Popular' ID of the user login.
function jm_id_univ_usuario(){
global $current_user;
$args = array(
'post_type' => 'universidad-popular',
'author' => $current_user->ID,
'status' => 'publish',
);
$id_universidad = get_posts( $args );
echo $id_universidad[0]->ID;
}
add_shortcode ('id_univ_usuario', 'jm_id_univ_usuario');

Thanks.

#841202

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you are echoing the ID from your shortcode. Instead of echoing, you should return the id.

Could you please try following code:

[credform class='cred-form cred-keep-original']
<div class="form-group">
<label>Universidad Popular que contrata</label>
[cred_field field='_wpcf_belongs_universidad-popular_id' value='[id_univ_usuario]' required='true' class='form-control' output='bootstrap'  use_select2="never" ]
</div>
[/credform]

Where:
- we set the shortcode to not to use select2.

Instead of echo - return the Id.

// Get 'CPT Universidad Popular' ID of the user login.
function jm_id_univ_usuario(){
global $current_user;
$args = array(
'post_type' => 'universidad-popular',
'author' => $current_user->ID,
'status' => 'publish',
);
$id_universidad = get_posts( $args );
return $id_universidad[0]->ID;
}
add_shortcode ('id_univ_usuario', 'jm_id_univ_usuario');