How can I do a validation to delete comments

Hello Team!

I'd like to know how can I do a logic for deleting comments.

I've got to check if the logged user is the author of the comment. If response is true, he can delete the comment.

It might seem like a stupid doubt but I'm a beginner at this and wish you guys could help me.



Hi Raissa,

What kind of "comments" are you talking about?

Hi Raissa Domingos

To achieve that you should store the UserId of the user who made the comment. Then you can compare the UserId of the comment with the UserId of the current user to see if they match.

You can use the function GetUserId() to retrieve the Id of the user.

Best regards,
José Proença

Solution

Hi Raissa,

Are you talking about where you have a page that has comments from multiple users?

Well for that, just put the delete button only available to the commenting USERID. For your safety you can also do this validation on the logic side (you can know the user through the getuserid () function)

Do you understand the idea I wanted to convey to you?

Cheers,
Nuno Verdasca

Solution

Kilian Hekhuis wrote:

Hi Raissa,

What kind of "comments" are you talking about?


It's an intranet project. There are some departments and the employees. The employees can create announcements, but only the author of annoucement can delete it.





So the solution to what questions is what I described to you. Did you get it?

If you did the WebDeveloper tutorial, you had to do something very similar.


Hi Raissa,

In that case the solution has probably been given above. You need to store, with the announcement, who created it, and check the current user vs. the one who created the announcement for deciding whether deletion is allowed (depending on usability considerations either in an If that enables/disables or shows/hides the delete button or link, or in the actial delete code before actually deleting).

@Nuno: please don't quote the entire post, it prohibits easy reading of the topic, thanks.

Yes, It was really helpful. Thank's for the reply!

Regards!



Raissa, you don't have to thank, we're here to help each other out. Continuation of a good work.

Cheers,

Nuno Verdasca