davo Posted September 30, 2014 Posted September 30, 2014 I've used form builder to create a form but but this isn't really a form builder question as I'm processing my own form. I've created a form that submits a multi value field back to itself called specialise[]. How can I then use that array to filter a multi page field array and return only pages that have any of the specialise[] values? A dmc page may have many specialise values by page select type. The specialise[] array in the get input again may have many values. This is my attempt so far but I'm not sure how I'd use $matches =$pages->find("timedifference, flightbit, --here i want to compare the specialise[] array to see if any values are in the specialise array") The field I want to search is DMCstats_Specialise_In which is multiselect page type. <?php /** * Page template * */ include("./dmcheader.inc"); $hours_flight = $input->get->hours_flight; // this comes from the slide $time_difference = $input->get->time_difference; // this comes from the other slider $specialism = $input->get->specialism; // this comes from a form builder using ASM select ?> <div class='container'> <div class='row'> <div class='col-md-6'> <!-- load in the form builder form --> <?php echo $forms->load('advanced_search')->render(); ?> <?php $modules->get('JqueryCore'); // ...or load your own jQuery $config->styles->append($config->urls->root . "wire/templates-admin/styles/inputfields.css"); $config->scripts->append($config->urls->root . "wire/templates-admin/scripts/inputfields.js"); $config->styles->append($config->urls->FormBuilder . 'form-builder.css'); $config->scripts->append($config->urls->FormBuilder . "form-builder.js"); foreach(array('jquery-ui', 'inputfields', 'main') as $file) { $path = $config->paths->FormBuilder . "themes/start/$file"; $url = $config->urls->FormBuilder . "themes/start/$file"; if(is_file("$path.css")) $config->styles->append("$url.css"); if(is_file("$path.js")) $config->scripts->append("$url.js"); } foreach($config->styles as $file) echo "<link rel='stylesheet' type='text/css' href='$file' />"; foreach($config->scripts as $file) echo "<script type='text/javascript' src='$file'></script>"; ?> </div> <div class='col-md-6'> <?php $negative_time = $time_difference - ($time_difference * 2); // time difference uses a signed integer $matches = $pages->find("template=dmc, DMC_Average_Flying_Time_hours<=$hours_flight, DMCstats_GMT<=$time_difference, DMCstats_GMT>=$negative_time"); // im after all pages that are less than or equal to the flight time, less that time difference and greater than the negative time difference $countresult = count($matches); echo "$countresult DMCs matching your search $specialism[1]"; echo "<ul class='list-group'>"; foreach($matches as $match) { echo "<li class='list-group-item'><a href='{$match->url}'>{$match->DMC_country_represented->title} - {$match->title} - $match->DMCstats_GMT time difference | $match->DMC_Average_Flying_Time_hours flying time </a></li> "; } echo "</ul"; ?> </div> </div> </div> </div> <!-- end container --> <?php include("./dmcfooter.inc");
davo Posted October 1, 2014 Author Posted October 1, 2014 Trying to think of this with a clearer head this morning, I think I could do something like this. Open the specialise[] get array and create a selector variable. Then paste that variable into the selector for the pages -> find command. I think it should work, but it's going to feel quite messy. Is this the only/best way? I've not tried it, but it would look a bit like this: $specialise = $input->get(specialse[]); $special_selector = "specialism="; foreach ($specialse as $special_item) { $special_selector = $special_selector . $special_item . "|"; } $special_selector = $special_selector . "," $search_results = $pages->find("$special_selector") just feels messy
davo Posted October 1, 2014 Author Posted October 1, 2014 OK, I think I got there in the end. I think it's still messy but I it does seem to work. For info of anyone that wants to do the same: $hours_flight = $input->get->hours_flight; // this comes from the slide $time_difference = $input->get->time_difference; // this comes from the other slider $specialism = $input->get->specialism; // this comes from a form builder using ASM select if($specialism){ $special_selector = ", DMCstats_Specialise_In="; foreach ($specialism as $special) { $special_selector = $special_selector . $special . "|"; } $special_selector = rtrim($special_selector, "|");}else{ $special_selector = "";} ?> $negative_time = $time_difference - ($time_difference * 2); // time difference uses a signed integer $matches = $pages->find("template=dmc, DMC_Average_Flying_Time_hours<=$hours_flight, DMC_Average_Flying_Time_hours!='', DMCstats_GMT<=$time_difference, DMCstats_GMT>=$negative_time $special_selector"); // im after all pages that are less than or equal to the flight time, less that time difference and greater than the negative time difference which renders me a page like this: http://www.dudmc.com/dmc-hunter/ ...plus there's something wrong with my divs, but that's for another day.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now