Jump to content

link on range field and find pages


bwakad
 Share

Recommended Posts

Somehow, I don't think it is possible to make a link from the field rangeslider value and then get the list of pages back... don't know exactly how to do this:

<a href=' $pages->find ( " range.min >= $page->range->min" ) ' > $page->range->min </a>

The above code displays the array in the link (when hovering). I can click it, but it does nothing...

So, lets say, on the current page the link (range.min is 30), then I want to click on that 30 and do a search for pages which have this value in that field to. Basically the link has to do this part: $pages->find ( " range.min >= $page->range->min" )

Now, in my search form I have this code, and is working fine. I just select the value and get to the search page:

<select id='search_hours' name='hours'>
        <option value=''>Any</option><?php
        // generate a range of hours, checking our whitelist to see if any are already selected
        foreach(array('0-10', '10-20', '20-30', '30-40', '40') as $range) {
            $selected = $range == $input->whitelist->hours ? " selected='selected'" : '';
            echo "<option$selected value='$range'>$range hrs</option>";
        }
        ?>

    </select>

Does anyone have tips to get me started how to do the same for a link?

Link to comment
Share on other sites

hmm... I really need to think about this. Normally, with any link in front-end I have: $page->fieldname->url. which actually is a page. From there in the template used for that page I have my function to select and output what I need. In this case "range slider", it's just a value.

So my best bet is to make a parent page - range, and two child pages - min and max. Then use the template which will hold my function to do my things. At least that way, I could use the $page->fieldname->url as a link.

Link to comment
Share on other sites

ok, I use range slider for min and max values. Then those are displayed on front-end.

I would like those values to be as a link, so when I click on the 'min'-value, it will do a search for all pages that have this 'min'-value.

example $pages->find("min-value >= $page->min-value")

Link to comment
Share on other sites

just a step closer. My link in displayed items is now:

<a href="<?php echo $config->urls->root; ?>/uren/min/"><?php echo $child->uren->min;?></a>

Where the page 'min' uses my browse template file.

My browse template file holds this code:

case '1192': // id of page min
   $selector = "template=child-template, uren.min>{$page->uren->min}";
break;
$selects = $pages->find($selector);

And includes my .inc file which then displays the foreach $selects etc.

But somehow, I get back all items (below, equal, and above the value) from the selector...

Link to comment
Share on other sites

Solved it by (again!) study php on lynda.com... I simply had to send the value through url (I think because the value is not a page)...

My pages can all be browsed by the browse.php template.

This template has only one function echoed out.

That function determines what the page id is, then create the selector, then include the browse.inc for layout.

In short, all my displayed field values are links to search the way which I control by the function.

Displayed link on browse.inc is this code (sorry if its not clearly readable):

// store value in variable
$min = $child->uren->min; 
//in the link I send the value through url with ?min=xxxxx
<a href="<?php echo $config->urls->root; ?>/uren/range/?min=<?php echo $min;?>"><?php echo $child->uren->min;?></a>

In my function I use this

case '1192': // id of current page
       $min = $_GET['min'];
       $selector = "template=child-template, uren.min>={$min}, sort=uren";
break;

// later on I use
$selects = $pages->find($selector);

// then include file for display again
include("browse.inc");

Great to study php!

Link to comment
Share on other sites



$min = $_GET['min'];

$selector = "template=child-template, uren.min>={$min}, sort=uren";



 

There's a security problem here. You are placing an unsanitized variable into a selector. Think of that like SQL query injection, even if it's not quite that dangerous. But you want to avoid any instances where user input could start expanding your selector string. So always sanitize user input before using it. In this case, if you know that $min is always going to be an integer or a float, then make it an integer or a float: 



$min = (int) $input->get->min; // if integer
$min = (float) $input->get->min; // if float


If you are dealing with some type of string, then at minimum sanitize with $sanitizer->selectorValue(): 



$value = $sanitizer->selectorValue($input->get->value); 


Do all of this sanitization before placement in a selector. Lastly, it doesn't matter whether you use $_GET or $input->get (or $_POST or $input->post), but I prefer to use $input->get or $input->post because they remove the issue of PHP's magic quotes setting, which may cause unexpected slashes to appear in your input, depending on the server settings. 
Link to comment
Share on other sites

Thanks for explenation!

But to be clear, the $input->get is not explicitly set for input fields? I thought is was because of the word 'input' and in the API it is explained under inputfields.

Then, I need to do the same for links sending through url?

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...