Skip Navigation

[Resolved] User sign up in create form custom typ

This support ticket is created 4 years, 2 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Raja Mohammed 4 years, 2 months ago.

Assisted by: Raja Mohammed.

Author
Posts
#1831373

Hi!

I would like create a form to create a custom type and sign up a user in the same form.

is it possible?

For example.

Fields about user:
- Email
- Name
- Phone

Fields about our shop:
- Address
- Products
and more

Could you help me?
Thanks!

#1831955

Raja Mohammed
Supporter

Languages: English (English )

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

Hello there,

The User and Post forms are two separate form types and cannot be processed on a single form submission.

The best approach is to set up a multi step form where you can create a separate form for the Users and another one for the Post type. Once the user form is submitted it can be redirected to a specific page to which the Post Form is added, ( The redirection can be added from the form settings. )

In order to pass the user information from user form to the post form, Make use of the API <srong>cred_success_redirect and the WordPress Query args

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
 // Allow to be run on the user form
    if ($form_data['id']==86)
        $user_data = get_user_by('login', sanitize_text_field($_POST['user_login']));    
       $arr = array('user_id' => $user_data->ID );
       $url = add_query_arg($arr, $url);
    
    return $url;
}

The above code will redirect to the page with the user_id as a url parameter,

To Automatically fetch the url parameter in the post form make the cred_generic fields as below

[cred_generic_field type='hidden' field='user-id' urlparam='user_id']
{
"default":"",
"generic_type":"user_id",
"persist":1
}
[/cred_generic_field]

And after that use cred_save_data hook to get the hidden field's value from $_POST global, for example what is used here:
https://toolset.com/forums/topic/change-author-attribution-on-cred-form-submitted-content/#post-609667

I hope this helps better.

Kind regards
Raja

#1835337

Thanks for you reply.

Could you said me where i have to add this function?

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
 // Allow to be run on the user form
    if ($form_data['id']==86)
        $user_data = get_user_by('login', sanitize_text_field($_POST['user_login']));    
       $arr = array('user_id' => $user_data->ID );
       $url = add_query_arg($arr, $url);
     
    return $url;
}

And this?

[cred_generic_field type='hidden' field='user-id' urlparam='user_id']
{
"default":"",
"generic_type":"user_id",
"persist":1
}
[/cred_generic_field]

thanks

#1835395

Raja Mohammed
Supporter

Languages: English (English )

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

The function can be added in the theme functions.php file.
Kindly adjust the code according to your field values and form id.