Skip Navigation

[Resuelto] Reverse creation process of CPT posts

This support ticket is created hace 4 años. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 6 respuestas, tiene 2 mensajes.

Última actualización por boW-2 hace 4 años.

Asistido por: Raja Mohammed.

Autor
Mensajes
#1839329

Tell us what you are trying to do?

I want to let a guest create a CPT post and afterwards create him as a user and register him as the author of the post

Steps:
1. guest user to enter data into a Toolset CPT form
2. On submit the post is stored (guests will be allowed to create posts with Toolset Access), and automatically taken to next step
3. The Id for the new post is displayed to the Guest and he is prompted to enter a password (new form?)
4. On submit a new user id is created (username = post Id, password = what guest entered) (php-code)
5. The post author is updated with username (php-code)

When the user later returns to the site he can login using the “post id” as username (from step 3) and the password he entered (from step 5).

Example to illustrate:

Screen 1 (the post):
Enter some data : ___________
Enter more data: ___________
SUBMIT-button

Screen 2:
The case Id created is: 12345
Enter your password: ______________
SUBMIT-button

User can later login with user-id: 12345 and the password entered - to display the post from screen 1 data (as an author)

Questions:
A. Step 1+2 is standard Toolset, but how can I jump to a new form and display the Id given (step 3) ??
B. I assume I will be able to code step 4+5 with PHP. Any hooks I can use ??

Your input is appreciated

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1839861

Raja Mohammed
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello there,

Basically for your approach you need to create two separate form one for the post (post form) and another for the user (user form)/

Regarding your questions:

A. Step 1+2 is standard Toolset, but how can I jump to a new form and display the Id given (step 3) ??

- From the post form you need to add a redirect to a specific page in the form settings, The specific page will be the page where the user form will be displayed
- In order to pass the Post information from post form to the user form, Make use of the API <srong>cred_success_redirect and the WordPress Query args
eg:

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
 // Allow to be run on the specific form
    if ($form_data['id']==86)
       $arr = array('username' => $post_id );
       $url = add_query_arg($arr, $url);
     
    return $url;
}

With the above code once the form is submitted it will be redirected the page specified in the form setting with the url param ?username=999
Refer : https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

B. I assume I will be able to code step 4+5 with PHP. Any hooks I can use ??

- A minor adjustment needs to be done in the user form. Instead of the username field use the cred_generic_field, as this can be an hidden field also gets the value directly from url using the url param attribute

eg:

[cred_generic_field type='hidden' field='user_login' urlparam='username' ]
{
"default":""
 }
[/cred_generic_field]

Refer : https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_generic_field

- Now you have both the form setup , With the help of the hook cred_save_data You can update the post with the appropriate author from the user form.
Refer : https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

I hope this helps better

Regards
Raja

#1846385

Hi Raja - thanks a lot for the support.

I struggle with the implementation of part B (cred_generic_field-part). I lack information/training about how to use the cred-fields. The programmers reference documentation doesn't help me. I have searched for how-to tutorials but havent found any ?!

Appreciated if you could help with link(s)

#1846901

Raja Mohammed
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Sure i can help can you let me know what is not clear in the document or where i can help.

Just in case if you are struggling with adding parameters to the cred_generic_fields you should enable the Expert mode in the form to see the form code where you can alter the field parameters.

You can also directly use my code for the generic field, Turn on the Expert mode in the form edit screen, Remove the default username field and replace it with the generic field code from my previous reply that should help as well.

#1847159

Hi Raja - your support is highly appreciated ! I have now succeeded in creating a new user (step B).

What I still need is to also be able to display the parameter transfered in the URL (in the form). Currently this value goes to the login_login field (hidden). How can this be achieved?

I have also searched for tutorials/documentation that explains how to use "expert"-mode in the form. Does it exist?

#1847317

Raja Mohammed
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Screenshot 2020-11-17 at 5.54.40 PM.jpg

You can turn on the Expert mode in form editor please check the attached screenshot, If you are stuck share temporary access to the site. let me try to help you with the setup. I have enabled private fields to securely share the details.

#1847329

My issue is resolved now. Thank you!