Search the Community

Showing results for tags 'api'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Found 203 results

  1. I have a hook that creates a page for a subset of the pages on our site. It uses the saved page's name as part of the created page's name. The problem I am having is that my hook, attached to Pages::saved(), is being called even when the page save failed because of missing fields. Is there a way I can tell that the page save failed due to missing fields? Never mind - it does succeed; it just issues warnings about required fields.
  2. Hi, I'm sure this is maybe in the works already, given that findMany() is a recent addition to the API, but having this (and the other new find options) available to $users would be a great addition. Cheers, Chris NB Communication
  3. Hi folks, On the website I am working on I do have a form which needs to be filled in (duh) and when the user clicks on download, the data is send with ajax and processed in the same file by using the ProcessWire API with $config->ajax; The data which is provided by the user will be checked with data in my database. If the data is correct I want to push a file download. But this is not working at the moment. It seems like the content of the (.exe) file is pasted in the console instead of pushing the file. My code looks like this: if ($config->ajax){ $serial = $input->post('serial'); $DB = DB(); $query = $DB->prepare("/*My query here*/"); $query->bindParam("comparision", $serial, PDO::PARAM_STR); $query->execute(); $reply = ''; $SN_rows = $query->rowCount(); if (!$SN_rows > 0) { $reply = 'error'; } else { $reply = 'success'; $installer = $page->attachments->eq(1); $filename = "Filename"; $filepath = $installer->filename; $options = array( 'forceDownload' => true, 'exit' => true, 'downloadFilename' => $filename ); wireSendFile($filepath, $options); } echo $reply; exit(); } What am I doing wrong here or is it a bug? Is there another way to do this with the processwire API? Thanks in advance, ~Harmen
  4. Hi! I have been struggling with this for the last few hours and could not find a solution for it anywhere on the forums. I want to create a repeater field using the API and then add fields to it programatically. I can create the field and assign it to a template alright, but I can't assign any fields to the repeater itself. I've tried using $field->repeaterFields when creating the field but cannot figure out what it's supposed to accept. I tried passing it an array of IDs as well as a fieldgroup, but I couldn't get either to work. Any ideas?
  5. Hi everyone, I've recently hired at a new company and here I am evaluating the abilities of ProcessWire for our projects. I was able to meet almost every requirement so far, but there is one point I couldn't find an adequate solution for: outputting data to json. I am aware of modules like https://modules.processwire.com/modules/pages2-json/ (which does not seem to work for me) but I thought with a function like wireEncodeJSON this should be much cleaner. What I would like to achieve is outputting pages with according field values into an array to use this within javascript. My first attempt on this was: $jsontestOne = $pages->find(1001)->children(); echo wireEncodeJSON($jsontestOne); which outputs [{}] and afterwards I tried that one: $jsontest = $pages->find("template=basic-page")->getArray(); echo wireEncodeJSON($jsontest); which outputs [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},...] Maybe you can point out where my mistake is. Thanks in advance!
  6. When a PageTable field in a specific template is being edited I need to know the Page that contains the PageTable so I can fill in hidden fields in the PageTable. I can capture the page being edited via: // $this->addHookBefore('ProcessPageEdit::execute', ... public function pageEditExecuteBefore(HookEvent $e) { $p = $e->object->getPage(); if ($p->template !== 'rtw-product') return; // $p is the page being edited } I can intercept PageTable entry being saved: // $this->addHookBefore('Pages::save' public function savePageBefore (HookEvent $e) { $p = $this->wire('page')->id; $page = $e->arguments('page'); $obj = $e->object; $name = $page->name; // page name of PageTable page $template = $page->template->name; // template of PageTable page $parent = $page->parent->name; // parent directory for PageTable items What I am trying to find is the page in which the PageTable field is located. I've also tried having pageEditExecuteBefore() saving $p in $this->context and then accessing that in savePageBefore() but it's a different instance of the class because $this->context is null when it gets to savePageBefore(). I could save the page ID in session, but that seems error prone. Does anyone know how to achieve this?
  7. Hello! I'm trying to use the data I create in Processwire as much as possible. So for a form, I try to use the fields description, name and also its built-in validation rules I defined in ProcessWire on the front-end. (minlength, ranges, patterns, etc) I already looked into this tutorial, but it is using external resources to validate the form. Since ProcessWire does all the heavy lifting, when processing data, I don't have to sanitize anything - ___processInput should do the job just fine. However, it is not actually working correctly. $fields = $templates->get('user')->fields; $submission = $input->post; foreach ($submission as $key => $value) { $field = $fields->{$key}; if ($field instanceof Field) { $field = $field->getInputfield($user); $field->___processInput(new WireInputData([$key => $value])); var_dump($field->getErrors(true)); // retrieve validation error } } This works for some constraints, but the values are not correctly validated. Example: All the fields are required and zip is an integer field. Yet, I get no validation error for zip, although it was entered as a string, and not an integer. Funny enough: if I provide a number outside the range, I get "Specified value 2 removed because it is out of bounds (min=1000, max=99999)". firstname will not return any error for being a required field. From what I have looked through the source code, there is no check for "required". Some fields only validate on setAttribute. Am I missing anything or am I doomed to build my own validation process? Thank you in advance! Best, Martin
  8. Do any experts have experience with the level of stability and/or support for turning on $config->advanced? I ask because of the warning at the bottom of the System tab "Please note that all of these system settings are intended for ProcessWire system development (not site development). Use them at your own risk." It provides two facilities that are invaluable to me (maybe because I don't know how to do them any other way). 1) Disable Settings Tab on a per template basis 2) Page Class Name - this makes it tweak a page while relying on the underlying Page class for the majority of functions. Are others using this setting in production? Have you used it over an extended time and seen that it is not changed often or at all?
  9. I have a Page Table field that, for new entries, I want to construct the name for. When I click the Add New button the page being added has already been given a random name like: 20170422-003744. I wish to 1) change that name so it's obvious it is a temporary name and 2) when either Publish or Save + Keep Unpublished is clicked, set the name of the page based on the content entered. What hooks can I use to accomplish 1 and 2? thanks.
  10. I'm trying to create a pagename (for internal use, not for presentation to the users) with multiple dashes in the middle. Here's an excerpt of my code: $p = new Page(); $p->template = 'template-name'; $p->name = "$prod--$variation"; ProcessWire seems to apply $sanitizer->pageName($name, true) which converts multiple dashes to a single dash so the page name doesn't have "--" in it. How can I force it to have multiple dashes?
  11. Good afternoon, I am attempting to loop through approximately 600 XML nodes. Each of those nodes has 2 child nodes (example below). One is an id for an existing page and the other contains values for a page reference field. I have put together a loop (below as well) to attempt to save each page with the label values. This all works....once. After getting the first XML node "label" saved to the correct page, nothing else is saved. I'm sure there is probably something that I have overlooked. But, I am also very new to this CMS. I'm hoping there is a veteran user who may be able to point me in the right direction. <row> <id>1041</id> <labels>lifestyle|savings</labels> </row> foreach ($xml->row as $items) { //get page id to update and set output formatting to false $blog_page = $pages->get('id='.$items->id); $blog_page->of(false); //create array from pipe separated label values $labelsArray = explode('|', $items->labels); //loop through array to get page ids by page name $labelIDS = array(); foreach ($labelsArray as $labelValue) { $labelPage = $pages->get('name='.$labelValue); array_push($labelIDS, $labelPage->id); } //add labels to label field in post $blog_page->labels = $labelIDS; //save page $blog_page->save(); }
  12. We have a three language web site - 'de', 'en', 'fr' with 'de' being the default. There are pages for which we want to use the name (it's unique within its parent-scope) as in the attachment. But when I fetch the name it does not return the name for the language - it always returns the name for the default language (guertel, in this case). I've tried $page->getLanguageValue($lang, 'name'), but name is not a "real" field, so it returns null. I can hack around it by extracting the last segment of the URL associated with that page (which is language sensitive) but it seems like I must be missing something. Is there some way to fetch $page->name for the $user->language setting?
  13. Hi all, I'm just trying to update a custom field value for a page but I noticed in the DB that the old value is still there? Rather than updating, it appears to create a new record for the updated value and increments the sort value. Why is this? Is it not possible to just overwrite the value within the DB using the API? For example: $pageObject->of(false); $pageObject->customField = "Updated Value"; $pageObject->save(); $pageObject->of(true); I would have expected the value just to be overwritten and persisted to the field table in the database? Obviously I am missing something or just not grasping why it works like this?
  14. This is probably really simple but I am unable to get the two letter code for the default language. $languages->default gives me a numeric code (the page ID for that language). $user->language give me the numeric code again $user->languages->name gives me "default" if it is the default language, else the two-letter code for the language. But I don't see the two letter code for the language in $config (I might be missing it) nor anywhere else. I've hardcoded around this now, so the question is largely academic, but I'd prefer not to hardcode it. Being able to get the two character code, and not 'default' for the default language would be equally helpful.
  15. This morning I pushed a module to github which extends the page api with moving and sorting capability. https://github.com/kixe/PageMove * CALLABLE (static & instance) * PageMove::execute($page, $parent = null, $newIndex = 0, $selector = 'all'); * $modules->get('PageMove')->execute($page, $parent = null, $newIndex = 0, $selector = 'all'); * * EXTENDED PAGE API * @method $page->move($parent, $newIndex = null, $selector = 'all') * @method $page->setIndex($newIndex, $selector = 'all') // set absolute index include=all * @method $page->getIndex($selector = '') // same as $page->index without argument @see getSelector() * * @method $page->moveFirst($parent = null) * @method $page->moveLast($parent = null) * @method $page->moveForward($steps = 1, $selector = 'all') * @method $page->moveBackwards($steps = 1, $selector = 'all') * * @property $page->moveFirst // same parent * @property $page->moveLast * @property $page->moveForward * @property $page->moveBackwards * * EXTENDED PAGES API * @method $pages->move($page, $parent = null, $newIndex = 0, $selector = 'all') * @method $pages->resortChildren($page, $selectorValue) * // same like core function $pages->sort($page, true); with capibility to change the sort condition Have a nice weekend.
  16. I am fairly new to Processwire and using APIs and I wanted to implement a certain functionality for one of my templates. Suppose I want all pages that use template A to display wiki content associated with page->title in page->body . For example if page->title is "Google", I want the body to consist of the data present on https://en.wikipedia.org/wiki/Google I understand that one way of doing this is using APIs from Wikipedia (but I do not have good experience in working with APIs) Could someone guide me though the process or point me to an already available module for this functionality in Processwire?
  17. https://bitbucket.org/chimmel/pw-import-shorthand It's shorthand for creating new fields, templates, fieldgroups, and pages via the API. See bb for example usage.
  18. I have a module here https://bitbucket.org/chimmel/pw-import-shorthand that I am using to create an image field like so: $mf[] = [[ 'tags' => $tag, 'name' => $pre.'logo', 'type' => wire('modules')->get('FieldtypeImage'), ],[ 'label' => 'Logo', 'columnWidth' => 50, 'inputfieldClass' => 'InputfieldImage', ]]; Yet upon its creation, initially, when I try creating a page of a template including it, it says that the field must first be configured. Once I go and save the field as-is, everything's honkey dory. It's just an annoyance, with every image field. I figured it would be the required inputfieldClass field field, but as you can see, that's included up in there, and it's still not good to go off the bat. Any clue as to why?
  19. Hi all, I do have a form in the 'backend' of my website which has a fieldtype of ASMSelect. I gave all the options of that field a custom attribute with a value: foreach ($feature_group['features'] as $feature_id => $feature) { $field->addOption($feature_id, $feature['name'], array('data-feature_group' => $feature_group_id)); } How can I read out the value of that custom attribute named data-feature group? I've tried it with $selected_feature_groups = $form->get($category_id)->getAttribute('data-feature_group'); //AND selected_feature_groups = $form->get($category_id)->feature_group; but that doesn't work. How can I get this to work? ~Harmen
  20. I have an already created web app of many php and other files. I want to access the PW API, especially for user info. Do they need to be inside the PW folder to do so? thx.
  21. I am thinking about using processwire for a special task - I have a shopping site with many product categories stored in a category tree. For each category id I want to provide content elements (texts, pictures, etc.) So I would like to import the category tree into processwire and define a template there to hold the content elements. My shopping site then would (via api?) send the category id to processwire and retrieve the content elements for this category id - so far my idea. Is this possible and easy to realize with processwire? Thanks!
  22. i have a page with similar repeater fields of various names, and similar output in a loop so i really don't really want to write endless foreach repeater for rendering but need to aggregate all repeater fields and then pass them via one foreach loop $repeaters=$pages->get("/advert_page/"); foreach($repeaters->fields as $repeator){ if($repeator=="title")continue; echo $repeator->summary; echo $repeator->images->first; } it simply doesnt work, so i have to manually do for each repeater $repeater=$pages->get("/advert_page/"); foreach($repeater->Media as $m) { echo "<img src='{$m->images->first()->size(120, 60)->url}'>"; echo "<p>Year built: {$m->summary} </p>"; } echo '</div><div class="uk-grid uk-grid-width-medium-1-4" data-uk-grid-margin="">"'; foreach($repeater->featured as $m) { echo "<img src='{$m->images->first()->size(120, 60)->url}'>"; echo "<p>Year built: {$m->summary} </p>";
  23. I'm just curious why $page->httpUrl returns mysite.dev/about-us/ When it should return mysite.dev/about-us when the template's settting "Should page URLs end with a slash?" is set to "No" I also noticed $page->url returns correctly mysite.dev/about-us Is that a bug with $page->httpUrl in the Processwire API or am I missing something?
  24. What's the easiest way to retrieve a PageArray -- with an offset and a limit, for use in paginated search results -- that is sorted by title using PHP's SORT_NATURAL instead of alphabetically? I was hoping there was a config setting or API method that would handle it for me, but if there is, I haven't stumbled across it yet.
  25. HI! I'm finding myself more and more balancing making get and post requests to templates or to admin modules, when really it would be nice to send all requests to a API url and get data back or a receipt. My example would be to click a link in an email to then make a setting change in PW, like change a specific user role, or publish a page draft etc. Has anyone done much of this and how did you structure it? I was thinking of maybe creating a template for my API and then using the $input inputs and whether you are logged in or not as starting points for sending data back for my API requests specific to my website (a news site with hundreds of members).