Jump to content

bwakad

Members
  • Posts

    450
  • Joined

  • Last visited

Everything posted by bwakad

  1. But in sublime you can set whatever you want to certain highlighting - which is also readable. I now use google profile because it's one of the more clear ones. Unless you use php strings...
  2. Never really hear of MODx, except in this forum. But I have been playing with so many php scripts and cms over the last year, and I suddenly came upon Processwire. Sure, in the beginning it's a strange learning curve to dive into. Global naming conventions would be nice when learning some software package, but is really a utopia. It took me around a month to learn about page vs pages, find vs get, and especially the API/cheatsheet and profiles. Thankfully on this forum there are many contributors that reach out and help. Meanwhile I get to learn PHP as well. And yes, of course there are always things you miss or are not clear. But so far, I am building a great website with just basic knowledge of PW which I had never done using any other software. If someone mention about another software, I will read it being curious, but skip using it any way. PW for me is so complete and easy and I doubt if I ever turn to other software. Also a good thing about PW is that it's solid. No errors (unless you make them yourself). Not if you update, use a profile, or a module (so far). There is really only you, building the way you want, making layout how you want. And certainly not a hundred or more coders uploading whatever profile/module the want. There's a great team behind it all.
  3. I have to warn I do not have much knowledge.... but did you try: $pages->find("template=xx,utenti={$myuser}") or perhaps $pages->find("template=xx,utenti=".$myuser)
  4. I did it by isLoggedIn(), which is much easier to read. So in my foreach loop I use this code: foreach($children as $child) { $class = $child === $page->rootParent ? " class='active'" : ''; if ($user->isLoggedIn()) { // is member? if ($child->name == "login") { // skip login page if logged in continue ; } } else { // is guest ! if ($child->name == "profile" OR $child->name == "logout") { // skip profile OR logout page if logged out continue; } } echo "<li $class><a href='{$child->url}'>{$child->title}</a></li>"; } Then I would think I also have to give some kind of statement in top of page, something like direct acces not allowed if one would enter it in the browser url?
  5. I have added a role named TESTER, and a user named TEST. My login(.php) template and page is ready but I want this only visible in menu if viewer is guest. The login - page role says: guest (everyone) - view (and of course superuser) but no tester! The login - template says : guest, tester, and superuser. The checkbox for tester cannot be unchecked...? The access > roles > tester : is (for now) set to view and update password. The access > users > test : is set to guest and tester. I cannot uncheck the guest (is required warning)...? I guess the guest is required by all roles one creates. My question is, do I have to do something in the backend to (based on roles) hide a page from the menu, or is there something wrong with my setup, or is there another way to do this? I hope someone can tell me what to do...
  6. Already found the answer and it seems to work fine - but there are times I never know exactly if this code is good since I only found created_users_id inside the database, and not on the api or cheatsheet...: $selects = $pages->find("template=child-template, created_users_id={$user}, limit=2"); // select only from current logged in user This way, in combination with my login.php I am able to only display items belonging to the current logged in user on the profile page.
  7. Hi all, I have used the code as in Ryan's example but only needed the login. But since it did not work I tried this code for the login which does work. However, taking into account that Ryan is the expert, I really want to know if this code is save to use: // login.php <?php if($user->isLoggedin()) { // user is already logged in, so they don't need to be here $session->redirect("/profile/"); } // check for login before outputting markup if($input->post->user && $input->post->pass) { $user = $sanitizer->username($input->post->user); $pass = $input->post->pass; if($session->login($user, $pass)) { // login successful $session->redirect("/profile/"); } } ?> <?php include("./myinclude/head.inc");?> <form action='./' method='post'> <?php if($input->post->user) echo "<h2 class='error'>Login failed</h2>"; ?> <p><label>User <input type='text' name='user' /></label></p> <p><label>Password <input type='password' name='pass' /></label></p> <p><input type='submit' name='submit' value='Login' /></p> </form> <?php include("./myinclude/foot.inc");?> Then is kept the following for profile page: //profile.php <?php // if user isn't logged in, then we pretend this page doesn't exist if(!$user->isLoggedin()) throw new Wire404Exception(); // need to redirect here if not logged in .............. include("./myinclude/head.inc"); echo "hello ". $user->name; $selects = $pages->find("template=child-template, limit=2"); // can I select here by user ID??? include("./myinclude/browse.inc"); include("./myinclude/foot.inc");?> On the include file I have this code to test the logged in user ID and name - which is working: //browse.inc <?php foreach ($selects as $child) { ?> <?php if($user->isLoggedin()) { if($child->created_users_id === $user->id) echo $child->created_users_id . " " . $user->name; } ?> And what I know need is to display only items OF the logged in user on this profile page - and a way to edit this items on front-end....
  8. well, I copied all code, followed instructions, but the login simply fails. Can't even login as admin from the front. The only thing working is the logout.
  9. thanks, I have seen this topic. However, one respons in this topic is linking to another topic, one part is from ryan's code, while others talk about a module. Which should I use? Sorry, you linked to the specific post from ryan... thanks!
  10. There are many topics about accomplish this, but none of them have a 'best answer' - leaving me with the questions: - is it working as aspected? - do I have to concern about security issues? - Is it a work in progress? - which ones are good examples? I also see a module, but once again, in some topics were concerns about the code written in modules as they should be in the preferred format. This leave me with a feeling not to use it.
  11. Well, after one month I must say, I did learn more of php and PW then any other software. So glad I suddenly see this software mentioned some time ago. I started from the DEV branch. Made my fields and pages. Made 1 template which I use to browse main and sub categories. Made 1 template to browse a single item. I have 2 files - 1 for search-form and 1 for results which I eventually will delete since I want to use it on my browse template. Added foundation css. Did my layout. My pagination is ready on all pages. And everything is working as expected. Next for me is a: adding tooltip markup for google markers (don't know how yet); registration form for front-end submission; front end submission; and registered user page (profile page). Does someone have suggestions for this???
  12. On my search form I wanted to make the selected value return back as what was selected to search. But I'm really having trouble retrieving this value. I'm not sure what I do wrong... My search_form.php (included in head.inc) code is this: <form id="search_form" method="GET" action="<?php echo $config->urls->root?>search/"> <label for='search_provincie'>Provincie <select id='search_provincie' name='provincie'> <option value=''>Any</option> // generate the provincie options, checking the whitelist to see if any are already selected foreach($pages->get("/provincie/")->children() as $provincie) { $selected = $provincie->name == $input->get($provincie) ? " selected='selected' " : ''; echo "<option$selected value='{$provincie->name}'>{$provincie->title}</option>"; } </select> </label> <button type="submit" class="button postfix" id="search_submit">Search</button> </form> and my search.php file is this: $selector = ''; if($input->get->provincie) { // Get the criteria and sanitize them $provincie = $pages->get("/provincie/" . $sanitizer->pageName($input->get->provincie)); if($provincie->id) { $selector .= ", provincie=$provincie"; $input->whitelist('provincie', $provincie->name); } } When I use the following code I retrieve it's chosen value: $value = $input->get('provincie'); echo $value; EDIT --------------------- changed my search form to this dropdown code so now it works as expected: <option value=''>Any</option><?php foreach($pages->get("/provincie/")->children() as $provincie) { // when my page parent is 'provincie' I know the children are select values, // then use (current) $page->name as $provincie->name. if ($page->parent->get("name") === "provincie") { $selected = $provincie->name == $page->name ? " selected='selected' " : ''; // when page parent is not 'provincie' I am on the search page, then use $provincie->name. } else { $selected = $provincie->name == $input->get('provincie') ? " selected='selected' " : ''; } echo "<option$selected value='{$provincie->name}'>{$provincie->title} </option>"; } ?> Next thing is, I have only 1 template file to browse all parents and all children under it, and 1 search file. But since my 1 template file is very dynamic I am thinking of making my search form redirect to this template as well. Unfortunatly, that is not yet working because I get a 'page does not exist' . On a separate search file it is working though.
  13. Well Roope, That was probably the solution to the mysterious comma issue! I now have all results when I do not choose a value, and when I do choose a value I get the desired results - for instance a selector value ", branche=1027, contract=1145". So, now I need to continue to capture the chosen values back into my search form while the current page is changed to search.php where my results are processed. The form is in my head.inc, but the search.php is just a page being send to. On a normal page I could go for if ($page->parent...etc. on the search.php this is not possible.
  14. Yes, I did understand that. Here is the code I changed earlier to what you said: if($input->get->branche) { // Get the criteria and sanitize them $branche = $pages->get("/branche/" . $sanitizer->pageName($input->get->branche)); if($branche->id) { $selector .= ", branche=$branche";//CHANGE YOUR SELECTOR AS SHOWN HERE $input->whitelist('branche', $branche->name); } } if($input->get->contract) { // Get the criteria and sanitize them $contract = $pages->get("/contract/" . $sanitizer->pageName($input->get->contract)); if($contract->id) { $selector .= ", contract=$contract";//CHANGE YOUR SELECTOR AS SHOWN HERE $input->whitelist('contract', $contract->name); } } // Search pages $selects = $pages->find( "template=child-template, $selector" ) ; foreach ($selects as $child) { echo $selector; // added this to see the value given Then, I changed the last line (removed the comma before $selector) but that gave zero results, and no selector value. Putting it back: Leaving the code (with comma) and NOT choosing anything on the search form - clicking search, I get back all items and no selector value. Leaving the code (with comma), branche and contract on the search form - clicking search, I get back all items asked, and a selector value ", branche=1027, contract=1145". One addition: my url looks like this: /host/search/?provincie=&branche=accountancy&contract= So could that be the issue?
  15. This works: $selects = $pages->find( "template=child-template, $selector" ) ; This is blanco: $selects = $pages->find( "template=child-template $selector" ) ; Maybe because initially you would need a comma between the first part (template) en second part (field). Strange thing is.... When I choose a value on search form: In the first which works - I would think I have two comma's - but get results. Second part which does not work - make me believe I have a single comma - but no results. ps. when no value is chosen, the $selector is not applied because: if($input->get->branche) {
  16. Thanks Pete, did what you said (except the last part): $selects = $pages->find( "template=child-template, $selector" ) ); I had to use the comma there because initially the selector is empty : $selector = ''; For my search-form.php I also had to change my code - to capture the name, rootParent was actually not good - so I use this code to send to the search.php (although I had in mind to avoid all the if{} statements for every <option> I do not see another way: <?php $value = $page->parent->get("name") ; if ($value === "branche") { ?> <option value='<?php echo $page->name;?>'><?php echo $page->name;?></option> <?php } else { ?> <option value=''>Any</option> <?php } ?> But then of course, this only works once. I can't use this code twice because after sending the form, my $page has changed to search.php and $page->parent is website root.
  17. Hi, The solution posted earlier by Macrura was a bit to complicated for my needs, to much fields and variables, did not see instructions. It might have worked though. I have tried the suggested solutions given by soma and pete, but the second field was either giving me a error 500 or nothing at all. I then tried it like this and it's working when I merge the fields into 1 variable $selector - have to do some more tests though - : --- SEARCH.PHP ---- $selector = ''; if($input->get->branche) { // Get the criteria and sanitize them $branche = $pages->get("/branche/" . $sanitizer->pageName($input->get->branche)); if($branche->id) { $selector .= "branche=$branche, ";//CHANGE YOUR SELECTOR AS SHOWN HERE $input->whitelist('branche', $branche->name); } } if($input->get->contract) { // Get the criteria and sanitize them $contract = $pages->get("/contract/" . $sanitizer->pageName($input->get->contract)); if($contract->id) { $selector .= "contract=$contract, ";//CHANGE YOUR SELECTOR AS SHOWN HERE $input->whitelist('contract', $contract->name); } } // Search pages $selects = new PageArray(); $selects->import( $pages->find( "template=child-template, $selector" ) ); Continued --------------- Now, since i could not catch the current page in my selector easy, I thought, let me turn it around and just provide the value from this current page. So I came up with this solution: ------ SEARCH-FORM.PHP ------- if ($page != $page->rootParent){ $value = $page->rootParent->name; $parents = array("provincie", "contract"); if (in_array($value, $parents)) { $value = $page->name; $option = ''; } } else { $value = ''; $option = 'Any'; } So for example, if my current page rootParent is 'provincie', it will take the child page name as value. And inside my form at <option> I use this: <option value='<?php echo $value;?>'><?php echo $value;?><?php echo $option;?></option> The only problem is, the value get filled in on all <option>'s of the form....
  18. I have this code which is for filtering/searching items: if (count($input->get)) { // Get the criteria and sanitize them $branche = $sanitizer->selectorValue($input->get->branche); $contract = $sanitizer->selectorValue($input->get->contract); // Search pages $selects = $pages->find("template=child-template, branche=$branche,contract=$contract"); } The problem is, it represents AND as in branche AND contract. In the API I see a pipe symbol is for OR, but this obviously is not working: $selects = $pages->find("template=child-template, branche=$branche|contract=$contract"); I need it to be some, all, or no fields. Is that possible? the search form has code like this: <div> <label for='search_branche'>Branche <select id='search_branche' name='branche'> <option value=''>Any</option> <?php // generate the Branche options, checking the whitelist to see if any are already selected foreach($pages->get("/branche/")->children() as $branche) { $selected = $branche->name == $input->whitelist->branche ? " selected='selected' " : ''; echo "<option$selected value='{$branche->name}'>{$branche->title}</option>"; } ?> </select> </label> </div>
  19. Thanks! In between our posts I was also able to find some other example but will certainly give yours a try.
  20. So, I added one piece of code from 'branche', but the only part getting accepted is from the original keywords input box. Again, how can one expand/modify if there are non examples? This is the search form in head.inc: <form id="search_form" action="<?php echo $config->urls->root?>search/" method="get"> <div class="row collapse"> <div class="small-9 columns"> <input type="text" placeholder="Keywords" name="q" id="search_query" value="<?php echo htmlentities($input->whitelist('q'), ENT_QUOTES, 'UTF-8'); ?>" /> </div> <div class="small-3 columns"> <button type="submit" class="button postfix" id="search_submit">Search</button> </div> </div> <div> <label for='search_branche'>Branche</label> <select id='search_branche' name='branche'> <option value=''>Any</option><?php // generate the Branche options, checking the whitelist to see if any are already selected foreach($pages->get("/branche/")->children() as $branche) { $selected = $branche->name == $input->whitelist->branche ? " selected='selected' " : ''; echo "<option$selected value='{$branche->name}'>{$branche->title}</option>"; } ?> </select> </div> </form> This is the search.php: $out = ''; // if a branche is specified, then we limit the results to having that branche (branches field in those pages) if($input->get->branche) { $branche = $pages->get("/branches/" . $sanitizer->pageName($input->get->branche)); if($branche->id) { $selector .= "branches=$branche, ";//CHANGE YOUR SELECTOR AS SHOWN HERE $summary["branche"] = $branche->title; $input->whitelist('branche', $branche->name); } } if($q = $sanitizer->selectorValue($input->get->q)) { // Send our sanitized query 'q' variable to the whitelist where it will be // picked up and echoed in the search box by the head.inc file. $input->whitelist('q', $q); // Search the title, body and sidebar fields for our query text. // Limit the results to 50 pages. // Exclude results that use the 'admin' template. $matches = $pages->find("title|body|sidebar~=$q, limit=50"); $count = count($matches); if($count) { $out .= "<h2>Found $count pages matching your query:</h2>" . "<ul class='nav'>"; foreach($matches as $m) { $out .= "<li><p><a href='{$m->url}'>{$m->title}</a><br />{$m->summary}</p></li>"; } $out .= "</ul>"; } else { $out .= "<h2>Sorry, no results were found.</h2>"; } } else { $out .= "<h2>This is from my search.php page</h2>"; } // Note that we stored our output in $out before printing it because we wanted to execute // the search before including the header template. This is because the header template // displays the current search query in the search box (via the $input->whitelist) and // we wanted to make sure we had that setup before including the header template. include("./myinclude/head.inc"); echo $out; include("./myinclude/foot.inc");
  21. Does anyone have an example of how to complete a search form??? I took some part from the skyscrapers for the form, and it's populating the fields good. But the whole idea behind skyscrapers is a bit to complicated with the functions and renders. How to send to search and complete an output??? I could not find any example and this for me is the first time creating a search... Search_form.php: <form id='my_search' method='get' action='<?php echo $config->urls->root?>search/'> <p> <label for='search_branche'>Branche</label> <select id='search_branche' name='branche'> <option value=''>Any</option><?php // generate the Branche options, checking the whitelist to see if any are already selected foreach($pages->get("/branche/")->children() as $branche) { $selected = $branche->name == $input->whitelist->branche ? " selected='selected' " : ''; echo "<option$selected value='{$branche->name}'>{$branche->title}</option>"; } ?> </select> </p> <p><input type='submit' id='search_submit' name='submit' value='Search' /></p> </form> search.php $selector = ''; // we use this to store the info that generates the summary of what was searched for // the summary will appear above the search results $summary = array( "branche" => "" // will need to expand these later on ); // if a branche is specified, then we limit the results to having that branche // (branches field in those pages) if($input->get->branche) { $branche = $pages->get("/branche/" . $sanitizer->pageName($input->get->branche)); if($branche->id) { $selector .= "branche=$branche, ";//CHANGE YOUR SELECTOR AS SHOWN HERE // $summary["branche"] = $branche->title; $input->whitelist('branche', $branche->name); } } // here's where it get complicated - at bottom it says: $content = renderSkyscraperList(findSkyscrapers($selector));
  22. The thing is, after a foreach I have a list of items with field values including the 'uren' - which means hours - and I would like this value to be a link to get results (again). With a page list select you can simply do this: <a href="<?php echo $child->contract->url;?>"><?php echo $child->contract->title;?></a> I click on that link and I get results back...
  23. With a page select it's possible to just put ->url behind the field name and place it inside a link. But the rangeslider is different... I can't simply use the following code to get pages that have the uren.min>={$page->uren->min} How to do this? <a href=' <?php $pages->find("template=child-template, uren.min>={$page->uren->min}, limit=50, sort=-created");?>'> <?php echo $page->uren->min;?> </a>
  24. On my template I need to have a number presented for hours per week, example: 05 - 10 40 - 40 30 - 40 12 - 13 The number on the left can be between 0 and 40 The number on the right can be maximum 40, but always - higher then / or equal to - the left number. Obvious I can't use a page select for this. So I thought maybe a input number should be okay. But since there has to be a "-" in between, or a word (whatever) it's difficult to do this with one field. Maybe with 2 fields, but how to connect them if 2 ? EDIT > I was to quick, I see there was a range slider and give that a try.
×
×
  • Create New...