-
Posts
6,798 -
Joined
-
Last visited
-
Days Won
158
Everything posted by Soma
-
This is a field that requires additional stuff thats why it doesn't work. It would work if you include jQuery UI (with js and css) and to init the datepicker to the input you either do it by yourself with a js script or you can use the wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.js. Depending on the jQuery UI theme you include, your form elements will get also styled. But you can roll your own or overwrite some stuff. Not sure what the best way would be for you but there are several.
-
Just wanted to share what I recently used to create forms in modules and in frontend using the API and Inputfield modules PW provides and uses on its own. I think many newcomers or also advanced user aren't aware what is already possible in templates with some simple and flexible code. Learning this can greatly help in any aspect when you develop with PW. It's not as easy and powerful as FormBuilder but a great example of what can be archieved within PW. Really? Tell me more The output markup generated with something like echo $form->render(); will be a like the one you get with FormBuilder or admin forms in backend. It's what PW is made of. Now since 2.2.5~ somewhere, the "required" option is possible for all fields (previous not) and that makes it easier a lot for validation and also it renders inline errors already nicely (due to Ryan FormBuilder yah!). For example the Password inputfield already provides two field to confirm the password and will validate it. De- and encryption method also exists. Or you can also use columns width setting for a field, which was added not so long ago. Some fields like Asm MultiSelect would require to also include their css and js to work but haven't tried. Also file uploads isn't there, but maybe at some point there will be more options. It would be still possible to code your own uploader when the form is submitted. Validation? If you understand a little more how PW works with forms and inputfields you can simply add you own validation, do hooks and lots of magic with very easy code to read and maintain. You can also use the processInput($input->post) method of a form that PW uses itself to validate a form. So getting to see if there was any errors is simply checking for $form->getErrors();. Also the $form->processInput($input->post) will prevent CSRF attacks and the form will append a hidden field automaticly. It's also worth noting that processInput() will work also with an array (key=>value) of data it doesn't have to be the one from $input->post. Styling? It works well if you take your own CSS or just pick the inputfields.css from the templates-admin folder as a start. Also the CSS file from the wire/modules/InputfieldRadios module can be helpful to add. And that's it. It's not very hard to get it display nicely. Here an code example of a simple form. <?php $out = ''; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'subscribe-form'); // create a text input $field = $modules->get("InputfieldText"); $field->label = "Name"; $field->attr('id+name','name'); $field->required = 1; $form->append($field); // append the field to the form // create email field $field = $modules->get("InputfieldEmail"); $field->label = "E-Mail"; $field->attr('id+name','email'); $field->required = 1; $form->append($field); // append the field // you get the idea $field = $modules->get("InputfieldPassword"); $field->label = "Passwort"; $field->attr("id+name","pass"); $field->required = 1; $form->append($field); // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Subscribe"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); // here is a good point for extra/custom validation and manipulate fields $email = $form->get("email"); if($email && (strpos($email->value,'@hotmail') !== FALSE)){ // attach an error to the field // and it will get displayed along the field $email->error("Sorry we don't accept hotmail addresses for now."); } if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { // do with the form what you like, create and save it as page // or send emails. to get the values you can use // $email = $form->get("email")->value; // $name = $form->get("name")->value; // $pass = $form->get("pass")->value; // // to sanitize input // $name = $sanitizer->text($input->post->name); // $email = $sanitizer->email($form->get("email")->value); $out .= "<p>Thanks! Your submission was successful."; } } else { // render out form without processing $out .= $form->render(); } include("./head.inc"); echo $out; include("./foot.inc"); Here the code snippet as gist github: https://gist.github.com/4027908 Maybe there's something I'm not aware of yet, so if there something to still care about just let me know. Maybe some example of hooks could be appended here too. Thanks Edit March 2017: This code still works in PW2.8 and PW3.
- 237 replies
-
- 54
-
How about unset? unset($images) Still trying to understand why remove all items?
-
I sometimes use CSV import module to create lots of pages from one list or names or titles. It's very handy and even can import images or files from an old website.
-
Can't reproduce, works fine here in Chrome and Safari.
-
Just tested and downloaded and installed via Modules Manager. Works great so far! Thanks for this module Ryan
-
I logged in and saved the page, it's back now.
-
I just recognized that on some new installation the module doesn't work as it failed to add the script needed. I corrected this and update the repo with version 1.0.2. http://modules.processwire.com/modules/form-save-reminder/
-
Problem with injecting custom JS to admin (jQuery is not defined)
Soma replied to teppo's topic in Module/Plugin Development
So u are having a ModuleJS? What if u don't make it autoload but permanent? So u dont have to install it, but maybe get loaded after. Well I also gave up after so many tries and use hook on somerhing to add script after jquery or after certain other module. Also as u wrote u want to add scripts on certain admin pages, u would anyway need some hook to determine when to do it. Sorry for triple post.. on mobile -
Problem with injecting custom JS to admin (jQuery is not defined)
Soma replied to teppo's topic in Module/Plugin Development
Apeisa, also wanted to mention it. A process module usually isnt autoload and loads scripts with same classname automatic, but i'm also confused everytime i want to add scripts and it gets appended before jquery hence my 1001 post about this subject. -
Problem with injecting custom JS to admin (jQuery is not defined)
Soma replied to teppo's topic in Module/Plugin Development
I don't mean "execute" function literally, just a hook or function that is added to a hook or process in the system or called directly somewhere. Adding script alone in the init on a autload module will always append it before jquery core. The code example on that link does have a hook with with a addLink function. This will get processed at a certain point where jquery core and likely other script are already appended. If you give us more example of what you are doing I can help. The code Ryan posted, is how the ModuleJS does it, but as I recently found out, doing it the same way in your module init, will add it before jquery core always, so you can't use ModuleJS. Look at the extensive thread I created also about the same subject here -
Problem with injecting custom JS to admin (jQuery is not defined)
Soma replied to teppo's topic in Module/Plugin Development
You need to have some execute function where you append the script, it won't work in the init of an autoload module, this appended as first. If you post the module code one surely can help. -
Glad you found the problem. This is where the Autocomplete Page Inputfield Module comes in handy, but its not installed by default so you have to enable it first.
-
Thanks, that's kind of you arjen. Glad it's well recognized and helpful.
-
Well you'd have to insert it into a image tag to see an image of course. echo $page->image->url only returns the url and not an image tag. You have to create your markup, PW doesn't generally generate markup. So that might look like this. Depends on how you need the image be rendered. $imgurl = $page->image->url; echo "<img src='$imgurl'/>"; That's all also shown in the images documentation with examples:
-
If it's a single image field you do simply: echo $page->image->url; If the field allows for multiple you have to loop the field or directly access one through index. $page->image->first()->url; You find some API infos here http://processwire.com/api/cheatsheet/#files And also in the Docs http://processwire.com/api/fieldtypes/images/
-
Ok thanks for confirming, I just updated the readme.
-
I just setup a complete new install with this module, and it also didn't work with pagination. I only enabled urlSegments to the proxy template (as in manual) and as soon as I enabled page numbers also it started working again. Can you check if you have url segements and page numbers enabled on the language proxy template. Works all fine here.
-
I will try later with a fresh installation, just to make sure. BTW what does my code example output? The admin debug output doesn't help much. Any errors? What are the url's and what does not work and does it show?
-
Based on netcarvers first script I tried this on my products (550) and grouping them by price field. $pa = $pages->find("template=product,sort=sort"); $groups = array(); foreach($pa as $p) $groups["$p->sc_price"][] = $p->id; echo "<ul>"; foreach($groups as $key => $gr){ $count = count($gr); echo "<li>$key ($count)"; if($count){ echo "<ul>"; foreach($gr as $key => $pid){ $r = $pages->get($pid); echo "<li><a href='$r->url'>$r->title</a></li>"; } echo "</ul>"; } echo "</li>"; } echo "</ul>"; echo "<br/>memory:".memory_get_peak_usage()/1024/1024; This doesn't add much memory in my case, 1MB more and maybe takes +~1sec but haven't looked at execution times. So 2000 pages will maybe be around +2-3MB and 2-3 seconds. I can run this script along with a ton other heavy scripts easily with 16M php memory limit. Further if you use PW's markup cache to only generate the list once every hour you would save some resources. Try it and see what you get. If memory would be a problem you might still consider constructing 1 or 2 sql queries and see if it performs better. This surely would involve some complex sql joins over fields, fieldgroup and page tables and make sure pages are published etc.
- 10 replies
-
- 2
-
What field is the field you want to check the same value? If it would be a page field it would be easy with find selectors.
- 10 replies
-
How best to adjust URLs after pre-launch site was in subdir?
Soma replied to MarcC's topic in General Support
Without SQL you could do it with simple bootstrap or in a template: foreach($pages->find("template=basic-page") as $p){ $p->body = str_replace("/newsite/","/",$p->body); $p->save(); } -
Just to make sure some more random thoughts. Any more infos would be helpful. What are the module setting? Have you enabled "Allow Page Numbers" in the template where you want to do pagination? Also try this code along with the pagination code: if($input->pageNum){ echo "<br/>pageNum: $input->pageNum"; } Any Infos on what doesn't work and what it exactly does would also be helpful. Generally any code in templates can maybe be the problem so I'm a little lost here because it works fine here. The url landitus posted is wierd and can't think of why it would be /page2/page2 as this is clearly wrong.
-
How To Intercept <img> elements before page rendered
Soma replied to Gazley's topic in General Support
In a autoload module you could hook the page render and replace all img tags. public function init() { $this->addHookAfter('Page::render', $this, 'hookPageRender'); } public function hookPageRender(HookEvent $event) { $out = $event->return; if(strpos($_SERVER['REQUEST_URI'],$this->config->urls->admin) === 0 ) return; $img_regex = '%(<img.*/>|</img>)%ixU'; $event->return = preg_replace($img_regex, "<div class='img'>$1</div>", $out); } If you want to only replace certain images in the body you could use some markers or a html parser like php simple html dom http://simplehtmldom.sourceforge.net/