Questions tagged [controller]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
21 views

Is there a way to compare what has changed on an entry while it's being saved?

I'm taking my first baby steps into the php side of Craft, and my php experience in general is extremely fledgling. But I'm pretty much forced to create a module for a project I have, so here I am ...
0
votes
0answers
13 views

htpasswd exception for controller

I'm wondering if anyone's using .htpasswd for basic site security for a staging site that's in review (where we're testing front-end registrations so we don't want to force control panel logins, ...
0
votes
1answer
34 views

Rendering a template from a controller - unable to find template

Once again going out of my mind trying to figure something out... I have a custom controller which I want to return a rendered template. The template should, ideally, reside in my front end templates ...
0
votes
0answers
30 views

How can I add data to a matrix field from a module without overwriting existing data?

I have an entry that has a matrix field. From a controller in a module I want to add additional data to it (e.g. some text that I have in a variable $messageText) but without overwriting the existing ...
1
vote
2answers
73 views

Can you call a controller method from within a plugin/module in Craft 3?

I initially asked a question here about how to use Solspace Freeform to build a custom front-end login form. I gave up too easily and accepted the "it's possible but probably not a good idea"...
0
votes
0answers
28 views

404 error when trying to access a module controller action

I’m creating a module for a site for the first time and I’m having some trouble figuring out how to get the correct action url for my controller. I’m using this template for setting up the module: ...
0
votes
0answers
16 views

Optimising entries fetching in php

First of all, the last time I did php was 10 years ago in school, so I'm basically a noob :D I have two channels, let's say shops and products. Shops contains a matrix field composed of a product ...
1
vote
1answer
28 views

Controller redirect not working in craft 3

I am working with Craft 3 and in my controller, I am trying to do this $this->redirect('https://foobar.test'); But it is throwing me back to the root url of my craft site. I am confused, what else ...
0
votes
0answers
18 views

Programmatically set a field from the Sprout Fields plugin

We are building a custom frontend form allowing users to create their own entries. How can we set the sprout fields programmatically in the backend? This is what we have tried so far with the phone ...
1
vote
1answer
15 views

How is conflicting asset filename created

I upload files on the frontend using AJAX requests to actionUpload controller. When file is uploaded, I immediately display it using filename returned by controller. In case if filename conflict, ...
0
votes
0answers
29 views

How can I get uploaded images from my controller and upload them to Craft?

