Add Slashes to input field

By: Ryan De Clute | Asked: 08/16/2022
ForumsCategory: How-toAdd Slashes to input field
Ryan De Clute asked 2 years ago
I'm creating a share folder request form.  I have a text field that needs to have slashes in it for the directory. Ex: \\ServerName\Folder1\Folder2\ Is there any way to be able to do this.  Basically I want the users to be able to copy and paste the UNC path to the directory they need access to without having to do anything extra.  Thanks in Advance, Ryan D.
1 Answers
Chris AdamsChris Adams answered 2 years ago
Hi Ryan, Can you explain a bit more about how you're creating the path for the directory? Are you creating the path dynamically when a user makes a selection in the form or some other method? If you're using the built in field calculations you can set it to be stored as text and add the slashes in to the 'calculation'. For example, if you set the default value for a field to be:
[123]\[124]\[125]\[126]
Then it will be populated with the values of fields 123, 124, 125 & 126 separated by slashes. Hope that helps Chris
Ryan De Clute replied 2 years ago

Not dynamic, literally just copying the folder path and pasting into the field or typing it out. I understand that PHP/HTML strips out the slashes, just trying to see if there is a way to keep them in.
when a user copies \\ServerName\FolderPath it sends the data as \SeverNameFolderPath. If I add \\\\ServerName\\FolderPath that works, but I don't want to have the users remember to add the extra slashes.

Chris AdamsChris Adams replied 2 years ago

Hi Ryan,

Ok i see. There are a couple of ways you can do this but i would probably use the frm_validate_field_entry hook to change all single \ to double \\ when the submit button it clicked and before the value is saved to the DB.

Off the top of my head you'll probably want to use preg_replace or str_replace but it might require a bit of experimenting to find the right method as you'll have a mixture of single and double slashes to replace for most paths.

Ryan De Clute replied 2 years ago

Thanks. I'll see what I can come up with. My PHP is a little rusty, might take me a while.

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