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
![Click here](https://images.tango.us/public/edited_image_f37bffb5-c72e-4548-9ac9-2d7ec6b33a64.png?fm=png&crop=focalpoint&fit=crop&fp-x=0.5000&fp-y=0.5000&fp-z=1.0000&w=1200&ar=2214%3A574)
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.
![screenshot 2022 09 27 at 20.35.17](https://snippetclub.com/wp-content/uploads/2022/09/screenshot-2022-09-27-at-20.35.17.png)
Note: Make sure to replace your form ID