Skip Navigation

[Résolu] set value in a CRED field

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 6 années et 5 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Minesh Il y a 6 années et 5 mois.

Assisté par: Minesh.

Auteur
Publications
#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

Les langues: Anglais (English )

Fuseau horaire: 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');
Ce ticket est maintenant fermé. Si vous êtes un client de Toolset et que vous avez besoin d'aide, veuillez ouvrir un nouveau ticket d'assistance