Jump to content

Jan Romero

  • Posts

  • Joined

  • Last visited

  • Days Won


Jan Romero last won the day on January 5

Jan Romero had the most liked content!

1 Follower

Profile Information

  • Gender
    Not Telling
  • Location

Recent Profile Visitors

14,447 profile views

Jan Romero's Achievements

Sr. Member

Sr. Member (5/6)




Community Answers

  1. @ryan Have you considered putting some new screenshots here? It’s a very popular feature judging from showcase threads, developers here love to show off their images to great effect (it was also asked about in this recent thread, for instance), but it gets almost no love in the public docs/store page, and even in the introductory blog post it can only be seen for a split second in the video. The images in the video are also kind of grey in comparison to @olafgleba’s beautiful display 😄 I’m sure showing it off on the store page would boost sales some!
  2. These always trip me up, I get all excited by a big blog post and then it turns out I already know everything from following your lovely weekly threads 😄 Great stuff as always!
  3. Repeater fields give you a PageArray. Have you tried getPageByID($id) to retrieve the item? Check the return value before removing. It might be NullPage, or when using get() it might be null. As a matter of fact, since you already know the ID, it should be perfectly safe to just delete the page: $pages->get($id)->delete();
  4. @fruid Admin pages are just pages in the admin branch of the tree. The ones ProcessWire ships with as well as those of some modules (e.g. Adminer) use a special admin template, but you can just put any old page there. So I would just make a new template with the things you need and create a new page under Admin and set it to hidden and unpublished. When the form is submitted you can get the page by its ID, add the submitted data to it and save.
  5. Well, once you have the submitted data, you can do with it whatever you want. It really depends on what the data is and where you want it. In my comment above the example is one email address and one comment. So if you want to store those things in your admin page, its template would need a way to store multiple email-comment pairs. That could be a Repeater or a ProFieldsTable (👌) or a custom fieldtype. You could also store one new page per submission as a child of your admin page (that’s essentially what a repeater would do behind the scenes anyway, it just looks different in the page tree and page editor – pretty much a matter of preference). Having a page per submission takes care of some stuff you probably want anyway automatically, such as storing the creation date. It also gives you a url for each submission that you could put into an email notification for yourself, or something. My comment gives a pretty complete example of how to get the data from the user’s browser into ProcessWire’s database. Are you struggling with anything specific?
  6. Hi. You're using $input->get('doc') in a couple of places, but the files are sent in a POST request. Also, check out this thread, especially the bit about "new WireUpload()": Additionally please note how the code blocks are formatted in that thread. Please do the same when posting lengthy code excerpts. You can click the button labelled "<>" above the text editor to insert a code block and even choose the programming language there.
  7. In addition to the other very valid comments, this is what’s causing the problem as I understand it. ProcessWire will still prepend _init.php for Ajax requests unless you tell it not to. One way might be to wrap these two lines in an if-block in config.php. That will disable the prepend/append files for all Ajax requests, which seems reasonable: if ($config->ajax) { $config->prependTemplateFile = '_init.php'; $config->appendTemplateFile = '_main.php'; } A more flexible approach may be to forego auto-append and just call those files explicitly when you want them. To expand on @szabeszs comment, $config->ajax works by detecting the header “X-Requested-With”, which browsers don’t send by default. If you’re using XMLHttpRequest, you need to add it like this: var request = new XMLHttpRequest(); request.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); If you use the Fetch API, there is a Headers() object you can pass: https://developer.mozilla.org/en-US/docs/Web/API/Headers Jquery sends the header automatically, which is. I believe, why ProcessWire expects it.
  8. Perhaps you can just run your code after saving? $wire->addHookAfter("Pages::saved", /* … */); Also worth noting is the hook Pages::savedPageOrField.
  9. +1 for installing Decimal by default and perhaps even making Float uninstalled by default.
  10. Hi @xportde. That field is not part of a stock ProcessWire installation, afaik. It is installed by the SystemNotifications module that was introduced in this blog post: https://processwire.com/blog/posts/processwire-2.5.3-master-2.5.4-dev/ The module comes with PW but is not installed by default (maybe it is with some site profiles?). Uninstalling the module automatically removes the field as well.
  11. What happens when you run that code? The delete() method returns a boolean, try logging it to narrow down the problem. Btw, you don’t need to pass $pages to your function. This should work too: $hidden = $pages->find("template=cast, status=hidden"); deleteHidden($hidden); function deleteHidden($hidden) { foreach ($hidden as $item) { $item->delete(); } } Do these pages have children by any chance? In that case you should get an exception unless you move them away first, or specify that you want to delete them as well, using $item->delete(true).
  12. What do you expect $s->cast_language->title to be here? $s->of(false); $s->cast_language = $s->cast_language->title.'|'.$language; $s->save('cast_language'); As I understand it, cast_language allows multiple selection, so it’s nonsensical to access an option’s title without determining a singular option first. Multiple selection options fields have WireArray values, so I feel like this might work: $s->of(false); $s->cast_language = $s->cast_language->implode('|', 'title') . '|' .$language; $s->save('cast_language'); I agree that’s a bit ugly, but there is probably a better way. I’m guessing $s->cast_language->add($language) won’t work because it’s not a WireArray of strings. Probably only works if you pass a SelectableOption. Honestly, just always use $page->save() (in this case $s->save()), unless you have a specific reason not to.
  13. Yeah but still, count_years is always going to flip on New Year’s Day, so if you’ve been placing great value since December 31st, it’s going to say 1 year even though it’s barely been a day.
  14. Btw, just subtracting years from each other may yield unexpected results if you’re thinking in terms of “birthdays”, as most people likely will. That is, considering your example of 1980-07-01, right now you would get 42. If that’s a person’s birth date we would think of them as 41 years old, though. Also, I realize your site is probably not in English, but as I understand it, this is one of the classic “false friends” where “since” feels like the German “seit”, but unlike “seit” it’s not used with time spans: (I. e. you would only say “since 1980” or “since the relaunch”.)
  15. Since these tags are introduced by CKEditor you know they’ll always be there and always look the same (I guess). So you can pretty much just count how many characters you want to skip at the beginning (3) and end (4) and do it without ever mentioning anything about <p> and </p> to PHP: $bodyCopy = mb_substr($pages->get("/nastavitve/")->kontaktni_podatki, 3, -4); Or you can go the replace route: $bodyCopy = mb_ereg_replace('^<p>|</p>$', '', $pages->get("/nastavitve/")->kontaktni_podatki); Note how using mb_ereg_replace you don’t need those annoying slashes. The regex ^<p>|</p>$ just means, “find a <p> at the beginning OR a </p> at the end”, so this leaves all the inner p-tags alone. You can get more fancy if you need to take into account all the ways a HTML tag might appear, but eventually you’ll get into this territory. There is also the ol’ strip_tags function and ProcessWire ships with a Textformatter module called ParagraphStripper, I believe. As well as HTMLPurifier if you really want to get your hands dirty.
  • Create New...