Jump to content

a-ok

Members
  • Posts

    812
  • Joined

  • Last visited

Everything posted by a-ok

  1. Sorry it's the same field... for testing purposes I just tried to find events-detail templates. If you stick your example in a repeater it won't work. $event->return = $event->pages->find("template=events-detail");
  2. Looks like it's to do with it being in a repeater
  3. I even changed it just to find all pages with a specific template (not a repeater) AND to a simple Select field (not ASM) and I get nothing. My PageReference field is in a repeater... could this be something that is killing it?
  4. Thanks, abdus. My PageReference field is InputfieldAsmSelect
  5. Hi folks, I want to return a few repeater items via a PageField and originally I would do this by writing the commented out code in the PHP area provided BUT now it states I should be doing this in ready.php via a hook. I have written the below... following from the example given in the backend but it's not returning anything in the PageField dropdown. The message I set up to do a bit of debugging seems to be returning the correct items. Any thoughts? And am I able to return the title of the repeater item being chosen as the getForPage()->title as shown below (how I previously did it). $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if ($event->object->name == 'home_whatson_article') { $event->return = $event->pages->find("template=repeater_events_detail_dates, events_detail_dates_start_date>today, sort=events_detail_dates_start_date"); $this->message($event->return); /* $options = new PageArray(); foreach ($pages->find("template=repeater_events_detail_dates, events_detail_dates_start_date>today, sort=events_detail_dates_start_date") as $e) { $e->title = $e->getForPage()->title; $options->add($e); } return $options; */ } });
  6. I'm sure I've seen something like this somewhere in either the modules or on one of @ryan's blog posts but I can't seem to find it anywhere. I current have 6 text fields which are meta details that relate to a project (size, year, location, status etc) – some of them are filled out/used and some aren't depending on the project. On the front-end these fields link up to a label and icon. The client is wanting to add to the list as they see fit (add a label (multi-language), text (multi-language) and icon (image upload)) so my thought would be to add make this into a repeater field – the issue is that most of the original 6 text fields (size, year, location, status etc) are applicable per project so to have to re-add them every time per project to a repeater is a bit tedious. The client also wants to be able to drag/drop the order of these fields so I can't simply create these 6 fixed text fields then add a repeater for extra fields. You see my issue. I'm sure something existed that allowed you to set some pre-defined defaults for a repeater/table then you can add more to them. Ideally, it would be possible to add more, choose the order they appear in across projects, edit headlines, edit icons, and they would be conditional on the front-end based on whether anything was input in them. Let me know if I'm missing something obvious or if this just doesn't exist Thanks!
  7. Thanks, Adrian. I managed to bootstrap in PW and change it all to $session and it worked! Must be that it doesn't like the multiple variables... although it does say this on the $session API page https://processwire.com/api/variables/session/ I hate not knowing why it wasn't working but I had tried and tested everything until using $session worked so perhaps that was just it. Re PayPal... not I'm not... I'm using something similar to this: https://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html and https://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/ExecutePayment.html and relying on the Approval URL. What do you think? Thanks again for all your help.
  8. Thanks for the help, Adrian. I'm really struggling to work this out. Basically I am using the PayPal PHP SDK and upon submission, using $.ajax I am passing the data (which is localStorage) to a page payment__paypal.php (which sits in the directory /api/ alongside /site/ and /wire/. From here I declare the PayPal API stuff and set my $_SESSION['formData'] = $_POST['formData']; and then on redirects to the homepage from PayPal (once successful) where I have <?php require('../../api/redirect__paypal.php'); ?> included in my head.inc. In this file it takes the $_SESSION['formData'] and does a few things with it, or at least it should. If I redirect from PayPal directly to this file (rather than the homepage with the file required) it works fine but for some reason it's not storing the session when I use the require on the homepage (head.inc). If I add $_SESSION['test'] = 'hello_world'; in the redirect__paypal.php file it seems to add it to the $_SESSION if I var_dump it on the homepage so I'm unsure why the $_SESSION['formData'] isn't being saved across? I realise this is perhaps more a PHP issue than a PW one but it's weird it works outside of the non PW page.
  9. Does PW unset the $_SESSION at all?
  10. I'm setting $_SESSION initially out of PW then calling it in head.inc but always returns NULL when returning it. I'm confused too. I could try and use PW's $session within head.inc.
  11. I need to add some saved $_POST data into a $_SESSION. This works fine on a page outside of PW (templates) but isn't returned on any page of PW (within a template or head.inc). I believe this is because $_SESSION is already started. Is there a way to push my $_POST data into the $_SESSION? $_SESSION['formData'] = $_POST['formData']; On a page within PW it is returned as NULL.
  12. Whoa array_chunk is great. That's good to know that PW API doesn't have a chunk method... always try to use the PW methods. Much appreciated and apologies if that felt like a simple PHP question!
  13. Hi folks, I have an image field, that has 50+ images (the total count varies per project) and I want to split them into groups of 15 (so if the total count is 50 the groups would be 15, 15, 15, 5 and if the count is 12 then it just shows twelve). I'd then be keen to loop through each 'group'. Any thoughts how I would do this using the PW API? Is it possible with only the API or would I have to use some non-API PHP? I was thinking I could use splice with a count but unsure if I need to create a new array per group each time?
  14. This is what I had to do... if ($result->next("include=all")->id != 0) { $next = $result->next("include=all")->id; // Next test element in the repeater } else { $next = $result->siblings("include=all")->first->id; // If next doesn't exist (end of repeater rows) then back to start }
  15. This seems to now work... partially if ($result->next("include=all")) { $next = $result->next("include=all"); // Next test element in the repeater } else { $next = $result->siblings->first; // If next doesn't exist (end of repeater rows) then back to start } Only issue is that the if condition isn't returning false or NULL to then go back to start.. it seems to return '0'.
  16. I believe it may have something to do with the ->next() method... https://processwire.com/api/ref/page/next/ // Get the next sibling, even if it isn't viewable $sibling = $page->next("include=all");
  17. Definitely works when logged in and returning values fine... must be a permissions thing.
  18. Yep, it all works when I'm logged in... but when logged out it doesn't. Hmm...
  19. I thought as much but this seems to only work when I'm logged in... <?php if ($this->input->post->action == 'randomTest') : // Get random test ?> <?php $pageID = $sanitizer->selectorValue($this->input->post->pageID); $testID = $sanitizer->selectorValue($this->input->post->testID); $result = $pages->get("id=$testID"); $text = $result->typefaces_detail_tests_text; // Random test text $size = $result->typefaces_detail_tests_size; // Related font size from random test text if ($result->next->id) { $next = $result->next(); // Next test element in the repeater } else { $next = $result->siblings->first; // If next doesn't exist (end of repeater rows) then back to start } return json_encode(['html' => $text, 'size' => $size, 'next' => $next->id]); ?> <?php endif; ?> $('.typeface__toolbar .reload a.trigger').on('click', function(e) { e.preventDefault(); var $this = $(this), pageID = $this.attr('data-page-id'), testID = $this.attr('data-test-id'); $.ajax({ url: rootURL + 'ajax/', type: 'POST', dataType: 'json', data: { 'action': 'randomTest', 'pageID': pageID, 'testID': testID }, success: function(data) { console.log(data); }, error: function (data) { console.log(data); } }).done(function(data) { console.log(testID); }); });
  20. I'm wanting to retrieve a repeater (via it's page ID) and was currently using this (with $testID being the returned repeater item page ID) $result = $pages->get("id=$testID"); This works fine when I am logged in (as superuser) but when logged out it returns null (I guess because it's an admin page). I have tried doing this with no such luck... $result = $pages->get("id=$testID, include=all"); Any ideas? Thanks.
  21. This is what I ended up doing... On each of my templates I added an include to languages.inc and in languages.inc I have the following... <?php $languages_array = array(); foreach ($languages as $language) { $url = $page->localUrl($language); $languages_array[] = array( 'url' => $url ); } $language_json = json_encode($languages_array, true); ?> <script> var languages = <?php echo $language_json; ?> </script> Then in my JS wrote a function that updates the values of the language switcher URL from the json outputted per page load. function languagesUpdate() { var language1Url = languages[0].url, language2Url = languages[1].url; $('aside.main ul.languages li').eq(0).find('a').attr('href', language1Url); $('aside.main ul.languages li').eq(1).find('a').attr('href', language2Url); } Then I called this function when the AJAX was successful and seems to work a treat. Maybe this'll help someone!
  22. Hi all! I'm using a language switcher on a site I'm building, and previously this has worked fine but as I am now using AJAX (and the language switcher is located in the head.inc file (which won't get called again while AJAX'ing between pages) I'm curious to know if anyone has implemented a multi-language switch on an AJAX-driven site. This is my simple switch. <ul class="languages"> <?php foreach ($languages as $language) : ?> <?php $url = $page->localUrl($language); ?> <li class="<?php if ($user->language->id == $language->id) : ?>is--active<?php endif; ?>"> <a href="<?php echo $url; ?>"><?php echo $language->title; ?></a> </li> <?php endforeach; ?> </ul> I had the same problem changing title tag/body classes as you switch between pages, so perhaps the solution is a similar one? <noscript data-title="<?php if ($page->id == 1) : ?><?php echo $pages->get("name=site-settings")->settings_site_title; ?><?php else : ?><?php echo $page->title; ?> – <?php echo $pages->get("name=site-settings")->settings_site_title; ?><?php endif; ?>"></noscript> <meta name="body-class" content="<?php echo $page->name; ?> <?php echo $page->template->name; ?>"/> Then, for example, when my AJAX is successful... var bodyClass = $('meta[name=body-class]').attr('content'), if (bodyClass !== undefined) document.body.className = bodyClass; Otherwise it just takes it server side from the head. Do you think I need to set up something similar for the language hrefs? Any thoughts are most welcome. Thanks!
  23. Thanks for your help everyone. Should I report this bug on Github, or?
  24. Thanks for the help. Yeah... bizarre. I've always used 1, 2, 3, 4 etc but this time I needed higher values. I managed to edit the DB values directly and seemed to work fine so perhaps a bug as you say.
  25. I'm defining some options in the Select Option fieldtype as follows: 1=Kalundborg Red 1035=Education Teal 1036=Living Orange 1037=Good Life Blue 1038=Careers Cyan However on saving the field it resets them to 1=Kalundborg Red 2=Education Teal 3=Living Orange 4=Good Life Blue 5=Careers Cyan Any reason why I cannot specify the unique ID to use?
×
×
  • Create New...