Building CRUD apps with Perch Runway

  • I've recently released Pipit Members v1.1.0 which makes it easier to allow members (registered with the first-party Perch Members app) create/edit/delete collection items via Perch-templated forms:




    This essentially makes it easier to build CRUD apps with Perch Runway without having to write your own custom Perch apps. You would use:


    I'm posting here to open a dialog with other developers. So feel free to share your thoughts, request features that would make it even easier for you or ask questions.

  • If I have a Collection of member biographies (with different field types like text and image), does this mean that a member or admin user would be able to edit these?


    Yes! Someone who's registered as a member via the Perch Member app would be able to edit this.




    A member should be able to edit their own biography not others. Is that possible?

    Assuming the collection items are linked to the relevant members (e.g. by relating them using the Members field type), you can only display the edit form to the relevant member.


    In a member-only page, you can filter by the member ID:



    And you can expand this to a list/detail pattern where the member is allowed to create/edit multiple items (e.g. a ticketing system):



    So you are controlling what items a member edits.


    The one thing this lacks right now is stricter checks at the form handler level. While the form is CSRF protected, a malicious user technically can edit the values of the hidden _id and member fields on the form.


    Normally you'd check the logged in member submitting the form is the same member linked to the item. The reason I have not implemented this check in Pipit Members yet is I find the identifying link to the collection item is not necessarily the member ID. So I'm working on implementing a way to allow you (the developer) to define this check.

  • I've added Pipit Members folder to perch/addons/apps and edited my apps.php file but I'm getting this error:


    PHP Fatal error: Cannot declare class PipitMembers, because the name is already in use in /perch/addons/apps/pipit_members/lib/PipitMembers.class.php on line 3


    ... which means I cannot see Perch admin. If I delete the Pipit Members folder, I can get back into Perch admin.


    Have I done something wrong here?

  • Loving the idea of allow website members to create collection items from frontend forms, but I must be doing something wrong, nothing happens when the form is submitted.


    I have this on a 'create' page:

    PHP
    1. <?php
    2. perch_template('content/qaa/create', [
    3. 'token' => perch_member_get('token'),
    4. 'member' => perch_member_get('id'),
    5. ]);
    6. ?>

    And this in the 'create' form template:

    Form outputs fine with values in hidden fields, but when I add a value for 'business_name' and submit. The page reloads and nothing is added to the 'QAA' collection. What am I missing?

  • Hey Brad,


    The rendered HTML should include the token value. I think you also need to assign the token value on the input tag (apologies as I don't think the docs specify this). Since you're using perch_template(), you need to use the perch:content namespace.


    HTML
    1. <perch:input type="hidden" id="token" value="<perch:content id="token">">


    You're also passing the member ID, but not using it within the form 'member' => perch_member_get('id'),. If you have a field in the collection to record the member, you also need to pass the ID at the moment. More details on this is in the docs.




    If you want to see Perch form errors in the debug message:

    PHP
    1. // all forms on the page
    2. PerchUtil::debug($Perch->form_errors);
    3. // specific form
    4. PerchUtil::debug($Perch->get_form_errors($formID));