-
Posts
6,798 -
Joined
-
Last visited
-
Days Won
158
Everything posted by Soma
-
I'm out.
-
Yes! A page field with multiple options, it's an PageArray. $pageArray->implode() is one utility to deal with it. Or just use on of the array methods you also see on cheatsheet. Others useful things are $page->pagefieldmulti->first()->title; Translates to: "currentPage->thepagefieldpagearray->thefirstinthearray->itstitle" Or in a foreach foreach($page->pagefieldmulti as $selected) echo $selected->title; Or to search and check for if a certain option is selected if($page->pagefieldmulti->has(1001)) echo "option page with ID 1001 is selected"; has($page) return true if the PageArray of the field contains the page you give it. $page->pagefieldmulti->has($someotherpage); Since the options of a page field are also pages, it may get clearer if you try to think of it as a array of pages. Many methods accepts various things like a string or object or int of an ID maybe even a path like "/some/path/to/a/page". Just play and experiment with it and see what works.
-
Ah the staff just sent me over... it's "questions/time" award. Sorry.
-
Oh and cheatsheet v2 extended reloaded is coming sooner or later to your nearby shop. Just append a variable name manually at the end of url. Like cheatsheet.processwire.com/page/.
-
One is certain you won the time/question award. You need to fix the logic here I think anyway but. The field here just returns a value as you see. There's no name or title. You would grab the field VIA template or fieldgroup. There it's an field object you can get label or description. I would go for a page field with input checkboxes.
-
Keyword would be most likely urlsegments.
-
Sorry, me again. This works too and may best option with page arrays where you have an id. if("{$a1->sort('id')}" == "{$a2->sort('id')}") echo "identical"; Sort them by id first and put into quotes to make them both a string, if string is same they were identical. To go further, you could extend the PageArray with a new method. This can be done with a simple hook. For example in your templates init: wire()->addHook("PageArray::compare", null, function($event){ $a1 = $event->object; $a2 = $event->arguments(0); $event->return = "{$a1->sort('id')}" == "{$a2->sort('id')}"; }); Then you can use it everywhere in your templates like this if($a1->compare($a2)) echo "identical"; If you the hook to an autoload module like the HelloWorld.module you could use this method throughout PW.
-
Just trying and while it works at first with two identical arrays, throwing in some different sorting it doesn't seem to work. Hmm. Edit: I think it should work, but got some wierd result could be me aswell I think there's another simple way when dealing with page arrays but will test some. Edit: Ah, I combined limit=N with sort...
-
Works too (with WireArray/PageArray) the trick is to add the two arrays together, PW will remove dublicates. So you can compare count after "merging", if result is different they're not identical. $orig = clone($a1); if($a1->add($a2)->count == $orig->count) $is = "identical"; Edit: hmm, too soon. small correction, needs a clone to keep original array in memory
-
Retrieve The Type of A Field From Inside A Module
Soma replied to bytesource's topic in Module/Plugin Development
I'm not sure I fully understand, it doesn't get called also on FieldtypeTextareaLanguage. And how do you now if you say you only use FieldtypeText and FieldtypeTextarea? One thing I could imagine is that FieldtypeText is base fieldtype for a lot of the other text fieldtypes, but testing here it works fine and only is replacing for the FieldtypeTextLanguage. -
It's simple: You have that function function limit_words($string, $word_limit) { $words = explode(" ",$string); return implode(" ",array_splice($words,0,$word_limit)); } A simple call to use this function would be $shorty = limit_words($child->body, 20);
-
I posted the solution in all login script threads... read the previous page of this thread quickjeff.
-
What you can also use, where PW does its validation is the processInput() of inputfields. You can hook into it and do you validation and add errors as needed. $form->addHookAfter("processInput", null, "formValidation"); function formValidation($event){ $form = $event->object; $email_inputfield = $form->get("email"); if($email_inputfield->value == "spam@hotmail.com"){ $email_inputfield->error("We got you!"); } } // direct on the inputfield type wire()->addHookAfter("InputfieldText::processInput", null, "validatText"); function validateText($event){ $inputfield = $event->object; if($inputfield->name == "username"){ ... } } And there's also the HTML5 regex pattern that can be used.
-
What I use in front end from is doing my own validation when needed, some fields are already validated like password inputfield or email inputfield. On a register form I have something like this for example, combined with jquery validation for client side validation... if($input->post->register) { // processes form, validates and add error messages to fields $regform->processInput($input->post); // check email unique if any if($sanitizer->email($regform->get("email")->value) != '') { if(!$helper->isUniqueUserEmail($regform->get("email")->value)){ $regform->email->error(__("Diese E-mail wird bereits verwendet.")); } } // check username format only a-z0-9-_. $username = $sanitizer->pageName($input->post->username, Sanitizer::translate); if($username != $input->post->username){ $input->post->username = ''; $regform->username->error(__('Benutzername ist nicht im richtigen Format.')); } // check if username ($user->name) unique if(!$helper->isUniqueUsername($username)){ $regform->username->error(__("Dieser Benutzername wird bereits verwendet.")); } if(!count($regform->getErrors())){ ... I have helper functions like isUniqueUsername etc, that is at the same time used in jquery validation via ajax. Depending on your knowledge and how fluent you are with PHP and PW, I find it easy to add my own methods or checks where needed and found use of any external validation class not needed (was using that before).
-
Looks more like dr dree headphone logo.
- 6 replies
-
- 2
-
- processwire
- oxford dictionary
-
(and 1 more)
Tagged with:
-
Just published an new article. Tutorial: Add custom JS in ProcessWire admin. http://t.co/pqw79Q51t3 #processwire #cms
-
UPS. My old brother... cheese we are screwd
-
I did it again http://soma.urlich.ch/posts/custom-js-in-processwire-admin/
- 10 replies
-
- 14
-
It may a good one to add a naming convention for quality 500x0-70? The quality setting is relatively new.
-
This is also wrong board.
-
Just as side note: $category_ids = $category->__toString(); You never need to do this, toString is a magic method that does automatic if you write: $category_ids = $category; Or simply $categories = $pages->find("template=category"); $articles = $pages->find("template=articles, parent=$categories");
-
Um no, It does save as it should for me. No matter If I specify 1 or 0 as the default in construct, if checked and saved, fname: 1 is saved to db (without the "workaround”) and when I uncheck and save the fname: 1 is cleared and no value in db, as it should. As said, in you don't specify a uncheckedValue it will always be checked, cause there's no value saved for unchecked and on load it will set 1, and not overwrite it as there's no value coming from db.
-
In case of checkbox, by default behaviour unchecked is NOT saved in DB, that's not a bug but a feature. No need to store a value, this is to either keep the logic of checkboxes and not waste space in DB. This only is an issue if you want to make the checkbox checked by default, even if you won't find any checked checkboxse by default in PW. Because it a better pattern to most of the time to inverse the logik and check a box to disable something, not the other way around. But for this case of still wanting to do the default 1, you can set the checked and unchecked value to make sure unchecked is a value that is saved.
-
It's a feature not a bug.