0

I have a form for people offering or requesting to share-a-lift to an event. I'm using the Guest Entries plugin.

But I need them to be able to edit and delete those entries, as once a pair are matched up they need removing from the list of offers/requests to avoid multiple offers.

I have a page with the list of the lifts on offer or requested and have a link from each of the entries to the form page but with the entryId as segment 2.

How do I code the Delete button? (turns out you can't)

I appreciate that this is not the most secure way of doing things, but the client has been using a similar form/method on their old site and have not had any fraudulent or malicious issues in many years. If anyone can suggest a more secure method without any logins or registration I'm open to ideas.

The final solution

As you can't delete or edit Guest Entries @carlcs came up with the idea of allowing a second entry (in another entry type) with a common field to the first.

In the template listing all the offers and requests you look for entries from both entry types with a matching field, and if a match is found don't show either. See the code in his answer for the details.

4

What you could try is to use the Preparse plugin and add a field to your entry type that automatically generates a secret key for each submitted entry.

Show the user this key on the page they are redirected to upon form submission, tell them to write it down.

You now set up a new guest entry form to submit matches. So instead of deleting entries, the user enters his personal secret key into a field to submit a new entry (I'd suggest to post to the same channel but different entry type).

On the front-end you can now list only those requests/offers entries that do not have a matching "delete" entry yet. Another advantage over your delete approach is that you have a nice record and overview in the CP of what was offered and when.

Code example:

There's no template function to generate a random string, but you could apply Craft's shuffle function on an array of characters.

{%- set chars = '012345678901234567890123456789'|split('') %}
{%- set key = shuffle(chars)|join %}

{{- key|slice(0, 6) }}

That's how you could generate the secret keys within the Preparse field. And to loop through your "requests" and only show them if there's no matching "response" entry yet, do something like this.

{% set requests = craft.entries({
    section: 'lifts',
    type: 'requests',
    limit: null,
}) %}

{# 
 # Loop through all "requests". Check for each of them if there's a
 # matching "response" before outputting.
 #}
{% for request in requests %}

    {#
     # Try to get an entry of entry type "responses" where the "secretKey"
     # field value matches the "secretKey" of the "request" in the current
     # itteration of this "requests" loop (returns an EntryModel or NULL).
     #}
    {% set hasResponse = craft.entries({
        section: 'lifts',
        type: 'responses',
        secretKey: request.secretKey,
    }).first() %}

    {#
     # Only output if "hasResponse" is not NULL
     #}
    {% if not hasResponse %}
        {{ request.message }}
    {% endif %}
{% endfor %}
4
  • That sounds like a plan. I've been thinking about letting them create a second entry and having a field that holds some common string, but I can't work out how to compare 2 separate entries for a matching string and then not show either if there is a match. Any pointers to a code example?
    – Paul Frost
    Feb 27 '16 at 17:22
  • Thanks carlcs, any reason why the user couldn't input their own password (instead of using Preparse) when they post their first entry and then use that when they submit the second one to remove it? Any chance of adding some comments to the code to explain what's happening so I can try and learn for the future. If the first set only gets all entries with the type: 'requests' how does the second set hasResponse get type: 'responses' find any 'responses' if the original set only included 'requests'?
    – Paul Frost
    Feb 27 '16 at 18:58
  • Well, you could also allow the user to set a password instead of generating one. But what happens when more than one "request" is stored with a password "1111"? This (most likely) won't happen with the generated ones. What you could do is to let them input a password, show them the request's ID and require them to input both, ID and password to submit a "response".
    – carlcs
    Feb 27 '16 at 20:02
  • I've got this working now. I'm using the original entryId as the secretKey in a hidden input and also asking for their email address as a second test. I suspect many people will forget any sort of password that they set or remember a generated random string. Security isn't that big an issue in this case.
    – Paul Frost
    Feb 28 '16 at 11:59
1

Using the Guest Entries plugin, how can I allow people to edit/delete?

As it currently stands, you can't. The Guest Entries plugin was written to accept new entries only. That's largely because, as you've touched on, they are "anonymous" submissions and there's no secure/easy way to authenticate that the user has permissions to edit/delete the entry they are trying to edit/delete.

So you'd need to fork the plugin and add your own custom logic to achieve what you're looking for.

3
  • Plugin development is out of my league. I'm not a PHP developer and this is my first Craft site after years of using ExpressionEngine, so I'm on a steep learning curve. Any other suggestions as to how I could achieve my goal? Would the standard front end entry form be easier to adapt to my need?
    – Paul Frost
    Feb 25 '16 at 22:41
  • No, the standard entry save form requires an authenticated session, which you don't want. I can't think of any way to do what you're looking for without some custom PHP/plugin work. Maybe someone else can.
    – Brad Bell
    Feb 25 '16 at 22:48
  • 1
    @PaulFrost Late to the party, but I forked the GuestEntries plugin to allow editing & deleting of guest entries... github.com/ChaseGiunta/GuestEntries Apr 28 '16 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.