Show the last few letters of a chosen selection in the mapped field

Released
April 21, 2019 07:19:26
cwliew
Topics: 9
Messages: 32
In formidable, I have a list of options that the user can select. They are addresses, with various character lengths. They all end with the post code, which is a 4 digit number.
On the end PDF, I want to ONLY show the 4 digit number. Is there a way to show ONLY the last 4 letters of a particular field in the mapped field in the end PDF?
April 21, 2019 08:18:00
E2Pdf
Topics: 7
Messages: 3615
Support
Hi,

It's depending on the number and format of "options" that user can select. If it's not a lot of options it's possible to accomplish with "Actions" and "Conditions" by changing "Value" depending on user choice.

Another solution can be to use [e2pdf-format-output] shortcode but it can work only if the nubmer of spaces and format of each options is the same.

If it's possible you can share a screenshot of "Formidable Form" list which is available for select by user so we can find best solution for you.

We remain at your service.

We would really appreciate your feedback at WordPress.org!
April 21, 2019 08:39:10
cwliew
Topics: 9
Messages: 32
Here is the list - it is quite long, and this option is in a repeater based on conditions set before it.
April 21, 2019 08:49:12
E2Pdf
Topics: 7
Messages: 3615
Support
Which field type are you using inside Formidable form? "Select", "Radio" or "Checkbox"?

We remain at your service.

We would really appreciate your feedback at WordPress.org!
April 21, 2019 08:50:54
cwliew
Topics: 9
Messages: 32
Dropdown. Which I guess is select.
April 21, 2019 09:21:14
E2Pdf
Topics: 7
Messages: 3615
Support
There is 2 possible solutions to solve it.

1) Convert Formidable Dropdown to "Use separate values". Set the "Saved value" as needed number and "Label" your current value. Inside Template use:
[575] to output label
[575 show="value"] - to output value.

* If it's inside repeatable section, shorcode will be [575:1] and [575:1 show="value"]

Screenshots attached.

2) To use "output" filter for value and field:
Code can be added to your theme "functions.php":

add_filter('e2pdf_extension_render_shortcodes_value', 'custom_extension_render_shortcodes_value', 10, 5);
function custom_extension_render_shortcodes_value($value, $element_id, $template_id, $item, $dataset) {
if ($element_id && $element_id == '6' && $template_id && $template_id == '160') {
if ($value) {
$data = explode(',', $value);
if (is_array($data)) {
$value = trim(array_pop($data));
}
}
}
return $value;
}


6 - "E2Pdf" Element ID. You can get it by "Right" mouse click on needed field inside "E2Pdf" Template and copy "ID" value.
160 - is the "E2Pdf" Template ID

Current code will get submitted value, explode it by commas and will replace "Value" with last element of exploded "Value".

We remain at your service.

We would really appreciate your feedback at WordPress.org!
April 21, 2019 10:05:11
cwliew
Topics: 9
Messages: 32
Interesting - so with option 1, I change the dropdown to separate values. But the issue with this is that some of the values have the same last 4 digits. This is not allowed in separate values.
April 21, 2019 10:22:15
E2Pdf
Topics: 7
Messages: 3615
Support
Sorry, didn't notice same values. Yes, you are right.

Value must be unique but in this case you can make them "unique" like 4120a and use "Actions" and "Conditions" to change "Value" on the fly. If [567 show="value"] = 4120a then change value to 4120. But it will be good only if there are not a lot of same values as it will be hard to manage.

Another solution will be to use point 2 as solution.

We remain at your service.

We would really appreciate your feedback at WordPress.org!
April 22, 2019 10:11:30
cwliew
Topics: 9
Messages: 32
OK, so without having to change the functions.php file, here is another thought. Is there a way to display the field aligned to the right, and then reduce the size of the box to show only the last 4 digits? That way, although all the data is there, it is only displaying the last 4 digits in the output PDF.
April 22, 2019 10:22:22
E2Pdf
Topics: 7
Messages: 3615
Support
We already added to our roadmap task to extend functionality of [e2pdf-format-output] shortcode to have possibility to complete your task as it can be useful for other users. So as soon as we add this functionality we will update this thread.

As about align text to right and map field - can be as temporary solution. "Text align" option is available under "Properties" of element. In that case it will be need to use "Input" field (Not HTML).

We remain at your service.

We would really appreciate your feedback at WordPress.org!
April 22, 2019 10:23:27
cwliew
Topics: 9
Messages: 32
That's great. THANKS!
April 22, 2019 10:52:59
cwliew
Topics: 9
Messages: 32
I just did some testing. If you want to show the last 4 digits, the easiest way to do it is to map the field, align to the RIGHT, and then close down the box until you isolate the size of the last 4 digits only. Works great
July 03, 2019 12:02:50
E2Pdf
Topics: 7
Messages: 3615
Support
Hi,

We just released update (1.08.00) which support now custom "Preg Replace" function which can help to split and output needed data depending on "Pattern". Example of usage is attached on screenshot.

We remain at your service.


We would really appreciate your feedback at WordPress.org!
July 03, 2019 12:45:14
cwliew
Topics: 9
Messages: 32
Interesting - how does it work. Does it replace the entire pattern with whatever is in the replacement field? Is there a guide on its use somewhere?
July 03, 2019 12:53:27
E2Pdf
Topics: 7
Messages: 3615
Support
You can read some documentation here: https://www.php.net/manual/en/function.preg-replace.php

From the page:
preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) : mixed

$pattern - is the "Pattern" field
$replacement - is "Replacement" field
$subject - is "Rendered" value.

In simple words function searches $subject for matches to $pattern and replaces them with $replacement. As an advice for testing you can try using this website: https://regex101.com/.

P.S. Regex can be a bit complex to understand but in same time it's really flexible. Regex below will output last digits from rendered value if it ends with number.

pattern: /.*\s(\d+)$/
replace: ${1}

We remain at your service.

We would really appreciate your feedback at WordPress.org!
Get News and Updates
Our monthly newsletter keeps you in the loop, so you'll always be up to date with the latest news and updates about E2Pdf.
* You can update your email subscription preferences here.
All trademarks, service marks, trade names, product names, and logos appearing on this website are the property of their respective owners. The use of trademarks such as Formidable Forms®, Forminator Forms®, Gravity Forms®, JetFormBuilder®, WordPress®, WooCommerce®, WPForms® and others is solely for identification purposes (nominative use) and does not imply any affiliation, sponsorship, or endorsement by the respective trademark holders.
© 2017 - 2026, https://e2pdf.com

We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. By clicking "Accept Selected", you consent to use of selected cookies according to our Cookie Policy.