In this short tutorial, I am going to show you how to get the slug from a url.
1. Create the fields
We need to create two fields:
- Text field with name attribute –
plugin_url
- Hidden field with the name attribute –
plugin_slug
2. Adding the code
We need to then hook into one of the many Fluent Form hooks that exist.
The hook we need is fluentform_insert_response_data
<?php add_filter('fluentform_insert_response_data', 'tct_get_url_slug', 10, 3); function tct_get_url_slug($formData, $formId, $inputConfigs) { if($formId != 47) { // Replace with your Form ID return $formData; } $formData['plugin_slug'] = basename($formData['plugin_url']); return $formData; }
Copy
What we are doing in this hook is getting the input from the user. In this case it’s plugin_url
and then usin g the built-in basename PHP function to extract the trailing name. (Or last part after the /
)
Final output
As you can see from the image below, the function pulls the slug from the end of both url’s and saves them in the hidden field we created.
Note: Make sure to replace your form ID