Skip Navigation

[Resolved] Multistep Form Redirects

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#2501797

The setup:
Post types: Landlord (parent) --> Property (child)
Property (parent) --> Property Review (child)
Landlord (parent) --> Landlord Review (child)

I need to create a form which is a review of both the property and the landlord that is the parent of that property. One should lead into the other.

You go to a page for the property: test.site.whatever/rental/123-fake-road/ and click on "Review".
That takes you to the first form: test.site.whatever/rate-property/?parent_rental_id=51
Once you submit that, you should automatically (through some cred_success_redirect magic I assume) be taken to the form to review the landlord for that same property (the parent of the post you just reviewed).
test.site.whatever/rate-landlord/?????

What variables can I use to accomplish this and what does it look like? Many thanks.

#2502201

Hi,

Thank you for contacting us and I'd be happy to assist.

What you're trying to achieve is possible and you're thinking along the right lines.

1. You'll create two separate pages, one for each review post form:

a). Rate Property
test.site.whatever/rate-property

b). Rate Landlord
test.site.whatever/rate-landlord

2. The parent relationship field in those forms, will be set to link to a URL parameter to read the parent post's ID.

For example, for the rate property form:
test.site.whatever/rate-property/?target-property-id=1234

And for the rate landlord form:
test.site.whatever/rate-landlord/?target-landlord-id=1234

3. The first "Review" link on the single property page will simply need the [wpv-post-id] shortcode, to pass the current property post's ID:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-id )

test.site.whatever/rate-property/?target-property-id=[wpv-post-id]

4. For the next step of redirecting to the second page "Rate Landlord", you'll use the "cred_success_redirect" filter:
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect )

In this filter's function, you can get the ID of the target "property" post through the URL parameter "target-property-id" by using the super global '$_GET' ( $_GET['target-property-id']" ).
( ref: hidden link )

And once you have the ID of the property, you can get the ID of its parent "landlord" post, by using the "toolset_get_related_posts" function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

That ID of the related parent landlord post can then be set in the final redirect URL so that on submission of the first form, the user is redirected to the second form page, with the correct URL parameter value of the landlord.

I hope this helps and please let me know if you need any further assistance with this.

regards,
Waqar

#2506443

Thank you for the detailed response.
Do you have any examples of that the functions.php file would look like to achieve this?

#2507429

Thanks for writing back.

We don't have a copy/paste file/snippet available for this, but I can assist you with some pointers on how to make the custom code work.

Can you please share temporary admin login details, along with the link to the pages where these forms can be seen?

I'll be in a better position to suggest the next steps, accordingly.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2509599

Thank you for sharing the admin access details.

I'll be performing some tests on my website with a similar setup and will share the findings with you as soon as I can.

Thank you for your patience.

#2515301

Thank you for waiting, as we had an unusually busy forum queue.

I've performed some testing on my website with a similar setup and here is an example of the code snippet, for the redirection code:


add_filter('cred_success_redirect', 'custom_redirect_property_rating_form',10,3);
function custom_redirect_property_rating_form($url, $post_id, $form_data)
{
	// check if specific form
	if ($form_data['id']==197) {
		if(!empty($_GET['parent_rental_id'])) {
			// get the parent manager post ID
			$get_results = toolset_get_related_posts( $_GET['parent_rental_id'], 'property-manager-property', 'child', 1, 0, array(), 'post_id', 'parent' );
			// if found append it in the URL parameter 'parent_manager_id'
			if(!empty($get_results)) {
				$url = $url.'?parent_manager_id='.$get_results[0];
			}
		}
	}

	return $url;
}

This function will be executed when your website's "Property Rating (Step 1)" form (ID: 197) will be submitted. It will get the ID of the target property from the URL parameter 'parent_rental_id', get its related parent 'property manager' post ID and set it in the redirection URL, in the parameter 'parent_manager_id'.

Important: The form "Property Rating (Step 1)" is currently set to show a message instead of the form, when the form is submitted. To make this redirection code work, make sure that this option is set to redirect to the next rating form page, which is "Rate Manager".

#2517329

That did the trick. Many thanks!