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

21 April, 2019 00: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?
21 April, 2019 01:18:00
E2Pdf
Support
Topics: 7
Messages: 3163
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!
21 April, 2019 01: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.
21 April, 2019 01:49:12
E2Pdf
Support
Topics: 7
Messages: 3163
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!
21 April, 2019 01:50:54
cwliew
Topics: 9
Messages: 32
Dropdown. Which I guess is select.
21 April, 2019 02:21:14
E2Pdf
Support
Topics: 7
Messages: 3163
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!
21 April, 2019 03: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.
21 April, 2019 03:22:15
E2Pdf
Support
Topics: 7
Messages: 3163
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!
22 April, 2019 03: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.
22 April, 2019 03:22:22
E2Pdf
Support
Topics: 7
Messages: 3163
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!
22 April, 2019 03:23:27
cwliew
Topics: 9
Messages: 32
That's great. THANKS!
22 April, 2019 03: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
3 July, 2019 05:02:50
E2Pdf
Support
Topics: 7
Messages: 3163
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!
3 July, 2019 05: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?
3 July, 2019 05:53:27
E2Pdf
Support
Topics: 7
Messages: 3163
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!