-
Posts
6,808 -
Joined
-
Last visited
-
Days Won
159
Everything posted by Soma
-
#1) https://processwire.com/talk/topic/5000-module-repository-last-updated/
-
Use FieldtypeTextLanguage in module config inputfield
Soma replied to Gayan Virajith's topic in Modules/Plugins
This has come up already... Module config doesn't work with language fields. Since its stored as json and you are actually using inputfields here not fields. Look at LanguageSupportPageNames how it can be done. Apart from that your code would be wrong. It's InputfieldTextareaLanguage with inputfield type InputfieldTinyMCE. -
$users->setCurrentUser() does not give desired result
Soma replied to Harmster's topic in API & Templates
$user isn't updated since you're in a template and $user was set before you execute this code. $users->setCurrentUser($u); echo "<br />After setting current user: " . wire("user")->name So the new current user would only be available via wire("user") or $users->getCurrentUser(), that will get the new current user. -
You don't need to overwrite $page. And the 404 is usually: throw new Wire404Exception(); And how about echo $child->render(...); ?. PW never does echo something.
-
RT @colingardom: I just downloaded @bitnami ProcessWire. Check it out! https://t.co/vPAJmsJ98e #applicationawesomeness /cc @processwire
-
One way without module would be to just enbale urlSegments on home/root template. Then do create urls with domain.com/1003 Then in the template something like this: if($input->urlSegment1){ $id = (int) $input->urlSegment1; $p = $pages->get("id=$id, include=hidden"); if($p && $p->id && $p->viewable()) { echo $p->render(); } else { throw new Wire404Exception(); } } else if(count($input->urlSegments) > 1) { throw new Wire404Exception(); }
-
Any more useful infos or code that shows what you're talking about?
-
Ah, sorry it's not $page->pagefieldmulti->has(1001) then it would have to be a selector if($page->pagefieldmulti->has("id=1001")) ... if($page->pagefieldmulti->has("id=1001|1002)) ...
-
Retrieve The Type of A Field From Inside A Module
Soma replied to bytesource's topic in Module/Plugin Development
It's not me it's PW having a designed built in solution. If you hardcodre it into textile textformatter it should be optional. -
RT @processwire: Time how long it takes to do something: $t = Debug::timer(); do_something(); echo Debug::timer($t);
-
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: