Jump to content

Jan Romero

Members
  • Posts

    672
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Jan Romero

  1. Whoops, my bad! I always default to the functions api because of the benefits laid our here https://processwire.com/docs/start/api-access/
  2. As it turns out, I don’t get a notification when you change your reaction to one of my posts, only when you add a new reaction, but I noticed anyway ? You have to get an understanding of how to debug what’s happening. Are you familiar with your browser’s web development tools? There will be a place that shows all requests it sends to your site and their results. You can use this to figure out what is going wrong. This line will initiate a POST request to auction-longpolling.php. Check your browser console to see the response status and its contents. It might be 404 or 403 or something, in which case you’re probably hitting the wrong URL or the server doesn’t allow the PHP file to be accessed that way. If it’s in the 500s there’s probably an issue with the PHP code.
  3. This is roughly what your directory tree looks like: Your file auction-longpolling.php should be in the same directory as index.php and favicon.ico. Then it should be accessible as example.com/auction-longpolling.php. You can test if the file is accessible by just typing the URL into your browser. This isn’t a very processwirey way of doing things per se. You might want to make a special Template and Page for this polling or use a Path Hook or a UrlSegment.
  4. Mh? Doesn’t fetch("/auction-longpolling.php" work? Starting with a slash is always relative to the “origin”. You could also put the full address: fetch("<?=config()->urls->httpRoot?>auction-longpolling.php" etc. (note httpRoot already comes with a trailing slash)
  5. If you look at that file, you see that in line 35 it calls the count() function and passes it the variable $architects. From the error message we know that $architects is NULL. Before PHP 8.0 I believe this would have been fine, but now it’s a fatal error. Further up in the same file, the $architects variable is assigned: $architects = $page->get('architect'); $page is the skyscraper you’re trying to view, so it’s trying to get the value of that skyscraper’s field called “architect”. It’s a page reference field for multiple pages. That fieldtype always gives you a PageArray, so even if the skyscraper has no architects you should still get an empty PageArray and not NULL. The fatal error would not occur. So how could $page->get('architect') end up being NULL? The most likely possibility is that the template doesn’t have a field called “architect”. Now if you check out install.sql, it looks like there is only a field called “architects”, which makes sense because it’s a multiple page reference field. So I’d say you’ve found a bug in the site profile. The line I quoted above should say architects instead of architect.
  6. It used to be on TV in Germany every night, so maybe that? ?
  7. Sorry for unearthing this thread, but I can’t figure this out… https://github.com/processwire/processwire/blob/master/.gitattributes What does "$ cat .gitattributes" do here? I know what cat is, but why is this line in this file?
  8. I feel like it would make more sense to call focus() first and size() afterwards, but I haven’t tested or read up on anything.
  9. Hm, does this still work for you? I just installed it and the download link appears, but it doesn’t seem to accept clicks: Tested it in Default, Reno and UIKit themes, in Firefox and Edge. Maybe something else I’ve done to this install is messing with it, though ?
  10. Sorry for the delay, I’ve posted the PR here: https://github.com/processwire/processwire/pull/251 Since it simply uses an anchor tag with a download attribute, it also allows you to open the full-size image in a new tab using a middle click or “open in new tab”, which is just the behaviour I would expect and seems pretty useful. Your SCSS module is amazing! Unfortunately SCSSPHP doesn’t seem to do exactly what Ryan’s setup does, and I suppose the “self” thing is a bug in SCSSPHP, but a great help nonetheless!
  11. Note that you’re hooking the save() method of “Fields” object. This line makes no sense. I assume you mean “$event->object”, but because you’re hooking a method of the Fields class, I would imagine that will give you the same as wire()->fields(), not the field that was saved. The saved field is the first and only argument of the save() method, so I expect this should work: $field = $event->arguments(0); Apparently, towards the end, Fields::save() also calls Fieldtype::savedField() , so you may want to hook that instead: $this->addHookAfter('FieldtypePassword::savedField', $this, 'updateBlacklist'); protected function updateBlacklist(HookEvent $event): void { $field = $events->arguments(0); if ($field->name == 'pass') { $this->wire('session')->message('works'); } }
  12. Well, for what it’s worth, it’s just a Warning, so it’s not going to crash your site, although it probably will when you upgrade your PHP to version 9 in a couple of years. Since I’m still not seeing the problem in the code you posted, I assume it’s somewhere else. The Warning should tell you a line number to investigate, but also I would advise you to install a PHP language server such as Intelephense for VSCode. It will show you such problems while you write your code.
  13. Is the line that throws the warning within the function you just showed?! Clearly the variable is defined right here: $pageparentdate = $page->parent->auction_end_date; I’m not seeing the problem right now, sorry!
  14. Sorry, I somehow overlooked this line. You can’t compare $page->template to this string because it is not a valid template name. The line will always return because the condition can never be true. I think you probably want this: if (!$page->matches("template=auction-bid, auction_bid_date>={$parentdateminusstart}, auction_bid_date<={$parentdateminusend}")) return; //only continue if the added bid’s auction_bid_date is less than 3 minutes before the parent’s auction_end_date. See https://processwire.com/api/ref/page/matches/.
  15. Now do bd($page->parent->auction_end_date) from inside the hook
  16. @Frank Schneider Did you get it fixed? I fear there may not be enough information here to diagnose it. You should look at the POST request in your browser console and maybe post the (presumably javascript) code that makes the request in this thread.
  17. How are you uploading from the client? Does your form element have the attribute enctype="multipart/form-data"?
  18. It has come to my attention that this is not strictly true. The XHR header makes modern browsers send the CORS preflight request, so requiring config()->ajax for your requests on the server side can save your users from CSRF shenanigans.
  19. I don’t think ProcessWire has this built in. Do you have gaps that you need to skip or maybe show as inactive? If not you can just find the oldest and newest page and iterate between them. Otherwise I suggest custom SQL to efficiently group by something like year(pages.published). I think RockFinder can also group things, might want to check that out.
  20. Works for me... However, a blank value will give you an empty string, so you need to take that into account when you write your comparisons. In PHP an empty string IS equal to 0 with loose comparison, so '' >= 0 is TRUE. To test for blank values, you can just check $page->myfloat === '' or is_string($page->myfloat) or probably a million other things, considering we’re in PHP land. I agree that this isn’t strictly mentioned your screenshot, but it should be. edit: lol turns out they changed this with PHP 8.0, so watch out for that too
  21. remove the s. https://processwire.com/api/ref/page/parents/ https://processwire.com/api/ref/page/parent/
  22. This is apparently a really old hat and common in many editors, but it’s the first I’ve heard of it and it just blew my mind. Did you know you can name heredoc strings “HTML” to get HTML syntax highlighting?! I kind of try to avoid heredoc, but this seems pretty neat.
  23. I mean we still don’t know what exactly you’re doing, but you definitely don’t need #1, it’s just there to show the result of my test POST. You just said you’re using formdata, so DON’T send the urlencoded header. In fact I just tested it with XMLHttpRequest and it also automatically builds the Content-Type header for you, so you don’t need that part at all. Building on my example above, this is all you need: document.getElementById('formdataxhr').addEventListener('click', async function(event) { event.preventDefault(); const request = new XMLHttpRequest(); request.open('POST', './'); request.send(new FormData(document.forms.fruidform)); //or manually use FormData.append() or FormData.set() as you said }); Yes, you need to add the X-Requested-With header, but that’s ONLY there to set ProcessWire’s config()->ajax property to true. Everything else works fine without it.
  24. Here is a minimal example that works for me: <?php namespace ProcessWire; if (input()->post('message')) { header('content-type: text/plain'); //this makes the browser show the "unformatted" response body, i.e. it won’t render HTML die(input()->post->textarea('message')); } ?> <form id="fruidform" method="POST" action="./"> <textarea name="message">&lt;h1&gt;two &gt; one&lt;/h1&gt;</textarea> <button id="urlencoded" type="submit">Tu es urlencoded</button> <button id="formdata" type="submit">Tu es als form-data</button> </form> <script> document.getElementById('urlencoded').addEventListener('click', async function(event) { event.preventDefault(); const response = await fetch('./', { method: 'POST', body: new URLSearchParams([['message', document.forms.fruidform.message.value]]) //you can also make a URLSearchParams from a form automatically, so you don’t have to reassemble all fields yourself: //new URLSearchParams(new FormData(document.forms.fruidform)) }); }); document.getElementById('formdata').addEventListener('click', async function(event) { event.preventDefault(); const response = await fetch('./', { method: 'POST', body: new FormData(document.forms.fruidform) }); }); </script> Observe how you get back “two > one” from the server in both cases. What are you doing differently? Also see how you don’t need to put the content-type header explicitly, because fetch() infers it from the body’s type automatically, but it is sent in both cases! If you look at the unformatted request body in the browser console, you’ll see that the first one is is: message=%3Ch1%3Etwo+%3E+one%3C%2Fh1%3E" message=%3Ch1%3Etwo+%3E+one%3C%2Fh1%3E" That mess of % symbols is “urlencoded” and the request has a header that announces this to the server, so the server will know how to decode it: “Content-Type: application/x-www-form-urlencoded;charset=UTF-8”. It’s called “urlencoded” because it specifically exists to encode GET parameters as part of URLs, but you can use it for POST as well, as you can see. The form-data request body looks like this: -----------------------------9162892302224017952318706005 Content-Disposition: form-data; name="message" <h1>two > one</h1> -----------------------------9162892302224017952318706005-- (Your boundary may vary. The browser generates automatically.) Again the request’s content-type header tells the server that it’s sending this format: “Content-Type: multipart/form-data; boundary=---------------------------9162892302224017952318706005”. If you use XMLHttpRequest, you may need to set the content-type explicitly according to the format you’re sending, I’m not sure, but it can't hurt. Another thing is that these are (I believe) the only two content-types that PHP will put into its $_POST and $_GET variables. That’s why @gebeer’s example had to use file_get_contents('php://input') to get the JSON. Of course you can also send JSON as urlencoded or form-data. Then you can use json_decode(input()->post('myjson')).
×
×
  • Create New...