Jump to content

bwakad

Members
  • Posts

    450
  • Joined

  • Last visited

Everything posted by bwakad

  1. I have another question about this code from soma / pete example. Since it would be dynamically creating the form fields, I suspect it can be used to sanitize dynamic as well. // Form started before this code // get fields from a template we require to complete this page $template = $templates->get("update_profile"); // loop through the fields foreach ($template->fields as $field) { $fieldlabel = $template->fieldgroup->getField($field, true)->label; $inputfield = $field->getInputfield($page); // set default value if we have one $inputfield->value = $member_page->get($field->name); // markup, and render() here then end the foreach; // form ends after these fields But when the form is done, we need to sanitize. One would have to use code like this, and name at least the fieldtype and fieldname: if($input->post->submit_details) { $sanitizer->text($input->post->contract); Or do the same code from above and foreach again. Or maybe there is another way... But what happens if one field will be text / textarea or something else? I have tried to use the foreach again, and echo out the fieldtype, hoping I could use it to sanitize dynamic: foreach($template->fields as $field){ echo $field->name; echo $field->type; But this gives me back "FieldTypePage" (in my case)... Logic thinking for text it would be FieldTypeText (I hope). I am really hoping to see how Soma and Pete did this.
  2. normally it would be: $inputfield = $field->getInputfield($page); $selected = $member_page->get($field->name) == $inputfield ? " selected='selected' " : ''; and then do: <option$selected value='{$field->name}'>{$field->title} </option>"; but now: echo $inputfield->render() has already the <option> tag.... -- EDIT -- think I need better vision. lol. Martijn gave a good hint, but I did not read the code through. It stated: // when a value is required and the value is empty and a default value is specified, we use it. $this->attr('value', $value); So the solution was simply setting it to what Martijn mentioned: $inputfield->value = $member_page->get($field->name); And then use render()
  3. Maybe I need to explain some more... This code is now on my profile.php, displaying the form fields which are set via "update_profile" template: $template = $templates->get("update_profile"); foreach ($template->fields as $field) { $fieldlabel = $template->fieldgroup->getField($field, true)->label; $inputfield = $field->getInputfield($page); if($fieldlabel == "Title") continue; echo "<label for='$field->name'>".$fieldlabel.$inputfield->render()."</label>"; } After submitting the form, it posts the values to the user member page. The member.php is the template that just outputs the values. A side note: on any other current page I could access the user member values by using this : $member_page = $pages->get("template=member,name={$user->name}"); And then this : $member_page->fieldname->title But the question was: how to get the values which could be on the member page already, into the field on the form (pre-selected or something) Using this code on the form: $inputfield = $field->getInputfield($page); echo $inputfield->render() I already have field values displayed on the member page using this: $page->contract->title I did not really understand what you meant by mapping, but if it is what I already do (displaying those values)... how to make them appear in the form?
  4. hey cstevensjr, I'm not using form builder. What do you mean with save to a configuration page? I am using the mentioned code on a profile page - available only to the logged in user. It post the selected values to this member's page - and that page is visible to members only. The easiest way would be to collect what was chosen before (I guess). As example - I can get those values by using : $member_page = $pages->get("template=member,name={$user->name}"); And then their values: $member_page->fieldname->title But it would be cool to have those returned in the select option. It's just, the following code that make me wonder how or were this markup is done, since it displays the field as intended. Meaning, it has the <select> and <option> and just output's it like it suppose to: $inputfield = $field->getInputfield($page); echo $inputfield->render()
  5. This method looks very good, collecting the field and values in one time. But what about the title field which is always required? You can't leave it out from the template. So, how to present that on the front-end? -- EDIT -- I just used continue; to skip Title $template = $templates->get("update_profile"); foreach ($template->fields as $field) { $fieldlabel = $template->fieldgroup->getField($field, true)->label; $inputfield = $field->getInputfield($page); if($fieldlabel == "Title") continue; echo "<label for='$field->name'>".$fieldlabel.$inputfield->render()."</label>"; } I am curious as to see how you all use this. Meaning: a new form for adding details is just displaying all fields. But after it is submitted there is a chance people like to change all, or some. So how do you proceed from there?
  6. I actually got it. But was saying it, because we want to see Kongondo eat his hat...
  7. lol. then maybe I need to say "don't understand"
  8. Yes, sorry bout that. Typed your name, was thinking of the movie and then made it all wrong. lol Okay, so again, it might have been my not reading correctly, but looking at the provided link I still do not see one that says USE ME! Since a select is in fact a field: $sanitizer->fieldName($value) OR $sanitizer->name($value) But then again, the value is a page name: $sanitizer->pageName($value) And this one specifically says INPUT: $sanitizer->text($value) OR $sanitizer->textarea($value) Then again, the pages are also considered to be part of url... As you can see, with me, the confusion is complete! And as said by Soma one time, I'm a hard nut to crack... so please be patience
  9. Thanks Martijn, I really have no experience (that I know of) with DOM inspector, but gladly take your word for it. Looking at a form, most of the fields are : <input type = text AND <input type = textarea. The difference here is recognizable: $sanitizer->text AND $sanitizer->textarea <option value = .... Here, according to Kokondo's answer: $sanitizer->text (again) So, to be clear, any other field then textarea is ALWAYS $sanitizer->text ? Just want to know this to not make mistakes.
  10. but, how would you do with a dropdown value? I'm thinking, even the dropdown value is in fact a text (if not using integers), or not? $sanitizer->textarea $sanitizer->text $sanitizer->
  11. Searching the forum, and reading the API... but have not really seen a good explaining. I have the feeling, anything were people can input text, is need to be sanitized. In some cases I see selectorValue, in other cases I see pageName. But most of the time I see text, or textarea... I hope someone can explain. for instance, let's assume I have this <select> where in this case, $field is "contract": echo "<select id='{$field}' name='{$field}'> <option value=''>Any</option>"; foreach($pages->get("/{$field}/")->children() as $field) { echo "<option value='{$field->name}'>{$field->title} </option>"; } echo "</select>"; normally with a input field where people can enter text, upon submission, you would do: $member_page->contract = $sanitizer->text($input->post->contract); with a textarea it would be: $member_page->contract = $sanitizer->textarea($input->post->contract); So, what about a dropdown <select> ? It might be text, but it's not free input... do I need to sanitize?
  12. Thanks for the thorough explanations! I will delve myself deeper in php (hope I get out though) lol
  13. Yes. I changed it to $somePages->explode('name') to see what is was returning: obviously the page withing the pageArray. >>> function getDistinctValues(PageArray $pageArray, array $fields){ >>> Isn't a pageArray returning objects by default?
  14. ps. in this function you need to pass the [$field] and [$p->$field] as string e.g. (string) inside [], or you will get illegal offset
  15. So, with your last code, I can't count the occurrence of a field VALUE, but can count the occurrence of the field NAME. Which, from my latest example is not what I am after, since all my fields are required and always occur. Because this code will give me the pagenames that have the array's field 'provincie' present: foreach($someFields as $field) { $resultArray[$field] = array_count_values($somePages->explode('name')); } echo "<pre>".print_r($resultArray)."</pre>"; But I will continue. You already helped a great deal and made me learn more. Thanks so far !
  16. I am not sure I follow you... "since PW 2.4 the simplest way to count values of certain keys/fields"... won't work with page fields. Isn't the page name/title and the (page) field name a string?
  17. Warning: array_count_values(): Can only count STRING and INTEGER values! on this line: $resultArray[$field] = array_count_values($somePages->explode($field)); It is strange because $field is in string format! Only this code: $someFields = array("provincie","branche"); echo "<pre>".print_r($someFields)."</pre>"; outputs: Array ( [0] => provincie [1] => branche ) 1 below is code from Soma: $someFields = array("province", "network"); $somePages = $pages->find("template=child-template, category=xxx"); $resultArray = array(); foreach($someFields as $field) { $resultArray[$field] = array_count_values($somePages->explode($field)); } // that's it show array result foreach($resultArray as $field => $values) { foreach($values as $value => $count) { echo "<p>$field - $value: $count</p>"; } }
  18. wow, you're good! I'd have to look a good number of times into these code examples you gave. At first I thought there was a native PW function, and was trying to use: $a->getValues() - which would return a php array with all values. $a->unique() - which would return array without duplicate values. But I really did not know how to use them inside the function, so I went for the long walk. lol Your examples are very good to study on (as I am still learning php) and I probably end up with a way of using them. My plan is not to just launch and then build further, but to build every week something, and much much later I launch. For now the learning curve is way to much fun, it's just the explaining from my part which is hard sometimes! I probably also did not mention my field values are in fact page selects. So to get all those values into an array, I would need to use a find parent=provincie and take child page names. I know PW is one of the fastest to retrieve items of any kind. Good job from Ryan! But I am concerned because I have 8 fields (parent page) with each about 30 child pages. Would it be an overload to use that in a function?
  19. I already was playing with that function... don't mind the names I used. For now, it's just to test. Basically I was thinking to use arrays function create_arrays(){ $page = wire("page"); $pages = wire("pages"); // this array will hold all my field names, for now just one! // Later, I will create the array automatic $fields = array('provincie'); // this array will hold all field values related to $fields array value // Later, I will create the array automatic $values = array('drenthe','friesland'); // here I create a new array to store values $new = array(); // iterate through the $fields array foreach ($fields as $field) { // then after one, iterate through the $values array foreach($values as $value){ // static code, but obviously I need the already used one which led me to current page // I use the $field and $value to get my "field=name" $selects = $pages->find("template=child-template, {$field}=$value"); if(count($selects)){ foreach($selects as $item) { // here I store the found $value in the array I created $new[] = "{$value}"; } } } } // this code is just to see output echo count($new) ; echo "<pre>"; print_r($new); echo "</pre>"; // this part does the actual counting of what I need $sub_count = array_count_values($new); while (list ($value, $qty) = each ($sub_count)) { echo "$value : $qty "." times"."<br/>"; } } So, if you use this code, with minor adjustments, you will see what I am after.
  20. Okay, because you look so mad on your avatar ... let's say I do a $pages->find("items") sorted by branche. In results I have items. And I display those like this: item 01 some title | branche: Nokia | province: Drenthe | network: 4 ------------------------------ item 02 some title | branche: Siemens | province: Groningen | network: 6 ------------------------------ item 03 some title | branche: Siemens | province: Groningen | network: 4 ------------------------------ then to say FROM each field: how many of these items have the same value or single? example: province "Drenthe" = 1 province "Groningen" = 2 network "4" = 2 network "6" = 1 branche "Nokia" = 1 branche "Siemens" = 2
  21. Can't really explain it differently. In a way Raymond gave, except I DO NOT KNOW it's value ! Difficult to do. But reading the API cheatsheet I see 2 functions: $a->getValues() - which would return a php array with all values. $a->unique() - which would return array without duplicate values. I am guessing I need to do the first and then count each value in this array. But using in a function I get undefined index???
  22. This is what I am after: Find pages with field01 value X returns results-array. The pages in this array have fields with the same or different values. So, I know the fields that will be returned, but not their values. result 1 - with field02 value A, field03 with value Y result 2 - with field02 value B, field03 with value Y result 3 - with field02 value A, field03 with value Z etc from these results I would like to know: HOW MANY have field02 with value A? HOW MANY have field02 with value B? HOW MANY have field03 with value Y? HOW MANY have field03 with value Z? etc. For the example above, I have about 15 parents with 10 to 35 child pages as values for my page-selects. The 15 fields (parents) are always in any single result. But the value can be different. So as long as I get a result, those 15 fields are displayed as values. I was looking into array functions, but it's way over the top: to make 15 arrays with their values, then match a value from the array with the one returned in a foreach .... I think. So I thought, maybe PW already had such a thing in mind?
  23. Suppose after a find, you would like to have a sidebar that says from these results, on field A, we have xx items on field B, we have xx items etc. to be clear: NOT the total of pages which are in DB. But from the found pages!
  24. I use sort values via input-> so that this part always stays at the end of the url the link is for example: $currentUrl.'?sort=name'; Since I also use segments to catch a specific field to search on, I had to change the ?sort url. This is why I used the urlSegmentsStr code below (found on a post from Martijn): // change url for sorting if segments are used if($input->urlSegmentsStr){ $currentUrl = $page->url.$input->urlSegmentsStr."/"; }else { $currentUrl = $page->url; } So the url now displays: /pagename/subpage/segment1/segment2/page2/?sort=name Pagination seems to work, keeping field and sort. Except when sorting again, on page2, any new sort will return back to page1 (not keeping the current page number 2). EDIT ---- Actually come to think of it: why would I need to stay on that page after a sort (in any order)? After all, I request a new sort and want to see whats the first result, right?! So I will close this topic... sorry!
×
×
  • Create New...