What would be the best approach to change the status of a channel form entry on page load? Without requiring the user to hit the submit button.
I’m having a problem that the comments tag form is a different form than then the channel form tag. That means I can only have one submit on the same page, and I need to update a channel entry status when someone comments on it. I don’t think it’s possible to use one submit button on the same page to submit both forms automatically.
To complicate the scenario is making an add-on hook, but since this is only for 1 specific channel it seems overkill. And I never make an extension for EE before, could not find any basic examples either. Executing this every time as I said would be bad for performance since I only need this for one specific channel only.
The other idea is, maybe enable PHP and update the database? Or is there some model I can use? I just redirect to that template after submit, which executes the code. Downside, I need to enable PHP on the template.
The other idea is JavaScript and submit a hidden form on page load. I tried this, but it seems almost impossible since there is the security token and the form seems to be rendered exactly to avoid being submitted by JavaScript it seems.
Any specific idea on how I can achieve this?
User submits a comment, redirects to an OK template page, that template page changes the status of the channel.
How are you intending to use the changed status? Maybe you want to filter on which entries have comments, or which don’t?
Depending on what it is you’re trying to do with the entry status, you might be able to use an existing field. For example, the {comment_total} field could be used to identify which entries have comments and which don’t.
Actually, I already do that. Exactly what you said. I filter some channels on my side based on the number of comments, last comment, entry date, etc.
But I also have the requirement for users to change the status after commenting programatically.
I did this in a dirty way, it works, not ideal or clean but seems to make the magic. I basically check the entry ID and then change the status directly in the database table using an Active Record query in PHP.
Not ideal because it forces me to enable PHP in that template. I think with Jquery or similar it would be cleaner, once loaded that template basically submit the form, but I was not able to achieve that and required a solution fast. Granted, my JavaScript skills are none existing but it seems the onload submit forms I found online, with JavaScript or JQuery would do the trick. Basically submit the form on load.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.