Fill text spaces with

By: Henry King | Asked: 09/26/2022
ForumsCategory: Code HelpFill text spaces with
Henry King asked 2 years ago
Hi Experts, I've a text field in Formidable Form with following session variable $SESSION['symbol'] that the user enters as "IBM 132". I need to fill build a query string with this '' . $_SESSION['symbol'];   I need to remove the space of add "%20" to the space.   How do I do this?   Thanks.    
1 Answers
Victor Font answered 2 years ago

$__SESSION is a PHP global variable that exists apart from WordPress/Formidable. I don't know what you mean when you say you have a text field with the $SESSION['symbol'] the user enters "IBM 132". You can use $__SESSION variables as default values but you can't assign values to them in a Formidable text field. You can capture a value in a Formidable text field and assign it to $__SESSION['symbol'] with jQuery or PHP after its been captured in a field.

Here's how you would do it in jQuery in the browser before a form submit:

PHP can do this after a form submit by using the frm_pre_create_entry filter where you can construct and sanitize your URL before using it.

Henry King replied 2 years ago


Thanks for your reply. Perhaps I can be clearer.
The user enters "IBM 132" into a Formidable Form text field say $_POST['item_meta'][6] where '6' is the id of the field. I would like to Trim the text so that it reads:

1) IBM132 (without the space) and

2) IBM%20132 (with %20 - representing a space).

Hope this clarifies.


Victor Font replied 2 years ago

You are asking for two completely different formats for a single field. If you remove the spaces like your example 1, there are no spaces to sanitize with %20 as you want in example 2. If you want two different fields, either that or settle on one format or the other for a single field.

That being said, you can either format with jQuery wither with a regular expression or character substitution. Here's an example with regular expressions:

Thist example show how to convert characters to HTML Entities. You can modify this code to convert a space to %20.

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