Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by bwakad

  1. Hey Martijn! Count() and find() does not return NullPage is not exist. Get() does. Unless you add specificly ->id But for testing, between count() and find(), the API states count() just returns the quantity, and does not load the page (if it does find).
  2. Thanks Diogo / Soma ! I had to combine your replies into 1, or combine Soma's with your's. To make this short, I am testing to see if a page really exist. Using get I need to add ->id, otherwise I am getting a false positive/negative (returning NullPage). Using count() without ->id, otherwise that last is property of non-object (if page exist or not). get() with id if($pages->get("parent=/contracts/, name={$contract}")->id) { echo "found"; } else { echo "not found"; } count() without id if($pages->count("parent=/contracts/, name={$contract}")) { echo "found"; } else { echo "not found"; }
  3. The problem is not the /contract/ but the $contract I need to check. So $contract represents a child page name in string format parent: contract child: $contract path: /contract/$contract
  4. Hey, thanks for explaining. I understand the code but I never used hooks because I really don't understand them. I guess I will go for the function. And google for something similar using 24 hr format. ps. I really don't understand the date/time field in PW... time is always zero...
  5. It's just an empty name used in the <option> and not a page. The directory I check is /contract/$contract where $contract is the $input->post->contract <option> selected Maybe that's the issue: if $contract is empty, it checks the /contract/ which does exist... hmmm how to do this? -- EDIT -- $pages->count("/contract/, child={$contract}"); works. Not sure if this is the fastest way though... not working
  6. Well, still having trouble with this... my default option for a dropdown is this: <option value=''>Any</option> if ($input->post->submit) { if ( empty($input->post->contract) ) { echo "hello" ; } // is returning hello when "Any" is submitted. So we know it is empty! echo $input->post->contract; // is returning the value if other option then "Any" is chosen. $contract = $sanitizer->text($input->post->contract); echo $contract; // is returning the value if other option then "Any" is chosen if($pages->count("/contract/{$contract}")) echo "found"; // this is wrong, it returns "found" with option "Any" or another value chosen. Empty or not! And that last part I can't find out what's wrong, since clearly the page "Any" is not existing...
  7. Then for accuracy count (your first example) is better. Thanks Soma! Probably there is no way to make this shorter: $contract = $sanitizer->text($input->post->contract); if ($pages->count("/contract/{$contract}")) {
  8. I would like to test if a certain single page exist... using a switch (true or false) or if statement. I can use $pages->find("/$contract/") or $pages->get("/$contract/"). find() is returning a pageArray, get() is returning a page or NULL. So which one is better to test? Is a NULL page still evaluating to true?!
  9. Assuming a member has the right to fill in some information on a certain page (this should be a template because we need to check). Knowing PW, I think it should be possible to limit the date and time to update / change this information. I have no code yet. But would like to know what the required PW addressing is? The two fields coming in mind are modified / created for $user. Do I need to use a php date function as well? Because the date/time need to be converted? Or are there more possibilities in PW?
  10. Due to an error on my side, I deleted a file before backing up. So, I had to make my page from scratch... but using the code below, I cant access the $input->value to check for errors. Tried $input->post / $input->get. Either with "contract" and ->contract. Must be forgetting something... It's driving me nutz! -- EDIT -- Forgot I first have to submit before getting value back. lol. really stupido! Answer in API: if ($input->post->submit_details){ $value = $input->post->contract; // access as object property echo $value; $value = $input->post['contract']; // access as array index echo $value; $value = $input->post('contract'); // access as function echo $value; } $form = "<div class='row'><div class='medium-8 columns'> <form action='./' id='details' method='post'> <fieldset><legend>Details of {$user->name}</legend> <div class='row collapse'><label for='contract'>Contract <small>Required</small> <select id='contract' name='contract' ><option value=''>Please select</option>"; foreach ($pages->get("/contract/")->children() as $child) { if (!empty($member_page->get('contract'))) $selected = $child->name == $member_page->get('contract')->name ? " selected='selected' " : ''; $form .= "<option$selected value='{$child->name}'>{$child->title}</option>"; } $form .= "</select></label></div> </fieldset><button class='button tiny' type='submit' name='submit_details' value='submit_details' id='submit'>Submit</button></form></div></div>";
  11. Well, the code from your answer is working perfectly. Many many thanks! It's amazing how you guys come up with these great snippets ;-)
  12. No matter what I searched about forms, I ended up to an old topic of Soma (with a lot of participation from forum members)... But I liked the approach of building a form like this since the code is easy to read. I did try to make a select field as this, and this shows me an empty select field: // create a select input $field = $modules->get("InputfieldSelect"); $field->label = "Contract"; $field->attr('id+name','name'); $field->required = 1; $form->append($field); // append the field to the form I added this part in between, based on code found on one of the seven pages in mentioned topic: $contract = $pages->get("/contract/")->children(); foreach ($contract as $p) { $field->addOption($p->id,$p->title); } But now, I am stuck on this part, that I also found on one of these pages. Is should be a default value for a custom select. But I can't really find out how to change this to use on my not-so-custom select: $field->attr("value", $input->post->cms ? $input->post->cms : 'pw'); But wait, there's more... I use this code so I can get to my field values (if posted): $member_page = $pages->get("template=member,name={$user->name}"); // now I can get a value like: $member_page->get('contract'); And the $field->attr should either be a value from the member_page contract field, or if none, display a simple text: "please select". Right now, without this attr. it defaults to the first select value as selected...
  13. bwakad

    World Cup 2014

    Enjoyed the match. Even though Spain was good in first half. The goals by NL were super!
  14. Why not just use the <code> tags around it?
  15. I tried once using session, but apparently session is set already by PW. Then at PHP website they tell you a session is not really meant for variables which change a lot. By the way, I use foundation css which has jquery abide for error messages. works great!
  16. bwakad

    World Cup 2014

    Watched the opening game Bra - Kro. And was dissapointed kroatie did not win. They played much better game then Brazil. A schwalbe + japanese forune cookie = goal. Last years Brazil is running on lucky oil. 2morrow I will go to Museumplein Amsterdam to see the Netherlands vs Spain match - expected visitors 180.000 people!
  17. I'm always curious as to how they do that. But Kongondo provided me with that tip to check against values so I created arrays for my options to check against: $contract_clean = array(); foreach($pages->get("/contract/")->children() as $contract) { $contract_clean[] = "{$contract->name}"; } // first I sanitize, still not sure if needed... $contract = $sanitizer->text($input->post->contract); // then check against array, definitly needed if(in_array($contract, $contract_clean){ and finally posting the data to the page I want
  18. Although any module I see in PW is great, they do take a great deal of learning away from you. But if a end-user has to type [[hello_world]] And forget one of the required bracket's, what happens?
  19. Thanks Kongondo, I will just sanitize anything inside the form from now on. Dynamic is like this: $template = $templates->get("update_profile"); // loop through the fields foreach ($template->fields as $field) { $sanitizer->fieldName($value)
  20. Martijn, you are really doing your best.... but you also confuse me. lol I rest my expectation that there is no way in PW to dynamic sanitizing. So, "almost" everything is possible. But the <select> on the form is submitted by post. The <option> value's inside the <select> are of course page title's. Hence, I expect them to be clean. I made them myself! Yet, many convinced me to $sanitize->text(). And in your answer you stated 'post'. Looking for a hat now ! If a user types text in input fields, I know I have to sanitize those. Yet in another topic it was said people can change values using the DOM inspector which let me to believe even clean values are requiring sanitizing. I think I will start eating my shoe....
  21. lol. your hat's to big... and mine is gone! but in this topic I kinda hoped to see we can loop through template fields to build the form dynamic and without actually checking to see what kind of sanitize : text / textarea / pageName / etc. I'd have to use (sanitize dynamic). Of course, in my case I know the outcome, they are all page selects and judging on other topic replies, I need to use $sanitizer->text($input->etc Where as I suspected it to be $sanitizer->pageName($input->etc. Since they are page titles passed back as value. But it would be nice to see it done automatic.
  22. I use for example this inside a function which get used on my main template, checking the current viewed page->id and at the end of the function I include $layout file that make up the code I want to display according to that page id. // see which page id is current one and create part of $selector switch ($page->id) { case '1171': // members // declare our variables first because they are used in all cases, then use SUB switch // we don't want to change variable $pages, just it's value. Change $layout $pages = $users; $layout = "./myinclude/members.inc"; // SUB switch to find user role. for now we let all roles see all roles switch (true) { // superuser case ($user->hasRole('38')) : $selector = "roles=38|1160|1170|1177"; break; // supplier case ($user->hasRole('1160')): $selector = "roles=38|1160|1170|1177"; break; // store case ($user->hasRole('1170')): $selector = "roles=38|1160|1170|1177"; break; // member default: $selector = "roles=38|1160|1170|1177"; break; } // end of SUB switch break; // end of case 1171 I use this to create the find() pages, but you can also use other code in the case's... // On that included file I start a double check, so sirect access is restricted // while the switch is still active, because this include file is inside the template if(!$user->isLoggedin()) { // redirect to login page $session->redirect("/login/"); }: Of course, the login is a seperate page, and one would never access the content without logging in first AND having the right role.
  23. Well, your first answer I read in the API to. No question about that, since a form is using post or get... But your second asnwer, although I used those two fields as example, according to the API text, all fieldtypes come from modules. Do I need to assume all other fields are also done and we do not need to sanitize? Basically, when I would loop over the fields on a template and came across those two, I would be in trouble sanitizing 2 times, and they would not match any that are given in the API $sanitize section. So, is it even possible to sanitize by default somehow?
  24. According to the API we have among others: $sanitizer->fieldName($value) $sanitizer->selectorValue($value) $sanitizer->text($value) $sanitizer->pageName($value) Probably it all depends on where you want to use it for, and what you want to get back from input. But the word input really drives me nuts!!! Do we mean the tag <input type='xxx'> which can be text or textarea... or the value we receive back? And then, how would you do this for a <select> which in PW is a pageName? Also the modules these fields are coming from, making an unlimited naming convention. CropImage and MapMarker (no offence, good modules)... but how would you know to sanitize this with what? echo $field->type gives me back different ones then I would expect: FieldtypePageTitle // I would expect it at least to be "Page" as in the back-end. FieldtypeText I understand there might be a need to put Fieldtype in front of it. One would even say that text is a input field, but is title also not a input field? Why suddendly the PageTitle? Leaving me with the question, if it's even possible to dynamically sanitize in a loop ? Why build a form dynamic, but manually check all the time what and how to sanitize. It doesn't make sence to me... $template = $templates->get("update_profile"); // loop through the fields foreach ($template->fields as $field) { // this probably would not work for all fieldtypes, but then again, I don't even know how to check that: $sanitizer->fieldName($value) I'm already half way through my hat....because knowing PW's reputation there must be a good way, just can't find it.
  • Create New...