Skip Navigation

[Gelöst] Redirect to Parent After CRED Child Post Form Submission

This support ticket is created vor 1 Jahr, 3 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Dieses Thema enthält 5 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Nigel vor 1 Jahr, 3 Monaten.

Assistiert von: Nigel.

Author
Artikel
#2637817

I have 2 post types:

company
company-review

I have a one to many relationship:

company-company-review

I have a CRED forms to create child "company-review" with edit button to link to content template.

CRED IDs:
Create: 722
Edit: 783

I've tried to follow this ticket: https://toolset.com/forums/topic/frontend-child-form-after-submission-redirect-to-parent-post/

My code snippet:

add_filter('cred_success_redirect_783', 'redirect_to_parent', 10, 3);

function redirect_to_parent($url, $post_id, $thisform) {
$parent_id = $_POST['@company-company-review_parent'];
return get_permalink( $parent_id );
}

This is just for the edit form to test. It currently refreshes the page, but does add &_success=783_1_1&_target=826&cred_referrer_form_id=783#cred_form_783_1_1 to the url.

Any advice is appreciated and have a great day.

#2638187

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Hi there

What are the form settings for what to do after the form is submitted?

It must be set to redirect to a specific page or post, otherwise the cred_success_redirect hook will not be triggered. (You can set it to redirect to any page, given that you will overwrite the URL to redirect to.)

#2638409

Thank You that works now! I hope you are having a great day.

I have another related question. On my CRED form, I'm trying to hide the parent selector since I only want people to be able to submit 1 review. I've tried adding type='hidden', but it's not working so I'm currently just using display: none; , which isn't as secure as I'd like it to be. Here is my field:

<div class="form-group parentSelector">
<label for="%%FORM_ID%%_@company-company-review.parent">[cred_i18n name='@company-company-review.parent-label']Companies Company Reviews[/cred_i18n]</label>
[cred_field field='@company-company-review.parent' value='[wpv-post-id]' type='hidden' class='form-control' output='bootstrap' select_text='--- not set ---' required='true']
</div>

Any advice is appreciated.

#2638531

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

It's not possible to add attributes to the form fields in that way, and clients typically hide the parent selector with CSS.

There isn't really a foolproof way of preventing users from using the browser dev tools to manipulate the selector, as they could do so whichever method is used to hide or disable the selector, and adding server-side validation doesn't really work in this scenario because the only way you would know what is the correct parent ID is based on the value submitted in the form anyway.

#2639011

Thank You. I'm showing the form only on the parent post when the user doesn't have any child posts for that parent using a view. I'm concerned users would be able to post multiple child posts by going to a different parent and using dev tools to be able to post on the original parent multiple times. Is there a way to limit the amount of child posts for a user for a parent post?

#2639191

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

If you want to limit how many child posts can be added to a parent post to just one then that can be done, you would need to use the cred_form_validate hook, see https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

In your case in your callback function you would get the child posts of the specified parent (using toolset_get_related_posts: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts) and if that were anything other than zero then you would reject the form submission.