I'm using dropzone to upload images on my front-end. The form action url is to my controller from a custom plugin and that works fine. However, now I'm trying to get the files from dropzone (a json ...
0
votes
1answer
26 views

How to save data from a form in Craft? Explain with an example?

where do you handle the POST requests? where do you write the validation rules and flash error messages? where do you write save to db code? (mainly i want to know how do you route a POST request to a ...
1
vote
1answer
36 views

doublesecretagency business logic module template: 404 on example form action

I set up the business logic module template following these instructions: https://doublesecretagency.github.io/craft-businesslogic/installation The test works out well, so everything seems to be in ...
0
votes
0answers
17 views

Extending Craft controller classes and using private methods in child class

I created Controller that exptends Craft AssetsController. Hovewer some of AssetsController methods are private - and I cannot use them using $this context in child module, so i just copied them to ...
0
votes
1answer
68 views

How to override UserController.actionLogin or the login form template in Craft 3?

Hi I'm trying to build a custom authentication plugin for an organization, and I'm having a hard time figuring out how to override the craft\controllers\UserController.actionLogin method. I tried ...
1
vote
1answer
30 views

Updating global set from controller

This is my code: $giveaway = Craft::$app->globals->getSetByHandle('promotions'); $giveaway->giveawayName = "New Name"; $success = Craft::$app->globals->saveSet($giveaway); return($...
2
votes
1answer
54 views

Finding the correct actions url

struggling to decipher how to link a plugins controller to an action route. The docs say to use "https://pluginfactory.io/" to scaffold one, but what it generates is a different structure to what the ...
1
vote
0answers
39 views

How can I override the Response status text from a controller?

I'm trying to set the statusText in a response, from a module controller. E.g.: <?php namespace modules\appmodule\controllers; use Craft; use craft\web\Response; class StatusController extends ...
1
vote
1answer
76 views

Does Craft automatically sanitize user input?

Can I rely on Craft to clean user input, is safe to save the following data like in the below example function, if not, what is the Craft best practice for cleaning(making it safe) user input? public ...
1
vote
1answer
69 views

Action route not available from URL. What do I have wrong?

I built a plugin for Craft 3 and need to run one of its actions via CRON. I know I can set this up as a console command, and will do that, but before I get there, I'd like to solve this issue. I ...
3
votes
1answer
386 views

What are the different scenarios to plan for when using $allowAnonymous in a controller?

Craft 3.2 updates how the allowAnonymous behavior works. I have things working in our plugins but I don't understand the different syntaxes needed across our different allowAnonymous use cases. For ...
1
vote
1answer
188 views

Get entries based on multiple fields in controller

I am trying to get the entries based on multiple fields. Fields can be of type tags, checkbox, radio box, and number. In my controller currently what I tried is. $extrafilter will be like Array ( ...
3
votes
1answer
134 views

How to re-populate form with old values when submitted from a controller?

I have a form in a template which makes a request to the specified action (a controller). The controller decides that there is an issue with the inputs and needs to provide error output for the user. ...
1
vote
1answer
633 views

How do I correctly send an external request to a module controller? runAction() is returning null

Craft 3.1.18 I have a simple controller VeteransController made using the updated Business Logic module. The purpose of this controller is to create a very simple endpoint for an external Vue ...
1
vote
1answer
469 views

Craft 3 Controller - Redirect with errors

I cant get this to work. I'm doing a post to a controller action. From that action I'm doing a lot of validations, db insert, file uploads etc. Coming from Laravel Im used to is doing like this: (...
2
votes
1answer
64 views

Update a lightswitch field in Craft CMS 2

How can I edit a lightswitch field in an entries field layout via PHP? This is my current approach public function actionSponsoredEntriesPriority() { $this->requireAdmin(); $this->...
1
vote
2answers
143 views

renderTemplate() renders the twig file without any CSS

I've set up the routing for a specific URL in my plugin to trigger the actionIndex controller method. I after logging a message to the Craft logs, I want to return the rendered twig file as the view, ...
5
votes
2answers
2k views

How to render plugin templates in Craft CMS 3?

I cannot find a way to render templates from a plugin controller in Craft 3. I feel as though I've tried every variation advised online but for some reason this still isn't working. <?php ...
2
votes
1answer
71 views

Some (but not all) controller action routes return 404 on staging server

I've created a module for a project that has several actions, all of which are called through AJAX. Each is a post request that sends over any required params plus the CSRF token using the method ...
2
votes
2answers
1k views

Action URLs from CP to a Craft 3 plugin controller

I'm working on my first Craft 3 plugin and want to add some buttons to my plugin's control panel section which post form data to a controller. My plugin is called 'myplugin', the controller I wish to ...
2
votes
1answer
243 views

How can I pass a variable defined in a Controller to my variables?

In my Craft 3 plugin I would like to pass a variable defined in my Controller to my PluginVariable.php file. Is this possible?
1
vote
2answers
387 views

How to disable plugin Disable and Uninstall?

I am developing a site with a customer logged in area. I don't want anyone to access the section if they are logged out and instead redirect them to the login form. I could just add {% requireLogin %...
1
vote
1answer
148 views

How can I call console controllers

I have a controller in the console folder. How can I call this controller via ajax please? I tried to config a route in Routes.php, and then call this route by jquery Get() function. But none of ...
1
vote
1answer
1k views

“Template Not Found” error when trying to access a module controller action

I'm a total Craft newbie, so I hope this question isn't ridiculous. I just want to see a controller / action work in my new module. I have src/controllers/ScrapeController.php as such: <?php ...
1
vote
0answers
466 views

Unable to call a service method from controller in my custom plugin

I know there are similar questions here, but I don't see a definitive answer, nor one that works for me. I've generated a plugin via pluginfactory.io, which has some controllers and a single service. ...
2
votes
1answer
1k views

Craft 3 Controller giving 404

Updating a plugin to Craft 3 (also changed its name). I know this is probably something very simple, like capitalization, but can anyone point out what's wrong? Firefox console shows a 404 for http://...
2
votes
2answers
295 views

Add a button to the entry edit screen via plugin

I would like to add a button to the edit entry screen, only for already saved entries, alongside the "Share" button. When clicked, I'd like to call my plugin's controller action and post the entry ID....
1
vote
1answer
2k views

How to call Controller in Module?

I'm very new to craft and I'm having trouble finding an answer to my question (I've scoured the questions on here - but the only answers appear to be for plugins). Basically, I want to submit a form ...
1
vote
0answers
514 views

Plugin Development (Craft 3): Pass variables with redirection

I'm building out a Craft 3 plugin and can't see who to pass variables with redirection from a controller. For example, I have a controller that I want to pass back to the defined redirect value ...
1
vote
1answer
169 views

How to render template instead of throwing an error?

I'm working on a plugin that hooks into Craft's Guest Entries plugin. I want to send a confirmation mail after an entry has been saved. This works nicely so far. Now I want to catch any errors in ...
1
vote
1answer
344 views

Filter entries by ajax to controller

Short story: I need your help sending value from dropdown selection as data to controller so my div updates with the filtered entries based on the selection. Long story and code: I have a listing of ...
2
votes
0answers
556 views

Craft 3 Plugin - Only default action works

I'm working on a Cloudflare integration plugin for Craft 3. I set up the plugin with settings, which works fine so far. Now I intended to verify the Cloudflare credentials using an AJAX call. I set ...
1
vote
1answer
107 views

Save Entry Data as CSV and Email it to the Author / Logged in User

I am trying to email some Entry data that they have created in CSV Format to the author/logged in user. I have a controller setup with a frontend form posting an action to the controller: public ...
1
vote
1answer
58 views

Posting children to a Structure

This question is a follow up of a previous question see: (Entry Form - Multiple Entries & Entry Type & Parent) I am trying to add multiple children to a pre-existing multi level structure: ...
3
votes
2answers
391 views

Query entries relatedTo multiple categories in controller

I have an AJAX GET call that should count all the products matching three different taxonomies. Product families Sectors of application Liquids suitable for the product so in the form the user ...
1
vote
1answer
46 views

Craft plugin services in subfolders

So I'm getting to a point where I have a lot of services in a particular plugin, and I would like to organize my plugin services into sub-folders. I've tried a couple ways but the controllers don't ...
1
vote
1answer
674 views

Ajax call to action 404

I've a trigger on my frontend that requires an action. I've started from the businessLogic template but I'm getting a 404 and can't find why. My function public function actionExampleAjax() { ...
1
vote
3answers
561 views

Craft CMS plugin with AJAX gives 404 error

I have created a small craft cms plugin to pull some information from the DB, and everytime I execute the plugin I get a 404. Here is the controller namespace Craft; class ...
1
vote
1answer
839 views

Error 404 When trying to POST to plugin Controller action

Before I dive into my problem, I do want to mention that I did do my due diligence and spent the last two days researching this problem, to no avail, so here it goes: So I'm getting the following ...
4
votes
1answer
92 views

Store categories in array by level in controller

I'm making a plugin and I need to get an array from a certain category group where the levels of the array are the same as the level of the categories in the group. So I used the following code to ...