-
Posts
10,901 -
Joined
-
Last visited
-
Days Won
348
Everything posted by adrian
-
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Sorry, did you see my note above about needing to echo it out? I actually have all that code in a filter_form.inc file. Then wherever I want to use it, I just put: include("./filter_form.inc"); echo $filter_formcode; Does that sort it out ? -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
You can comment out that line if you want, or add this function somewhere: function strip_selected_tags_by_id_or_class($class, $text) { $regex = '#<(\w+)\s[^>]*(class|id)\s*=\s*[\'"](' . $class . ')[\'"][^>]*>.*</\\1>#isU'; return(preg_replace($regex, '', $text)); } I added that because my page fields have the ability to add a new item and I didn't want this visible on the front-end, even though it will only be visible to logged in users with rights to add, it is still not appropriate for a front-end filtering form. Chances are it won't be relevant in your situation anyway, so I would just delete the line. -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Try this complete code. It is actually as I have it working except I removed the text search box in case you don't have a body field, or need that functionality. Of course you'll need to add an echo at the end. I use this as an .inc so it is not in this code block for me. <?php $filter_formcode = ''; if($input->post->filter_save) { // Search selector builder $search_string = ''; $current_field = ''; //print_r($input->post); foreach($input->post as $field_name => $field_result){ if (is_array($field_result)){ foreach($field_result as $f_value){ if($current_field == $pages->get($f_value)->template){ $search_string .= '|' . (int)$f_value; } else{ $search_string .= ',' . $pages->get($f_value)->template . '=' . (int)$f_value; } $current_field = $pages->get($f_value)->template; } } /*else{ //This is only needed if you want the text search field which is an optional add on below if($field_name == 'body' && $field_result != ''){ $search_string .= $field_name . '%=' . $field_result; } }*/ } $search_string = trim($search_string,','); } else{ $search_string = ''; } error_log($search_string); $message = ''; // Populate with the names of the fields you want to exclude OR include (see instructions below) // Leave empty to output all the fields $myfields = array('id','title','body','images'); $form = $modules->get('InputfieldForm'); $fields = $page->child()->getInputfields(); /* //This adds a text search field if you want it $field = $this->modules->get('InputfieldText'); $field->attr('id', 'Inputfield_body'); $field->attr('name', 'body'); $field->label = "Search term"; $form->append($field); */ // If array is not empty use it to filter the fields if ($myfields){ foreach($fields as $f){ // Output all the fields minus the ones listed in the $myfields array // Instead, to output only the fields that are in the array, remove the (!) from the condition if (!in_array($f->name, $myfields)){ $f->value = ''; $form->append($f); } } } else{ // Else, include all the fields $form->append($fields); } // Add save button $field = $this->modules->get('InputfieldSubmit'); $field->attr('id+name', 'filter_save'); $field->attr('value', 'Find'); $field->label = "find"; $form->append($field); // Process the form if($input->post->filter_save) { $form->processInput($input->post); } $display = 'block'; if($form->getErrors()) { $display = 'block'; } $filter_formcode .= ' <div id="collapsed_form" style="display:'.$display.'">'; // render out form $filter_formcode .= $form->render(); $filter_formcode .= '</div>'; $filter_formcode = strip_selected_tags_by_id_or_class('InputfieldPageAdd', $filter_formcode); //Strip out the option to add new item to page field even though it only appears to certain admin users $filter_formcode .= '<script> $(document).ready(function() { $(\'select\').css({"max-width":"270px"}); $(\'li\').removeClass("InputfieldColumnWidth"); $(\'li\').removeClass("InputfieldColumnWidthFirst"); $(\'li\').attr("style", ""); }); </script>'; //set select to max width and remove floating selects so each one on own line -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
That code also works for me without populating existing values ( a good thing), but you'd still need to remove some fields like images etc. -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Try editing this line: $myfields = array('id','title','body'); to include your images field and any others that are not page fields that should be included as filter select options EDIT: Definitely - I have it working on several sections of a site I am working on -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Right - I see what you mean now - "the value which is selected". This is why I have this line: $f->value = ''; This clears the selected values when displaying the filter form. I agree this doesn't seem efficient, but it works and no other way seems to. -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Just to clarify my setup, the fields are all ASM Page fields and I want the values so the user can choose the values to filter from (hence the need for getInputfields()). Wish I could show you guys the working version of this, but it's not live yet. -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Catchable fatal error: Argument 1 passed to InputfieldWrapper::append() must be an instance of Inputfield, instance of Field given, called in /xxx/site/templates/filter_form.inc on line 101 and defined in /xxx/wire/core/InputfieldWrapper.php on line 159 -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Try replacing: $fields = $page->child()->template->fields; with: $fields = $page->child()->getInputfields(); It's working great for me and no need for all that new page stuff - thanks Soma. Are you getting the same error, or a different one? EDIT: Is properties-listing.php the template for the parent page or the child pages. The filter code as I set it up needs to be in the parent template. Does that make sense? -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Actually that creates an error, but this works: $fields = $page->child()->getInputfields(); Pitbull, I think if you remove those two lines I mention in #15 above and then use this line for getting the fields it should hopefully work for you. Let us know how it goes and I'll amend the initial code example. -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Soma, Thanks for chiming in. Good point - actually not sure now why I went that route. However I do think it would be good to be able to make this code more portable so you don't have to specify the template. I actually use the above as an .inc in many templates and it works great, although obviously can be improved. Pitbull - Soma is suggesting to eliminate these lines: $filter_form_page = new Page(); $filter_form_page->template = $page->child()->template; and replace: $fields = $filter_form_page->getInputfields(); with: $fields = $templates->get("mytempl")->fields; I am not sure if that will work the same way, but maybe it will I would still like to see something though that grabs the appropriate fields based on the template of the child of the current page. At least that is what I need to make it work for my purposes since it is the child pages that contain all the content we want to filter down to. Untested, but maybe something like: $fields = $page->child()->fields; -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
I don't think it is a subdomain issue. Did you make the change I suggested in 2 above? Does this error happen when loading the page, or not until you've chosen some filter options and clicked find? -
Filter results of selector using select/checkbox?
adrian replied to antknight's topic in General Support
Hey Pitbull, Sorry it's not working for you. A couple of things I can think of: 1. Does your current page have a child? The code above relies on that to set the template and therefore generate the filter fields. 2. Perhaps try replacing: $filter_form_page = new Page(); with $filter_form_page = $page; Let me know if that helps at all. -
Blocking the regular admin pages, and using custom forms with the api and hooks is what I do. It is possible to make the forms match the fields for the page so you can re-use the same code anywhere. Again, sure you have seen it given all the reading you have done, but this is a good place to start: http://processwire.com/talk/topic/59-module-want-form-builder/page-4
-
Peter, Not sure if this really answers your question, but members do not need create/add/edit rights, or any rights that allow them to see the admin panel. You can still create custom forms that allow them to add and edit data. Even a guest user can submit a form that updates a page. Although I think you already probably know this, but just in case it helps
-
Pitbull, Sorry I don't have time for a step by step right now, but the code I posted here: http://processwire.com/talk/topic/3583-filter-results-of-selector-using-selectcheckbox/?p=35204 has been working well for me for filtering based on existing category/page fields. Might be helpful for you.
-
Not sure that you need to get that complex. I did the following. Not sure how you handle front end logins or redirects from the login page, but you get the idea. if($user->isLoggedin()){ echo $page->comments->renderForm(); } else{ echo '<hr /><br /><h3>Post Comment</h3><p>To leave a comment, you must be <a href="/login/?pid='.$page->id.'">signed in</a></p>'; }
- 7 replies
-
- 2
-
- comments by users
- permissions
-
(and 1 more)
Tagged with:
-
Error saving file coming from Pagefile (kinda urgent)
adrian replied to evanmcd's topic in API & Templates
I am confused - something that seems to be happening a lot lately , but why does a local file copy need allow_fopen_url? What am I missing? Is it something to do with the fact that you are setting the source to https://..... rather than just the full path? The original error message doesn't seem to show this though? Sorry, probably not much help - I will bow out now -
Ability to define convention for image and file upload names
adrian replied to adrian's topic in Wishlist & Roadmap
Ipa, Currently PW should not change the filename at all, except that it appends a number if you go to upload the same file again. So long as you delete the original, save the page, then upload it again, you shouldn't have any issues with filenames being changed. What changes are you seeing? -
Error saving file coming from Pagefile (kinda urgent)
adrian replied to evanmcd's topic in API & Templates
Based on the error, I don't see it making any difference at all, because it is a filesystem error, but I have always uploaded photos like so: $entry->entry_photo->add($config->paths->files . $input->post["entry_photo"]); I am sure you have entry_photo set to only support 1 image, but maybe there is something related to that, due to the way it will still be an array via the API. I might be totally off the plot here, but when you're in a hurry to get a live site working again, sometimes it is worth trying anything -
Error saving file coming from Pagefile (kinda urgent)
adrian replied to evanmcd's topic in API & Templates
Just a quick observation - there is a "//" in the from path -
Does parse_str do what you need? http://www.php.net/manual/en/function.parse-str.php
-
XML needs numeric character references, rather than named entities. I wonder if a nice addition to the RSS module might be to convert an named entities to numeric automatically. This would take care of preventing any errors when body/summary etc fields are included in the RSS output.
-
BTW hafa - please ignore my original answer - I really didn't read your question properly at all
-
Willy, thanks for the heads up about that PW function. hafa - here is the details of that function: https://github.com/ryancramerdesign/ProcessWire/blob/dev/wire/core/Functions.php I had to look it up myself