Members file uploads

  • I have added a few file fields to the member.html template so it looks like below.


    Code
    1. <perch:members type="text" id="first_name" label="First name" listing="true" order="1" />
    2. <perch:members type="text" id="last_name" label="Last name" listing="true" order="2" />
    3. <perch:members id="document1" type="file" label="Document 1" order="3">
    4. <perch:members id="document2" type="file" label="Document 2" order="3">
    5. <perch:members id="document3" type="file" label="Document 3" order="3">
    6. <perch:members id="document4" type="file" label="Document 4" order="3">
    7. <perch:members id="document5" type="file" label="Document 5" order="3">
    8. <perch:members id="certificate1" type="file" label="Certificate" order="4">


    When I create a new member in the backend it shows all the new fields, I can upload files and it all works great.


    After saving the member, these fields are then empty, I try uploading a different file but it wont take the files are still missing on the backend and they are still the origional files from when I created the member on the front end.

  • drewm

    Approved the thread.
  • Sorry, Im creating the member in the backend, when I create the user it takes the file fields and it creates the user like I expect. But when I then go to edit the member again in the backend it shows all the file fields as empty. I try uploading the files again or different files but it still shows the file fields as empty on the backend, on the front end it still shows the original files uploaded when the member was created.


    I have got a bit further in debugging it. When I edit the user it updates the memberProperties column in the database but then doesn't render those changes like its being cached.


    Update

    I have discovered the same issue with the textarea tag, the code below has been updated to fix this issue too.

    Solution

    While PerchFieldType->render_inputs($details) looks for $id in $details for whatever reason PerchFieldType_file->render_inputs($details) looks for 'perch_'.$id in $details doesn't find it and things the field is blank. The front end caches the member details in their session, to clear the cache log out and in.


    To fix the backend copy and paste the below code after the opening <?php in "addons/apps/perch_members/modes/members.edit.post.php".



    Code
    1. $PerchedDetails = [];
    2. foreach ($details as $key => $value) {
    3. if (is_array($value)) {
    4. $PerchedDetails['perch_'.$key] = $value;
    5. } else {
    6. $PerchedDetails[$key] = $value;
    7. }
    8. }
    9. $details = $PerchedDetails;
  • Quote

    I have got a bit further in debugging it. When I edit the user it updates the memberProperties column in the database but then doesn't render those changes like its being cached.


    I was right. The member properties are pulled from the database and stored in the users session at login. When you call perch_member_get to get a member property it comes from the users session not from the database. This means that the database and user session can get out of sync where the backend shows whats in the database and the front end shows whats in the now out of date session.



    To fix the issue


    I added a new function to the end of "perch_members/runtime.php" called perch_member_sync() which updates the user session from the database.



    I then call perch_member_sync(); at the top (before any data is sent to the user) of any frontend page that was giving me issues.

  • Exactly what I needed! You just saved me several hours. Thanks!


    Thank you so much.