Martin Muzatko

Members
  • Content count

    29
  • Joined

  • Last visited

Community Reputation

15 Good

About Martin Muzatko

  • Rank
    Jr. Member

Contact Methods

  • Website URL
    http://www.happy-css.com

Profile Information

  • Gender
    Male
  • Location
    Stuttgart, Germany
  • Interests
    Everything Webdev.
    I'm a passionate Designer and Developer. Always eager to bring love to the world in shape of software and knowledge.

Recent Profile Visitors

2,191 profile views
  1. @matjazp I'm not sure. I made it now work with the following: $data = new WireInputData([ 'email' => $input->post->email, 'username' => $input->post->username, 'species' => $input->post->species, 'firstname' => $input->post->firstname, 'lastname' => $input->post->lastname, 'password' => $input->post->password, 'password_repeat' => $input->post->password_repeat, 'email' => $input->post->email, 'street' => $input->post->street, 'zip' => $input->post->zip, 'city' => $input->post->city, 'country' => $input->post->country, 'birthday' => $input->post->birthday ]); $token = $session->CSRF->getTokenName(); $data->$token = $session->CSRF->getTokenValue(); $post = $input->post; $post->setArray(array_merge($data->getArray(), $post->getArray()));
  2. I've read a lot into this tutorial, which uses the built-in validation: Thank you a lot for that @Soma! Although, CSRF does not work correctly, so I read through this topic here: But I can't find a clue, why when ajax-posting to my form, this fails.
  3. Hey there! I find myself discovering more and more beauty when working with ProcessWire. this render method is also new for me. Thank you a lot for sharing this.
  4. 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
  5. Ugh! This makes sense and it works perfectly. The debug message looked like there was a problem with the result being a PageArray, not that PageArray has no children method. Thank you a lot @LostKobrakai!
  6. Hello @LostKobrakai. As documented for custom selectors for PW 3+: <?php $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'ticket') { $page = $event->arguments('page'); $result = $page->parent()->parent()->children('template=event-tickets')->children(); print_r($result); $event->return = $result; } }); This selection happens from within a Registration. See example structure here: Thank you already!
  7. I found out: Even if the select is a MultiPage Select, I still get the error.
  8. Hello! I'm trying to have a custom page selector as well, but when I select a pageArray for a select field, I get the following error:
  9. Hello! I am using ProcessWire for a good three years now already, and I am really happy with the flexibility it provides. There is one thing though that bugs me. For a recent project, I need lots of templates. I already have a site/templates folder polluted with a package.json, yarn.lock, node_modules, errors, .eslintrc, .git and my entire build setup. And I thought: OK - when I am forced to use site/templates for templates, is it actually correct to put all my javascript, styles, components, functions, classes also there? I mean, at least this is what the default theme encourages (they put styles there also) I read into other posts covering this topic about having a sub folder for templates. Because even with the non-template files stored somewhere else, the template files are still too many. Unfortunately, they also discovered that this is not possible: Sub Directories for Templates Should all template files put under site/templates folder What are your ideas? I already thought about having a page field, that defines the template path from a dropdown, but with this I would only reinvent an already almost working wheel. Thank you for your inspiration. Best, Martin
  10. I want to set published to an earlier date, which is why the snippet below does not help me unfortunately. Looks like there is no way around manually changing this through SQL :/ $page->of(false); $page->status = 2049; $page->save(); $page->status = 1; $page->save(); I guess there is no other way right now? I have to say: it is a bit annoying that I'm faced with choosing either a custom publish-date field, when there is an existing one to do the same, or hacking my way around the built-in constraints of published/created/modified. Thank you a lot already kixe!
  11. Hello! I searched a lot to find various solutions to the problem of setting a custom publish date. Which is a must if you do a redesign of a website and need to write import scripts. Since I can't re-use the database. I understand that there is no field to set the dates for created/modified/published manually, but this should be at least possible with the page API. So I tried to set the published date via API: $page->of(false); $page->published = 1486297829; $page->save(); Which did not work, whenever I ask for $page->published, I get the date back that was first set when publishing the page. So I researched a little more and found that the Page class stores the published date in $page->settings['settings']; (see Github) I also tried $page->set('published', 1486297829); but with no success. Is it possible that this has to be done via SQL? Why? Why can't I use the API? Or do I miss anything? Thank you a lot in advance!
  12. Hello LostKobrakai. That is what I can't do, as I want a generic approach for all data. It does work for this one instance where the field is a SelectOptionInputField. but It will throw errors for other fields. I want a generic solution to get all the data for fields. If I try to retrieve the data No matter if it returns a string or an object with a title. Having to individually pick information depending on FieldClass would mean a lot of extra effort - I want the front-end to handle this. But no matter how I try to get access to the field data, I never have access to the title. This is how the field is set up: Example: Using 'field' => (array) $page->{$field->name} \ Maybe the data in *data.1 is lost because I cast it to a one-dimensional array. 'field' => json_decode(json_encode($page->{$field->name}), true) does not yield any data at all for the field. What am I doing wrong? Thank you in advance.
  13. Hello! I'm building a REST API utilizing Processwire. A problem I currently encounter, is that I need all data from fields. Either I create different objects depending on the field type (which would suck) or I get all the data that I require in the first place with something like (array) $page->fieldname; In Processwire, I would access the title of the select field via $page->fieldname->title so I don't just get the value 1 or 2, but the mapped name of that select option. See specifically the code for the field: 'field' => (array) $page->{$field->name} I'll share my code for GET method below case 'GET': $json = []; $connections = []; foreach ($page->children as $key => $child) { $connections[$child->id] = $child->httpUrl; } $additionalFields = [ 'created' => $page->created.'000', 'published' => $page->published.'000', 'modified' => $page->modified.'000', 'createdUser' => $page->createdUser->name, 'modifiedUser' => $page->modifiedUser->name, 'parent' => (string) $page->parent, 'template' => $page->template->name ]; $json['children'] = $connections; foreach ($page->fields as $field) { $json[$field->name] = [ 'value' => htmlentities($page->{$field->name}), 'field' => (array) $page->{$field->name} ]; } foreach ($additionalFields as $field => $value) { $json[$field] = [ 'value' => $value ]; } break; No matter with what I try to access the $page->{$field->name}. I never get to figure out that I can use "->title" I tried: get_object_vars() get_class_methods() json_decode(json_encode()) (array) and even Reflections to no success. Any idea what I can do to get ALL the data in a JSON friendly manner? See attached the whole code. Thank you already in advance! json.php
  14. Here is what I have done so far: PUT and DELETE is - as already said - very important to tell what should happen with the resource. Which can be compared to CRUD GET - Show content POST - Create content PUT - Update content DELETE - Remove content <?php namespace ProcessWire; ini_set('display_errors', 1); error_reporting(E_ALL); ob_start(); $method = $_SERVER['REQUEST_METHOD']; $json = ['message'=>'NONE']; //$request = explode("/", substr(@$_SERVER['PATH_INFO'], 1)); switch ($method) { case 'PUT': if($user->hasPermission('page-edit', $page)) { $pageFields = json_decode(file_get_contents('php://input')); foreach ($pageFields as $field => $value) { echo $field . " " . $value; $page->$field = $value; //$json[$field] = [$page->${field}]; } $page->setOutputFormatting(false); $page->save(); $json = ['message'=>'RESOURCE UPDATED']; } else { $json = ['message'=>'NOACCESS']; } break; case 'POST': if($user->hasPermission('page-create', $page)) { $pageFields = json_decode(file_get_contents('php://input')); $title = $sanitizer->text($pageFields['title']); if(!$page->children('title != '.$title)) { // create new page, if not already there $p = new Page(); $p->template = $pageFields['template']; $p->parent = $page; $p->name = $sanitizer->pageName($pageFields['title'], true); // URL name $p->of(false); // turns off output formatting $p->title = $title; $p->save(); } http_response_code(201); $json = ['message'=>'CREATED']; } else { $json = ['message'=>'NOACCESS']; } break; case 'GET': $json = []; $additionalFields = [ 'created' => $page->created.'000', 'modified' => $page->modified.'000', 'createdUser' => $page->createdUser->name, 'modifiedUser' => $page->modifiedUser->name ]; foreach ($fields->find('*') as $field) { $json[$field->name] = htmlentities($page->{$field->name}); } foreach ($additionalFields as $field => $value) { $json[$field] = $value; } break; default: //handle_error($request); break; } //ob_clean(); header('Access-Control-Allow-Origin: *'); $content = json_encode($json); //EDIT: My bad! POST is create, PUT is Update
  15. RT @k15tsoftware: Today's #morningtalk: on how rewarding & challenging community service can be from Joshua. Blog post coming soon! https:/…