Skip Navigation

[Resolved] Cred user form

This support ticket is created 5 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 44 replies, has 2 voices.

Last updated by olivierF 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1311473

Hello,
I created a user form and added a generic field with the slug 'societe'.
I would like that when the user form is submitted, the information is saved in a custom post type 'auteur' in the respective fields.
how to tell him that the generic user formfield with slug 'societe' must go into the field 'societe' which is in the cpt 'author'
Can they have the same slug?

I checked the cred documentation API https://toolset.com/documentation/programmer-reference/cred-api/
but I can't do what I want.

Here is my code for now :

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id']==62)
    {
    $my_post = array(
    'post_title'    => $_POST['wpcf-societe'],
    'post_content'  => '',
    'post_status'   => 'publish',
    'post_author'   => $post_ID,
    'post_type' => 'auteur'
);
    
wp_insert_post( $my_post );
    }
}

Merci d'avance pour votre support.
Olivier Foguenne

#1311521

Hi, the generic field will not have "wpcf-" prefix in $_POST unless you put "wpcf-" in the generic field slug in the Form builder.
So this code will set the post title to be the value of the societe generic field:

'post_title'    => $_POST['societe'],

If you want to set the value of a Types custom field, then you can add it using the 'meta_input' key in your my_post array, like this:

'post_type' => 'auteur',
'meta_input'   => array(
        'wpcf-field-slug' => $_POST['societe']
    )
#1311557

Hi Christian,
There seems to be a problem in my code, when I remove it, the user adds but when I add the code, nothing happens when I send the form.
The id of the form is the right one,
The slug is good, and the cpt also

The code :

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id']==62)
    {
    $my_post = array(
    'post_title'    => $_POST['societe'],
    'post_status'   => 'publish',
    'post_author'   => $post_ID,
    'post_type' => 'auteur',
	'meta_input'   => array(
        'wpcf-societe' => $_POST['societe']
    )
);
    
wp_insert_post( $my_post );
    }
}
#1311587

Okay, if no auteur post is created I'll need to log in and take a closer look. In my local tests, this code creates a post automatically and registers a new User. Can you provide login credentials here? Let me know where I can see the Form on the front-end of the site.

#1311621

Thank you, where can I submit the Form, from the front-end of the site? I can't find it.

#1311623

hidden link

#1311625

You must be disconnected to see the form

#1311635

It just worked for me, can you check again? New User registered:
hidden link

New Auteur:
hidden link

#1311647

thanks Christian, it works now...
Is it possible to have a multiple choice generic field with the possibility for the user to encode another proposal if it is not in the list? How can I add such a field? I must then add it to the CPT 'auteur' as a category.

#1311677

No, there's nothing exactly like that. It would require custom code. The only way to add an option in the Form like that, without custom code, would be to use a taxonomy instead of a custom field. Users can add new terms to a taxonomy, but cannot add new options to a field.

#1311683

How to use a taxonomy in user form ?

#1311699

Oh yes, I forgot we were discussing a User Form. So it's not possible to use a taxonomy field here. I guess you could use a generic field, then use Forms email notifications to send a notice to an admin User containing the new value. That admin User would then have to edit the custom field in the User field editor, then edit the User to select the correct value. It would be a very manual process.

#1311743

Thanks a lot Christian,

I have a other problem with a publication form 'projet'
You can see the form here hidden link
you must be connected with your precedent user 'christian.c' to see the form.
The information is not transmitted but when sending the form disappears.

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/forums/topic/cred-post-form-is-not-working/

#1311783

Okay I have split this question into another ticket so we can discuss in more detail.

#1312359

Hi Christian,
My user form does not work anymore, nothing happens when I send it.
I modified some elements in my code to retrieve the first and last name and the email in order to send it into the CPT 'auteur'.
Thank you very much for your precious help.
Here's my code:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id']==62)
    {
    $my_post = array(
    'post_title'    => $user_firstname,
    'post_status'   => 'publish',
    'post_author'   => $user_ID,
    'post_type' => 'auteur',
	'meta_input'   => array(
		'wpcf-type' => $_POST['type'],
		'wpcf-prenom' => $user_firstname,
		'wpcf-nom' => $user_lastname,
		'wpcf-societe' => $_POST['societe'],
		'wpcf-telephone' => $_POST['telephone'],
		'wpcf-email' => $user_email,
		'wpcf-site-web' => $_POST['site-web']
    )
);
wp_insert_post( $my_post );
    }
}