Skip Navigation

[Resolved] Form filtering Post Type in View is displaying but not saving the input data

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by Luo Yang 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#569678
example2.jpg

I am trying to: Hello we are filtering a post type in a view before using a sort code to display the data in a dropdown/select input element, the data is displaying fine, but when the form is submitted the input element recorded but other standard form data is. I have double checked the postmeta for the submitted form to confirm this.

Thank you

Link to a page where the issue can be seen:

View: hidden link

Form: hidden link

Post Type for the Filtered data (Drivers): hidden link

I expected to see:

The form shows the filtered data under the label "New List:" and the same data using the standard method of showing data in a form (but clearly not filtered) under the label (Old List).

Instead, I got:

So "New List" data is not being saved or sent through via email which we want it to do.

#569722

Dear Peter,

Thanks for the details, I can login your website.
But I am not sure where and how I can see the problem you mentioned:
So "New List" data is not being saved or sent through via email which we want it to do.

Could you describe detail steps to produce above problem?

Thanks

#569826

Sorry if it was not clear - have tried to explain the issue -

The Driver post type is a parent of the Booking post type.

Originally we had a Select field on the CRED Add Booking Form (ID:24) that just bought through every Driver Name so a Booking could be assigned to the correct driver. This was achieved with the following Shortcode -

[cred_field field='_wpcf_belongs_driver_id' value='' required="true" class='form-control' output='bootstrap']

This is still on the CRED form labelled as Old List.

We need to filter the list of Driver Names based on whether they are Approved in the new Driver Select field called 'driver-allowed' - so we want the Select to only show Drivers who are marked in the field as Assigned(1) and not display Drivers marked as Suspended(2) or Left(3). We have created a View that filters the Driver Posts called 'Driver Allowed'

The issue is we have put the output of the View into a generic Select field on the Add Booking form so the correct list is displayed (labelled as New List), but the Booking is not writing the chosen value with the Booking Post as a child of the chosen Driver post.

The generic field on the form shows the filtered drivers in the Select dropdown, but does not appear to write the value to the database and the Booking is not registering as a child record of the parent Driver.

<select field='driver-allowed' name="driver-allowed" id="cred_form_24_1-select-1-1505305099" class="form-control wpt-form-select form-select select select js-wpt-validate" output="bootstrap" select_text="HINT: Type first letter of Drivers Christian Name for speed" data-wpt-field-title="driver Parent" data-wpt-type="select" name="select-_wpcf_belongs_driver_id">

  [wpv-view name="driver-allowed" orderby="title" order="asc" cached="off"]

</select>

How can we get the chosen name to correctly save so the Booking is a child of the correct Driver?

#569865

Thanks for the details, I am checking it in your website, will update this thread if there is anything found, but I am on a trip, may answer it later.

#570096

In your case, it needs some PHP codes, for example you can try with CRED action hook "cred_save_data",

When user submit the CRED form, use action hook "cred_save_data", trigger a custom PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
This hook allows doing a custom action when post data is saved to database.

In this PHP function, get the value of your "generic Select field", and save it into database:
https://codex.wordpress.org/Function_Reference/update_post_meta

#570303

Hello, thank you for that I have been able to use the 'cred_save_data' to save this data to the database.

However even though this data is now saved as postmeta along with the rest of the post data to "post_type": booking all data except for this postmeta can be show shown using

[types field='order-number'][/types]

on the website by using a using a template "Toolset > Content Templates > Bookings Display" however

[types field='driver-allowed'][/types]

does not return any data?

hidden link

and

hidden link

So is there a way of making a "Content Template" pull postmeta directly for the post it is displaying ?

There is also a second issue of the information not being able to appear in the email sent on form submit, though solving this is less important.

#570314

It is a new question.

Since you did not point out the problem page URL, where and how can I see the problem:
[types field='driver-allowed'][/types] does not return any data.

So I have to guess what happened in your website, I assume we are talking about this case:
in the single "booking" post, for example:
hidden link

there should be some result just after text:
"Data Should display here:"

If it is, please edit the problem single "booking" post, see here:
hidden link

There isnt' any custom field that is using name "driver-allowed" , "driver allowed" something like this.

So there isn't custom field "driver-allowed" in the single "booking" post, as a result, the shortcode [types field='driver-allowed'][/types] will not output anything in the front-end.

If you are going to display the field value from other post/page, you can specific the "id" attribute of the Types shortcode, for example:
[types field='driver-allowed' id="12345"][/types]

More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/
Attribute "id":
"$parent" | "post-id" | "$custom post name"
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
Displaying Fields of Parent Pages

And please create new thread for the new question, that will help other users to find the answers. thanks

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.