How to add a form field to a link extension in a view

By: ali adli | Asked: 03/11/2024
ForumsCategory: Code SnippetsHow to add a form field to a link extension in a view
ali adli asked 9 months ago
I want to add a link to a members' profile page. And need to do this inside the view. This works. But, it only works for the users with a single username. If any space is used, or if a user decides to register with email I have to filter out some characters and empty space. So for this I tried to add the following, but it fails: <?php
$usrk=[form field key]; //username form field key
$clnusr=str_replace(' ', '', $usrk); //to remove the space
?>
<a href="https://www.site.com/members/<=? '$clnusr' ?>"> Profile</a> Somehow, php does not work in editing section of the page content of the relevant view. Any help is appreciated.
2 Answers
Victor Font answered 8 months ago
How are you creating the link in a view? Are you embedding the PHP directly into the view HTML? Why are using user name instead of user id?
ali adli answered 8 months ago
Hi Victor, I am using the text box in view, and the html code for the link to the username site. So, it must be username, not ID. Without the php this code works. It opens the user profile page. But the problem is in wordpress username is not restricted. A user can leave space or use email address as username. There I get an error. I have to delete the space and @ and replace. with -. 
Victor Font replied 8 months ago

You cannot use unsanitized text in a URL. To work in a URL, the special characters need to be converted to HTML entities. I suggest you store the sanitized user name in a hidden field and use that as your link. What you want to do will never work.

See this: https://formidableforms.com/knowledgebase/advanced/#kb-sanitize-url

ali adli replied 8 months ago

Thanks Victor,
You were right. My approach was peculiar indeed. sanitize_URL did not work. But [x sanitize=1] worked perfectly.

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