Skip Navigation

[Resolved] How to display the form instead of a drop down menu

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

Problem: I would like to show a Form that will create a child post and automatically link that post to the parent post where the Form is shown.

Solution: Add a generic field in the Form and set the value using wpv-post-id and the $current_page operator. Then use the Forms API cred_save_data to trigger the post relationships API toolset_connect_posts, connecting the new post and the post where the Form is shown.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

This support ticket is created 5 years 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
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 29 replies, has 2 voices.

Last updated by ayoub-aliq 5 years ago.

Assisted by: Christian Cox.

Author
Posts
#1385103
658566.jpg
023658.jpg

Hi
I'm want to set the form fields instead of the drop-down menu
But that didn't work
Although I followed the explanation in the link below

01: https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/
02: https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/creating-new-connections-between-related-posts/

The steps you did are as follows:
steps 01: create new relations "So much to much"
steps 02: create form relations forms
steps 03: create template and add in relations forms
--
But only a drop-down menu appears

#1385263

I'm want to set the form fields instead of the drop-down menu
But that didn't work

Hello, please allow me to clarify this. A Relationship Form cannot create new Student posts. It can only create relationships between posts that already exist. Similarly, a New Post Form cannot create many-to-many relationships between posts. It can only create posts. If you want to create a Student post from this page, you must insert a new Student Post Form. If you want to link an existing Student to this Course in a many-to-many relationship, that Student must already exist. Then you can use a Relationship Form to link the Student and the Course.

If you want to automatically link a Student and a Course from a new Student Post Form, it is possible using custom code and our Forms API and our Toolset Relationships API. We have documentation for those APIs available here, with code examples:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

Let me know if you have questions about this type of automation and I can offer some more guidance.

#1385341
3625455.jpg

Excuse me if my question is not clear
Please see the attached picture
I mean how to show the child form in the front-end

thank you for help

#1385353
Screen Shot 2019-11-17 at 2.23.19 PM.png

You must create this Form, then insert it in the site somewhere. Go to Toolset > Post Forms and create a new child post Form. Then insert the new child post Form somewhere, for example, in the parent post Content Template. Click the "Toolset Forms" button to insert the new child post Form (see the screenshot).

Please note that you cannot place a new child post Form inside another Form. The parent and child Forms must be completed separately.

#1385363

A Relationship Form cannot create new Student posts

I want students register in courses from the front-end?

#1385389

You must create this Form, then insert it in the site somewhere. Go to Toolset > Post Forms and create a new child post Form. Then insert the new child post Form somewhere, for example, in the parent post Content Template. Click the "Toolset Forms" button to insert the new child post Form (see the screenshot).

Yes, sir, but when I do the student is not saved under any course

#1385427

I want students register in courses from the front-end?
Yes, sir, but when I do the student is not saved under any course
If you want to automatically link a Student and a Course when a new Student Post Form is submitted, it is possible using custom code with our Forms API and our Toolset Relationships API. We have documentation for those APIs available here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

Let us assume you place the new Student Post Form inside the Course Content Template. When the User submits the Form, you want to create a Student post and automatically link it to the current Course. You must follow these steps:
- Create a "number" generic field in the New Student Post Form called "current-course".
- Set the value of this field to be the ID of the current post:
[wpv-post-id item='$current_page']
- Use the cred_save_data API to trigger the toolset_connect_posts API when the New Student Post Form is submitted, for example:

add_action('cred_save_data', 'connect_new_student_and_course',10,2);
function connect_new_student_and_course($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12345)
    {
        if (isset($_POST['current-course']))
        {
            // connect the new student to the current course
            toolset_connect_posts( 'relationship-slug', $_POST['current-course'], $post_id );
        }
    }
}

- Replace 12345 with the numeric ID of the new Student Post Form.
- Replace relationship-slug with the slug of the many-to-many relationship.

Let me know if you have questions about using custom code.

#1385441
add_action('cred_save_data', 'connect_new_student_and_course',10,2);
function connect_new_student_and_course($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12345)
    {
        if (isset($_POST['current-course']))
        {
            // connect the new student to the current course
            toolset_connect_posts( 'relationship-slug', $_POST['current-course'], $post_id );
        }
    }
}

Where to use this code?

#1385445

You can place custom PHP in a child theme's functions.php file, or you can paste the code into a new custom code snippet in Toolset > Settings > Custom Code.

#1385475


- Replace 12345 with the numeric ID of the new Student Post Form.

Do you mean here to determine the course id number?
But I have, for example, 50 courses
Do I need to specify the id number on each course?


- Replace relationship-slug with the slug of the many-to-many relationship.

I did not understand this

thank you sir

#1385477

The idea is sir
I want to work as directory courses
some Members register new courses
some Members register for those courses

#1385481
form-id.png
relationship-slug.png

- Replace 12345 with the numeric ID of the new Student Post Form.
Do you mean here to determine the course id number?
No. I mean you should go to Toolset > Post Forms and find the numeric ID of the new Student Post Form. I am attaching a screenshot here form-id.png showing the numeric ID of each Form in an example site.

- Replace relationship-slug with the slug of the many-to-many relationship.
I did not understand this
Find the slug of the many-to-many relationship by going to Toolset > Relationships. Then click "Edit" for the Students - Courses many to many relationship. You can find the slug of the relationship here. I am attaching a screenshot here relationship-slug.png showing the slug of an example relationship. My example relationship slug is book-chapter, so the code for my example would be:

toolset_connect_posts( 'book-chapter', $_POST['current-course'], $post_id );

You should replace book-chapter with the slug of your Students - Courses relationship.

#1385503

Thank you sir This is very clear
But what if you want members to register new courses
Others join these courses
How to make the member open the course page and fill out the form

#1385505

I don't completely understand, sorry! How is the Student post created for a new User? Is there a Form where new Users create Student posts, or is the Student post created in wp-admin by some administrator?

#1385507

The action is as follows:
I have two members "Teachers" and "students"
1-the teachers-members create new course in front-end page
2-the students-members On the course page, view the registration new student form

Another example:
1- Members ask questions
2- Administrators respond to it via the form on the question page

Just that's all I want
I'm very sorry that I couldn't make the question well