"Calculate" an URL for creating of a users subsite at registration

By: Maximilian Beyer | Asked: 12/09/2023
ForumsCategory: How-to"Calculate" an URL for creating of a users subsite at registration
Maximilian Beyer asked 4 months ago

Hello everyone,

In my WP multisite network, I'm trying to give new users the option of assigning an individual subdirectory string for the subsite they create with their registration. The registration form should already show the user what the future URL of their subsite will look like.

I have tried various ways and have always come to a dead end:

Putting it together as [siteurl]/[x] to display it in in a string- or a html-field, where x is the ID of the text field for entering the subdirectory string, works, but adding "sanitize=1" or "sanitize_url=1" does not work even when I'm using page breaks between the entry and the display field. This means that spaces and special characters are not converted to URL-specific strings and the user cannot see the final result.

The attempt to temporarily store the entire URL in a text calculation field [y] and then have it checked or corrected in a separate URL field failed, as I apparently cannot enter an ID [y] in the URL field. I hope I have been able to describe my problem clearly and would be grateful for any advice (even if someone has already faced the same problem and it simply cannot be solved).

Many thanks in advance!

2 Answers
Rob LeVineRob LeVine answered 4 months ago

If I understand your requirement, you can use a text field in your form and let the user type in whatever they want and then use the hook frm_after_create_entry to create the full URL in PHP and either store that new value in the same field or in another hidden field. Regardless of how you do it, I'll assume you need to use the hook frm_validate_field_entry to validate that no two users try to create the same subdirectory.

Maximilian Beyer answered 4 months ago

Thank you so much for your quick reply. I haven't used any of the hooks yet, so I think I'll work on the rest of my todos first and try that when it's time. I am still learning ^^! 

Rob LeVineRob LeVine replied 4 months ago

When you start using hooks, I suggest reading this first - https://formidableforms.com/knowledgebase/formidable-hooks/

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right