Skip Navigation

[Resolved] Use of a Views as a select inside a Forms don't work id additional parameters de

This support ticket is created 3 years, 8 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 17 replies, has 2 voices.

Last updated by Shane 3 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1756415

Pat

Hello,

I'm trying to use a Views as a select inside a form (to populate a generic field).
The Views uses a filter based on a shortcode (anneeu) and I have define a hook to retur the current year as [annee_univers].

If I'm using the Views without additional shortcode parameter, that's working fine. If I add a shortcode parameter, then, the select is no more eworking inside the Forms.
Here is my Views :

	<!-- wpv-loop-start -->
		<wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name="views_woo_price"]€"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name="views_woo_price"]€"}
		</wpv-loop>
	<!-- wpv-loop-end -->

and my generic field inside the form :

[cred_generic_field type='select' field='wpcf-id-du-produit-achete']
{
"required":0,
"persist":1,
"options":[[wpv-view name="backoffice-select-sortie"]]
}
[/cred_generic_field]
</code
Like this, everything is fine. Now if I add the shortcode parameter :
[php]
[cred_generic_field type='select' field='wpcf-id-du-produit-achete']
{
"required":0,
"persist":1,
"options":[[wpv-view name="backoffice-select-sortie"  anneeu="[annee_univers]]]
}
[/cred_generic_field]

Then, the select is no moire working inside the forms.

Is there something I need to know to move forward ?
Regards
Pat

#1756863

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2020-08-25 at 10.32.38 AM.png

Hi Pat,

Thank you for getting in touch.

View isn't really meant to pass data into our plugins like this, however could you ensure that "Disable the wrapping DIV around the View" is checked on your view setting. See Screenshot

If you view is returning the wrapper divs then this setting will disable the wrapping around it.

Please let me know if this helps.
Thanks,
Shane

#1757029

Pat

Hi Shane,

Thanks for the return.
No change when checking or not the div button.

For info, here is the hook I'm using to insert the Views insede a Cred form :

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
 
function prefix_clean_view_output( $out, $id ) {
if (( $id == '5880' ) OR ( $id == '6152' )OR ( $id == '6184' )) 
{ 
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if ( 
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out, $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}

Let me know if you have other idea on this.
Regards
Pat

#1757055

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pat,

With the new checkbox option you actually won't need this custom hook anymore.

Can you send me a link to the form so that I can see what is being generated ?

Thanks,
Shane

#1757171

Pat

Hi Shane,

Unfortunately, this part of the site is not accessible for now.
If I de-active the hook, then the select does not work anymore.
Which new checkbox option are you speaking of?
Regards
Pat

#1758177

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pat,

Without seeing the site and checking what is the output of the view in the HTML code on the frontend I won't be able to provide adequate assistance.

Secondly the checkbox i'm referring to is the one that i've described in the response here.
https://toolset.com/forums/topic/use-of-a-views-as-a-select-inside-a-forms-dont-work-id-additional-parameters-de/#post-1756863

Thanks,
Shane

#1758693

Pat

Hi Shane,

OK understant concerning the checkbox. This means that this checkbox can replace the hook if I'm right!

Now, concerning the use of the Views with a parameter inside a generic field, I need to know if this is something that is feasible or not. So could you ask a Toolset developer if this is possible or just make a test in a blank site on your own?
Regards
Pat

#1759185

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pat,

OK understant concerning the checkbox. This means that this checkbox can replace the hook if I'm right!

Yes that is correct.

Also it is still possible to do this, however looking at your JSON output I see an issue where the output quotations are missmatched.

Try using this one below.

<!-- wpv-loop-start -->
    <wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name='views_woo_price']€"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name='views_woo_price']€"}
    </wpv-loop>
<!-- wpv-loop-end -->

You need to use single quotes when you are wrapping parameters inside double quotes. This ensures that you don't close your double quotes early.

Thanks,
Shane

#1759215

Pat

Hi Shane,

Thanks for the info.
This is not working no more.
Have you been able to validate that this was something feasible (ie : use of shortcode parameter fliter in a views when inserting this views inside a generic field?
I have other filters that are working fine but they are not based on a shortcode !
Regards
Pat

#1759257

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2020-08-27 at 10.57.23 AM.png
Screenshot 2020-08-27 at 10.57.36 AM.png
Screenshot 2020-08-27 at 10.57.48 AM.png

Hi Pat,

Yes I have tested it on my end and it works fine for me, see screenshots .

The fields is generating with the correct value. So I am confirming that it is still possible to use views to provide the data for a generic field.

Have you adjusted your markup like the above ? https://toolset.com/forums/topic/use-of-a-views-as-a-select-inside-a-forms-dont-work-id-additional-parameters-de/#post-1759185

Secondly are you able to quickly set this site up in a live environment where I can investigate or are you able to provide me with a duplicator package of the website ?

You can follow the instructions in the link below in order to provide me with the copy .
https://toolset.com/faq/provide-supporters-copy-site/#creating-a-copy-of-your-site

Please let me know as further debugging is needed to be done here but I will need to see the site itself in order to fully diagnose why this isn't working.

Thanks,
Shane

#1761651

Pat

Hi Shane,

Looking at your screenshot, I'm wondering if I have been sufficiently clear in my description.

What you are displaying is working fine for me. Now, I have added a filter based on a custom field (wpcf-annee-universitaire) and define the Views filter as a shortcode linked ot the anneeu parameter).
I have also another shortcode ([annee_univers]) created with a hook in the Toolset parameters tab, and that returns the current year.

So, what I would like to do is this :

[cred_generic_field type='select' field='wpcf-id-du-produit-achete']
{
"required":0,
"persist":1,
"options":[[wpv-view name="backoffice-select-sortie"  anneeu="[annee_univers]]]
}
[/cred_generic_field]

Doing this returns nothing in the generic field, but if I'm using the Views in a post, I'm getting the right value.
Another test : if I place manually a value in the gebneric field like "options":[ 2020 ], it's also working.

So it seems the issue is related to the use of a shortcode inside a shortcode as a generic field option?
Could you test your generic field with the whole context (filter parameter based on a shortcode) and tell me if this is working for you?

Regards
Pat

#1762573

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pat,

So in the case where you have added the parameter it won't work.

The problem is that the internal shortcode is breaking the markup for the view. You won't be able to use another shortcode within the view to filter the results.

You may need to convert your custom shortcode to a static query filter for your view using our filter hook.
Thanks,
Shane

#1762763

Pat

Hi Shane,

What would be needed in the internal shortcode to comply with the Views rules?
As this shortcode is created thanks to a hook, I should be able to modify it in order to make it compliant?
Regards
Pat

#1762771

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pat,

The view requires a clean output for it to work correctly. It also can be that the nested shortcode breaks the expected format of the generic field.

This is why I suggest filtering your view using the query filter hook below.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

You should be able to translate your custom shortcode to the hook, given that you are using the custom shortcode to filter your view.

Based on the shortcode, what kind of values is it passing to the view ?

Thanks,
Shane

#1767755

Pat

Hi Shane,

Thanks for your porposal. I can use it as a workaround, but this is not solving completely my need. I think being able to use a Views ass select and define some additional parameters thanks to a shortcode is a must and should be integrated inside Toolset as standard.
Let me know if this is something that could be feasible in the near future?

Regards
Pat

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