Echoing search criteria won't work when searching miltiple fields

8 posts by 2 authors in: Forums > CMS Builder
Last Post: September 13, 2022   (RSS)

By daniel - September 8, 2022

Hey Jerry,

In the $_REQUEST variables, try replacing "genre, genre_2, genre_3_match[]" with "genre, genre_2, genre_3_match". In a select/input name, the [] indicates that the field will be returned as an array, but it's not part of the name used by $_REQUEST. (You can similarly see how the Genre 1 select field has name="genre_match[]", but uses $_REQUEST['genre_match'])

For that reason, though, this line will not work, even if you remove the []:

<?php if (@$_REQUEST['genre, genre_2, genre_3_match[]']) { $searchCriteria30 .= "and with a <b>Book Search</b> including: {$_REQUEST['genre, genre_2, genre_3_match[]']}"; } ?>

$_REQUEST['genre, genre_2, genre_3_match'] will contain an array of record numbers, not the actual genre names. I think you'll want to use $booksearchCriteria instead since there's a loop earlier that populates this with the genre names.

Let me know if that helps, or if you have any other questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 9, 2022 - edited: September 9, 2022

Hey Daniel,

Thanks for getting back to me so quickly.

So I if I understood correctly, I changed

This

<?php if (@$_REQUEST['genre, genre_2, genre_3_match[]']) { $searchCriteria30 .= "and with a <b>Book Search</b> including: {$_REQUEST['genre, genre_2, genre_3_match[]']}"; } ?>
<?php if ( @!$searchCriteria30 ==''):?>
<?php echo @$searchCriteria30 ?>
<?php endif?>

To this

<?php if (@$_REQUEST['genre, genre_2, genre_3_match[]']) { $searchCriteria30 .= "and with a <b>Book Search</b> including: {$booksearchCriteria}"; } ?>
<?php // if ( @!$searchCriteria30 ==''):?>
<?php echo @$booksearchCriteria ?>

<?php echo $_REQUEST['genre, genre_2, genre_3_match[]'] // just to be sure ?>

<?php echo @$searchCriteria30 // just to be sure ?>
<?php // endif?>

But no luck.

If I put <?php echo $_REQUEST['genre, genre_2, genre_3_match[]'] // just to be sure ?> into the mix on line 569 of the attached search18.php I get a an Undefined index: genre, genre_2, genre_3_match[] error

Based on the working code example for genre 1 in my original post I thought that this code did the conversion to name values from num values (but that's just a guess):

/ Start Book Type Search
@$booksearchCriteria = ""; // set default value
if ((@$_REQUEST['save'] == 1) && @$_REQUEST['genre, genre_2, genre_3_match[]']) {
@$booksearchCriteria = "<b>Admin Book Search 1: </b>"; // set default value
// cycle through each genre selected
foreach ($_REQUEST['genre, genre_2, genre_3_match[]'] as $genre_3) {

// lookup genre number in database
$genreRecord = mysql_get("genre_categories", $genre_3);

if ($genreRecord) {
// add "genre" value to output
@$booksearchCriteria .= $genreRecord['genre_names'] .", ";
}
}
}
// End Book Type Search

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

search18.php 56K

By daniel - September 9, 2022

Hey Jerry,

Sorry if I was unclear, in addition to using $booksearchCriteria, you also need to change this:

$_REQUEST['genre, genre_2, genre_3_match[]']

To this:

$_REQUEST['genre, genre_2, genre_3_match']

anywhere that it occurs. You'll notice that none of your working examples include the "[]" at the end of the request key.

Also, just for robustness's sake, I'd recommend using this:

<?php if (@$booksearchCriteria) { $searchCriteria30 .= "and with a <b>Book Search</b> including: {$booksearchCriteria}"; } ?>

This way it will work even if you change how $booksearchCriteria is populated.

Let me know if that works!

Thanks,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 9, 2022 - edited: September 9, 2022

Hi Daniel,

I tried your suggestion, but when I remove the [] (as in http://popupdude.com/search19.php) the search results do not return the records for a multi value search, so, for example, when I search for both animals and Advertising Popups, the results returned are only for animals.  This multi value search works in http://popupdude.com/search18.php with the [] left in the code.

http://popupdude.com/search.php is the live search page with the complete code

I wonder if you could take a deeper look at this issue for me.

Thanks,

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

search19.php 56K

search18.php 56K

search.php 55K

By daniel - September 9, 2022

Hey Jerry,

In search19.php you also removed the [] from the "name" property of the <select> elements - it should remain here, as it is in the working examples. It only needs to be removed from the $_REQUEST keys.

Here are some resources to better understand the purpose/usage of the [] in form input names, multiple-selects in particular:

If this still doesn't work, go ahead and send a support request (https://www.interactivetools.com/support/request/) and I can have a look into it.

Thanks,

Daniel
Technical Lead
interactivetools.com

Just to follow up in case anyone comes across a similar issue - the remaining issue was that there were spaces in the input name "genre, genre_2, genre_3_match" which get converted to underscores after submit: "genre,_genre_2,_genre_3_match". Removing the spaces seems to have solved the issue.

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 13, 2022 - edited: September 14, 2022

Thank you Daniel,

I really appreciate that you are there for us and that you're so good at this.

The working page is attached.

Hope it helps someone.

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

search.php 53K