Field formatting and fields not saving
-
Hi Doeke, we are using your plugin to save order data and have run across some issues, hope you can help.
Is it possible to name the field columns by admin field label, not the field label the customer sees?
Is it possible to separate address fields, I have “Split multi-fields” checked but the address column includes street, town, postcode etc are all saved to one column
Another question, sorry. Is it possible to remove number formatting from columns? eg the price field is saving with price formatting, we just need a number
Also some other custom fields (eg credit card and card type) do not save to the CSV but are in the website.
Thanks in advance.
-
Hi @bridieamelia,
Thanks for the questions. No need to apologise; that’s what we’re here for.
A quick response now; I will throw some code at you later. Got to work ??.
Also please provide all the versions of plugins and php as stated in the sticky topic.
1. Yes it is possible to change the labels. A small function in functions.php can hook into a filter for that.
2. That’s really odd. It almost sounds like you have a function that disables this. Check out the FAQ. There is a code sample to disable this. Maybe you have this turned on? Does the name field split into multiple columns?
3. Yes. There is some info about this in the FAQ. If you need an example I’ll provide it later.
4. I’ll look into this. This should export. If it’s a bug I’ll try to resolve it by the next release. That is coming somewhere this week, if I can find the time.
I’ll let you know as soon as I can.
Thanks Doeke, you are too kind! (actually you are just the right amount kind )
I will check the FAQs, I am a little familiar with writing functions so hopefully will be fine with 1 and 3.
Will check 2 again and maybe try disabling some plugins to see if there is a clash.
4 looks solvable but would love some assistance with writing a “field-renderer”.
Hi @bridieamelia,
As promised some code for you. You can add all of these to your
functions.php
file.1.
$transformer = new GFExcel\Transformer\Transformer(); add_filter('gfexcel_field_label', function ($value, GF_Field $field) use ($transformer) { $gfield = $transformer->transform($field); if (!$gfield instanceof GFExcel\Field\SeparableField && !empty($field->adminLabel)) { return $field->adminLabel; } return $value; }, 10, 2);
This was WAY harder than I thought, or than it should be. So I will make this easier in the future.
2. I still think this works as intended. I’m pretty sure you are overwriting the setting somwhere in the
functions.php
.3. I actually need some more information about this. Wat sort of field are talking about?
Because the “total” field actually only returns a number. Also, every price value is saved as the value you get.
So if you change the currency later on, it still saved the correct way, but with the new currency.
Also, the decimal, en thousands charactar change per country. SO in order to fix this for you I need to know:
– What field(s), please name them individually.
– What is the currency?
– What is the decimal and thousands character? Please name both.4. Oh, this is fixed in the next release. But for now you just need to add this field as a SeparableField.
add_filter('gfexcel_transformer_fields', function ($fields) { if (!array_key_exists('creditcard', $fields)) { $fields['creditcard'] = 'GFExcel\Field\SeparableField'; } return $fields; });
This will be automatically fixed in 1.6.0. And it will do no harm if this code stays in your
functions.php
.
But when you upgrade you can remove this code.- This reply was modified 5 years, 11 months ago by Doeke Norg. Reason: formatting
- This reply was modified 5 years, 11 months ago by Doeke Norg.
Thanks Doeke! The first and fourth worked nicely.
I am still having trouble with #2, separating the address. I have deactivated and tried redownloading the CSVs but the problem remains.
I could send you some system info if you think you could help. It doesn’t seem like major plugins like Yoast and Wordfence would play a role.
As for the currency issue, I get your meaning.
We are using AUD$, a . for the decimal and a comma , for the thousands mark.
We have two main forms, one is a simple amount with a field called “your-donation”
The other is more complex, it is a dropdown with multiple options called “buy-tickets”
The format for Buy Tickets is 3 tickets for $15 ($ 15.00) (we just need the final 15)
I think the number issue is going to use something like this:
$number = GFCommon::to_number( $value, '' );
Hi Bridie,
Thanks for the
$number
code! That will come in handy ??On issue #2, does the creditcard field now contain 1 field, or 2? Because if that is split into 2 fields than the toggle on the settings page works. if it’s only one, then the toggle isn’t saved correctly, and you can try to re-save the general settings page.
Otherwise try to add a
add_filter('gfexcel_field_separated','__return_true');
to yourfunctions.php
.I’ll get back to you on the prices thing. Thanks for all that info you provided. This will help a lot!
Hi Bridie,
for #3, something like this should help:
add_filter('gfexcel_field_value', function ($value, $entry, GF_Field $field) { if (!GFCommon::is_pricing_field($field->type)) { return $value; } return GFCommon::to_number($value, rgar($entry, 'currency')); }, 10, 3);
Please note that a dropdown also used to show the label of the selected option. It now only shows the price! Hope thats ok!
Thanks Doeke, the number code work for plain price fields but not for dropdown select price fields.
For example, for the entry “3 tickets for $15 ($ 15.00)”
I get 31515.
No luck on the address thing ?? will keep searching for a clash.
So, I deactivated literally all of my plugins except GF and yours, and also resaved the settings, and also submitted another form, but the address still does not separate.
PS not sure what you mean about the credit card field – the type is in another column if that’s what you mean.
Not that I think any of these would be an issue, but in addition to code you’ve given me, this is the only code in my functions file.
//Page Slug Body Class function add_slug_body_class( $classes ) { global $post; if ( isset( $post ) ) { $classes[] = $post->post_type . '-' . $post->post_name; } return $classes; } add_filter( 'body_class', 'add_slug_body_class' ); // Do not append GF forms URLS with anchor */ add_filter( 'gform_confirmation_anchor', '__return_false' );
Not sure that helps?
With the number issue, I have found one thing that may help: if I select the checkbox “show values” in the dropdown product within form edit tab, and give the ticket options some values (the actual price, 15, in number only for example), my output in the CSV export is now 1515 instead of 31515.
But it is still picking up the price also…is this also a separable field issue?
Can you send me an export of your form via the Gravity forms export tab? That’s a file in JSON format. I can import that file to have the exact same forms (including the settings). You can send it to [email protected].
Here is a fix for the dropdown field:
add_filter('gfexcel_field_value', function ($value, $entry, GF_Field $field) { if (!GFCommon::is_pricing_field($field->type)) { return $value; } if ($field instanceof GF_Field_Select) { $value = $field->get_value_export($entry, $field->id, false, true); $value = $field->get_value_merge_tag($value, $field->id, $entry, [], 'price', $value, true, true, 'text', true); } return GFCommon::to_number($value, rgar($entry, 'currency')); }, 10, 3);
PS, I’m asking for the form itself. Not the data. I want to reproduce the form so I can check on the address field.
- This reply was modified 5 years, 11 months ago by Doeke Norg.
Doeke, I have solved the price dropdown number format issue!
Will leave here, maybe it will help you or someone else.
So, I have used this snippet from Spivurno on github which maps field values to other fields:
https://gist.github.com/spivurno/7029518
And then, using giving a value to each price dropdown option (in my case number of tickets bought), and can then assign to two hidden fields:
1. {field-id:price}
2. {field-id:value}This saves the separate number values into two more columns, thus leaving clean data for my client to use in the CSV export.
Thanks again for all your help!
PS, I also used the code above as part of that solution ??
Awesome. Great job! Enjoy the plugin. And if you need any help in the it the future, don’t hesitate!
Cheers.
- The topic ‘Field formatting and fields not saving’ is closed to new replies.