Forums › Forums › Search & Filter Pro › How do I get the form fieldvalues?
- This topic has 10 replies, 2 voices, and was last updated 7 years, 3 months ago by Trevor.
-
Anonymous(Private) September 14, 2017 at 10:18 am #130952
I tried to ask the base of my question(s) in many ways already, but it seems I have to split it up in little parts to get a bit further. I am trying to use the function filter_function_name( $args, $sfid ) to do something with the fields I use in the form. The fields in the form connect with ACF fields to do the search. But I just want to access the value I instered in the frontend in the form. How do I do that?
Thanks,
Peter
Anonymous(Private) September 14, 2017 at 6:46 pm #131101Do you want me to search everything???? I just ask for one general example to be able to get the values of search fields and use them. Already looking so much everwhere in the forum. But I don’t get it, not so experienced in PHP, so please show me how to get it done.
Anonymous(Private) September 15, 2017 at 6:32 am #131178Hi Trevor,
As I explained I have tow fields in a search form. I just want to accees those two fields and make a calculation and us the outcome in a third field.
The first is the ‘width’ of something and the second field is the ‘height’ of something. I need to calculate height x width, so I want to pupulate the third field with that value.
Peter
Trevor(Private) September 15, 2017 at 8:41 am #131197The first thing then is to find what the array (data) looks like after you submit a search (with values in those two fields). Into whichever results template you are using, I need you to add this PHP code (before the loop runs), and it will print out the array of data to your screen, which you can then post back here within code ticks (the backwards quote mark that is on the key normally to the left of the main keyboard ‘1’ key, one before the code and one after it):
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(12345)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>
Where I have used
12345
, you need to replace that for the ID of your form.Anonymous(Private) September 15, 2017 at 9:30 am #131208I still think it’s me who is making the strange question 😉
I hope I will give this one a last try before I have to give up, since I cannot help my customer a step further.I will give you a step by step list of what I have done and want to have:
1. I just have a front end search form in which the customer uses two fields to insert the ‘height’ and the ‘width’ of something
2. I also wnat to use S&F to search/filter on a third field (which does not need to be filled in by the customer, since that field should be the calculation of height x width. It is kind of unlogical to let the user fill in the calculated value of something so simple. Right?
3. So I don’t need to see all the fields on the screen, I just need to get access to the two fields I mentioned. I found the names of them: _sfm_breedte (width) and _sfm_hoogte (height)
4. I thought I could use the ‘Edit Query Arguments’ routine, and use it for the ID of my S&F serach (in my case 3954). I thought I could get the field values in that routine and make the needed calculation of the third field value there.
5. Yes and that field might be made invisible in the front end, since the user does not need to see it. So you in ACF Pro I use the three fields, but only two shown in the search form. Ik hope that makes the appraoch for my request more clear.
Questions:
1. Is the routine I want to use the right one?
2. So, how do I access and get the values of the two defined fields? I don’t need to dispaly them, just use them to make a calculationExample of non-PHP code in written words:
function filter_function_name( $query_args, $sfid ) {
//if search form ID = xxxx, the do something with this query
if($sfid==xxxx)
{
get me the value of ‘height’}
return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 ); -
AuthorPosts