modifiedcontent

Members
  • Content count

    106
  • Joined

  • Last visited

Community Reputation

17 Good

About modifiedcontent

  • Rank
    Sr. Member

Recent Profile Visitors

799 profile views
  1. I had to add this... && $_FILES['headshot']['name'][0] != '' ...to this bit... if($input->post->img_upload && $_FILES['headshot']['name'][0] != '' ) { That was the only way I could find to prevent Internal Server Error if someone clicks submit without selecting a file. Is there a better, more Processwire way to do this? $input->post->headshot etc. doesn't work.
  2. ankh2054, we can't get this code to work here. What are we doing wrong? Shouldn't it be possible/easy to get the same image upload UI as in the admin area? Or some other cropping or centering tool? Any jquery script would work or mess up the system?
  3. Edit: I had posted here because I thought this didn't work: But it does work. The images just don't end up where I expected them - the 'headshots_uploads' directory is supposed to stay empty? You can see the result of the upload with: There should be a headshot/avatar field in the user template. It can get confusing if you have some kind of custom user profile page; you have to make sure you get the avatar of the relevant user instead of the logged-in user. And the upload is saved to $user, not the $page the form is on. There is no way to get the nifty image upload from the admin area on the front end? Edit: I have added $user->headshot->removeAll(); because I kept seeing old avatars. This way you can only have one image in the field/array, so you can't have a feature where the user can swith between uploaded avatars. Is there a more elegant way to "refresh" or make sure that only the latest modified profile picture is shown? Edit2: If you click Submit without selecting an image, you get an Internal Server Error. So I guess you need a check if the input field is empty or not. How do you do that in Processwire? What I have tried so far - adding && $input->post->headshot to the first if statement etc. - didn't work.
  4. Nevermind. Long post deleted here. Sorted it out here.
  5. I am trying to do the same thing as adrianmak - had you figured out how to do this? Do you need the 'current password' field? I think 'new password' and 'confirm new pass' should be enough if the user has access to this form. Or am I missing something? You can use $user->pass->matches($inputPass) to check the input, but, to be clear, there is no PW function or similar that adds the same 'change password' thing that is in the admin profile edit? Password is the same as any other input field? You can save a password from a form input simply with this? ... $user->pass = $sanitizer->text($input->post->pass); $user->save(); And then PW takes care of the hash stuff? The hash stuff is confusing... Or are there specific password checks or processes to take care of? Edit: I see there is an InputfieldPassword.module, probably part of the forms API that I still can't wrap my head around. I guess you should use that somehow? Adding this, as a quick test, produces a server error:
  6. I keep running into $p = new Page(); and $u = new (); , but how do you update an existing page or user? 'current Page()'? Do you have to define $p = current page? What is the proper process? Edit: Nevermind. I guess this is the basic process to update an existing user?
  7. Thanks Zeka! This works: function qa_get_public_from_userids($userids) { global $users; $useridtopublic = $users->find('id=' . join('|', $userids))->explode('fullname', ["key" => "id"]); return $useridtopublic; }
  8. $userlist is not an array - at least my version via $users-> and global. var_dump($userlist) produces a server error. echo $userlist displays a piped string of ids. I can't get wire() to work in the external script. In which file should I add 'namespace ProcessWire'? The function is in another script that bootstraps PW by including the index. Shouldn't that be enough? The var_dump(wire()->users->find('id>0')) results do not look like anything my script could use. Is there no simple way to convert a piped string into an array?
  9. I keep getting 'PHP Fatal error: Call to undefined function wire() ...', with or without '$config->useFunctionsAPI = true;' in the config.php This version had no error, but returns an empty (0/null) array: I have been trying variations of this for the last two days, going in circles. I have a custom field 'fullname', so ignore that, could be 'name' instead. Will try again later... I'd like to try array_combine or something like that. I'd need two valid arrays. var_dump($userids) returns a healthy looking array. Getting that second array of fullnames is my problem. Or would it work if I can get wire() to work? $userlist is not an array, so that foreach can never work?
  10. Thank you abdus ! I had come across array_combine, but had no idea how to use it. I have now tried something like this: function qa_get_public_from_userids($userids) { global $users; // build a selector like id=1|2|3|4 $userlist = $users->find('id=' . join('|', $userids)); $names = $userlist->getProperty('fullname'); // create an array of [username => userid] $useridtopublic = array_combine($userids, $names); return $useridtopublic; } That still doesn't work; $userlist is not an array, but a "piped string" (?) of user ids. Same as $userids, but another format. Can $users->find be used with multiple selectors? Or did you really mean to use 'users()->find'? users()->find produced server errors for me. The $names line should probably be a foreach loop? How do you get a key/value array out of a foreach loop? That is one of my main questions that I keep running into. Will try again tomorrow...
  11. I am trying to integrate another script, Questions2Answer, with Processwire user management. The script needs an array with key/value pairs for user->name => user->id The script provides an array $userids with active user->ids that looks like this var_dumped for a page with two users: array(2) { [0]=> int(1107) [1]=> int(41) } How can I take $userids, find the corresponding $user->names in Processwire as values and then return that to Q2A as a clean key/value array? This is probably basic PHP, but I have tried so many variations that I now completely lost the plot. Any pointers appreciated.
  12. Thanks! This worked: $news = $pages->find("template=post, sort=-created");
  13. Dumb question coming up. I can't get sorting to work. I show child pages (posts) of a parent page (news) on the homepage with this in the template: $news = $pages->find("template=post"); foreach($news as $post) { ... Sort order setting in the template or page is apparently ignored. The sort order is correct in the admin area, but shows up wrong on the home page. What am I missing?
  14. adrian's solution works well, but causes an internal server error on one page that loads an external script: 2017-04-02 07:06:03 guest http://mysite.com/http404/ Error: Cannot redeclare setRedirect() (previously declared in /var/www/html/site/assets/cache/FileCompiler/site/ready.php:5) (line 5 of /var/www/html/site/assets/cache/FileCompiler/site/ready.php) Renaming the function did not fix it. Don't have time to dig into this right now. Leaving this note here and will report back...
  15. Thanks adrian ! Yes, that does seem to work. I have seen another hooked function like this: $wire->addHookAfter ... Is wire() and $wire and wire-> etc. all the same? What's what? I guess I'll have to study up on that... And would this work within the templates folder, in a functions.php or something like that? I'll have to try that... The ready.php file is awkward.