-
Posts
1,489 -
Joined
-
Last visited
-
Days Won
43
Everything posted by gebeer
-
To expand on arjen's answer: I had use cases where I had to add more than one tab to several templates. To avoid creating too many individually named fields of type FieldsetTabOpen, I did the following: Create fields of type FieldsetTabOpen with generic names, like tab1, tab2 etc. Apply the field to template A and in the template override for the field label name it e.g. "Sidebar Left" Apply the same field to template B and in the template override for the field label name it e.g. "Sidebar Right" This way you only have one field of type FieldsetTabOpen but can use it for differently named Tabs in different temp[lates.
-
I can confirm, that put is working. All JSON that I send in the request body is available in $params. For patch/delete, I'm sorry, but I don't know because I haven't used them. If $params is empty: did you make sure that header Content-Type application/json is set? Or maybe the JSON in your request body is malformed?
- 32 replies
-
- helper
- processwire
-
(and 2 more)
Tagged with:
-
I am not sure about passing variables to field->renderValue. But adding your JS and CSS dependencies to custom arrays is pretty straightforward. In config.php you can define your custom JS and CSS arrays like $config->customJs = new FilenameArray; $config->customCss = new FilenameArray; Then in your template file where you want to include your dependency you do $config->customJs->add('pathtoyourscriptfile'); $config->customCss->add('pathtoyourstylefile'); In the head section of your html you then render them with <?php if(count($config->customCss)) foreach($config->customCss->unique() as $file) echo "\n\t<link type='text/css' href='$file' rel='stylesheet' />"; ?> and in the head or end of body section render your JS <?php foreach($config->customJs->unique() as $url) echo "<script src='$url'></script>"; ?>
-
Looking again at my above implementation for additional content in the marker popup feels a bit hacky because the content of the popup is being constructed in MarkupLeafletMap.js I think the cleaner and proper way of doing it would be to construct the HTML that goes into the popup on the template file level and then pass it to the map render function. Something like this: $options = array(); $options["markerPopupContent"] = "<b><a href='{$page->url}'>{$page->title}</a></b>{$page->body}"; // ... more options $map = $modules->get('MarkupLeafletMap'); echo $map->render($items, 'map', $options); Hope to get your opinion on this. I would then implement the code into my fork of this module.
-
Since browser support for flex is now pretty good, I am looking into using flexboxgrid. It looks very promising and looking at their github repo with all those likes and forks it sure will last. Has anybody here used it and what do you think?
-
@houseofdeadleg At the moment only the title is supported. You would need to change some code in the module: https://github.com/madebymats/FieldtypeLeafletMapMarker/blob/master/MarkupLeafletMap.module#L115 -> add another line 'markerBodyField' => 'body', https://github.com/madebymats/FieldtypeLeafletMapMarker/blob/master/MarkupLeafletMap.module#L192 -> add another line $body = $options['markerBodyField'] ? $page->get($options['markerBodyField']) : ''; https://github.com/madebymats/FieldtypeLeafletMapMarker/blob/master/MarkupLeafletMap.module#L193 -> change line 193 to $out .= "$id.addMarker($marker->lat, $marker->lng, '$url', '$title', '$body'); "; https://github.com/madebymats/FieldtypeLeafletMapMarker/blob/master/MarkupLeafletMap.js#L65 -> change line 65 to this.addMarker = function(lat, lng, url, title, body) { https://github.com/madebymats/FieldtypeLeafletMapMarker/blob/master/MarkupLeafletMap.js#L98 -> change line 98 to marker.bindPopup("<b><a href='" + marker.linkURL + "'>" + title + "</a></b><br>" + body); Then in the template where you render the map, you need to include the markerBodyField in the options that you pass to the render function, e.g. $options = array(); $options["markerTitleField"] = $page->title; $options["markerBodyField"] = ($page->body) ? $page->body : ""; // ... more options $map = $modules->get('MarkupLeafletMap'); echo $map->render($items, 'map', $options); I have not tested this but it should work. Please report back here.
-
@horst you could also use the (relatively) new $sanitizer->int($value) or $sanitizer->intUnsigned($value) method like if(wire("sanitizer")->int($input->get->id)) {...}
-
@Alxndre' I can see an advantage using $params: it utilizes a standardised way of sending data through the request body in a JSON object. So there is only one place where you have access to all the data that was sent with the request. Also, if you do basic http authentication and use my modified version of the helper classes, you will have access to $params["name"] and $params["pass"] to do request validation.
-
@alan do you get <li> instead of <fieldset> tags? That would be the default behaviour. You can set the HTML tags that are rendered, even by inputfield type, see here.
-
It would be fantastic if we could set different configurations for CKEditor fields based on template or user roles. Like described on https://weekly.pw/issue/14/ under "More CKEditor upgrades", we can use config files in /site/modules/InputfieldCKEditor/ to store settings per field. E.g. for the body field this would be /site/modules/InputfieldCKEditor/config-body.js. Maybe this logic could be extended to something like /site/modules/InputfieldCKEditor/config--field-body--template-home--role-mycustomrole.js. I was coming over from Joomla to PW couple of years ago and there we had an excellent CKEditor integration called JCE where you could define settings per user role etc. Maybe I am wrong but up to now we need to create additional fields if we need editor config settings per template. If there already is a way to do that I'd be happy to know.
-
And Sublime Text has 2 plugins that index method definitions and let you jump there quickly: https://github.com/SublimeCodeIntel/SublimeCodeIntel https://packagecontrol.io/packages/WhoCalled%20Function%20Finder (not maintained anymore)
-
Selector problem with multiple keywords in multiple fields
gebeer replied to opalepatrick's topic in General Support
The manual for selector operators states for ~= "Contains all the words". So your search returns only fields that have all of the $parts, e.g. "myfabric yellow". I think you need to use the OR operator for your selector values, too (see here). So your code would read $selector .= ", title|body|collection.title|hue.title|pattern.title|pattern_type.title|usage.title~=" . $sanitizer->selectorValue(implode('|', $parts)); | pipe instead of blank space in the implode. -
Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)
gebeer replied to ryan's topic in Modules/Plugins
I have converted the relevant db query code to PDO and will issue a pull request. -
Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)
gebeer replied to ryan's topic in Modules/Plugins
thank you adrian. I will give the renaming a try. Yes, I'm sure that it is this module because the error throws only on pages with embedded video and on the settings page for the module in the backend. The module officially supports PW only up to 2.4. That may be why it is not using PDO. EDIT: rnaming $db to $database didn't help. $db is initialized in the module with $db = wire('db'); -
Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)
gebeer replied to ryan's topic in Modules/Plugins
When I open a page with video embedded, I get this: Error: Class 'mysqli' not found (line 23 of /home/gocinet/public_html/wire/core/Database.php) Same error when I access the module settings page in the backend. PW 2.7.0. This only happens on the live server, not on my dev machine. So it seems to be server related. Any pointers on how to solve this would be great. Thank you. EDIT: I just discovered that mysqli support is not installed on the live server (godaddy VPS). Installing it should solve the problem. -
With $pages->get("template=events") you only get one page. You need to use $pages->find("template=events") to get all event pages. Try $nextevents = $pages->find("template=events")->events->find("end_date>today, sort=end_date, limit=2"); Not sure though if this works. You might need to loop through your events and inside the loop remove those that don' match required dates $nextevents = $pages->find("template=events, sort=end_date"); foreach($nextevents as $e) { if ($e->getUnformatted(events->end_date) < time()) $nextevents->remove($e); } // get first 2 events with slice, see https://processwire.com/api/arrays/ nextevents = $nextevents->slice(0, 2);
-
@LostKobrakai yes, this is right. Here Soma gives a good example of how to use your own form markup and do the processing with PW API.
-
clients sites need to talk to one main site
gebeer replied to Marco Angeli's topic in General Support
I am using REST API to exchange information between independent PW installs. There is Ryan's Pages Web Service Module you could use on the client sites and then query it from the main site. Or clsource's REST Helper classes for setting up a REST API. I wrote a tutorial on setting up the latter. If you decide to go the REST route, there is the HTTPful REST client for PHP which makes life a lot easier when doing requests with PHP (from your main site to the client sites). -
@justb3a thank you for those. Didn't know about $form->setClasses(). Pete has just given some nice info about $form->setMarkup() over there. I will definitely have a closer look at these methods.
-
You are welcome. Formbuilder is a great tool and makes the task of building frontend forms quite convenient. It covers most of the use cases for forms on websites. Building Forms is always a somewhat complex topic in every CMS/framework and I think Ryan has done a great job, both with Formbuilder and with the form API, to make this task easier for developers. If you need total control over the HTML of your form, coding it from scratch and then processing it manually seems to be the way to go.
-
I have to say that the form API works pretty well in the frontend. I have several sites where I use it without issues. Once you get the hang of it, it is actually quite nice to interact with. Only thing I am missing is a more easy way than the current to get more control over the rendered markup. Formbuilder comes to the rescue here. If I remember correctly, when UI framework support was introduced to formbuilder, Ryan stated that the core functionality was altered to easier support UI frameworks. But I never found any hints on how to easily alter rendering of form markup (especially field wrapper's markup and attributes) other than through hooks. Nevertheless, I agree that it would be nice to have a docs section dedicated to this topic. Or at least have a link collection to relevant forum posts that deal with frontend forms, processing and saving of input values. Links I can come up with quickly: https://processwire.com/talk/topic/2089-create-simple-forms-using-api/ and, of course, Soma's great gists (big kudos) https://gist.github.com/somatonic/5011926 (build and process generic forms from page templates) https://gist.github.com/somatonic/4027908 (build and process forms manually with API) https://gist.github.com/somatonic/4150974 (upload images) https://gist.github.com/somatonic/5415646 (form with fields in table) https://gist.github.com/somatonic/5233338 (manual form markup with file upload handling)
-
If you take a look at the html that is rendered for every form, you will see, that the fields are wrapped in li elements which are inside an ul container with class Inputfields. <ul class="Inputfields"> <li id="some_id" class="Inputfield ...">The form inputfield html</li> </ul> 'list' => "<div {attrs}>{out}</div>" refers to the ul container. So in this example ul would become div 'item' => "<div {attrs}>{out}</div>" refers to the li elements inside the ul. So in this example the li elements would become div elements. {attr} refers to the ids and classes and {out} to the inputfield markup. You can change id, name and class of an inputfield with $field->attr("class" , "myclass"); $field->attr(id+name , "myname"); But you cannot change the ids and classes of the inputfield wrappers in this way. You'd need custom hooks for that. EDIT: yes you can, see Pete's post below Or you get formbuilder which makes it really easy to generate forms for uikit and other frameworks.
-
@Gurumeditation regarding UI frameworks, you can set your desired classes to the inputfield wrapper with $form->setMarkup(array( 'list' => "<div {attrs}>{out}</div>", 'item' => "<div {attrs}>{out}</div>" )); and set classes to fields with $field->attr("class" , "myclass"); That is the only way that I know of how you can get to use your framework's classes in the form. Sanitizing: you just need to run the $input->post values through PW's $sanitizer methods before they actually get saved. It depends very much on the data your handling with your form, which methods to use. This legendary thread about building forms with the PW API is worth reading and should answer most of the questions.
-
You should take a look at Soma's great gist about building frontend forms from fields of a template (or page). This code also pulls in all the dependencies you need for asm page fields, image fields etc. It also takes care of server side form validation. Only thing you need to add is sanitation of the form values. I have used this code as a base for several frontend forms (even complex ones) and it is working great.