Questions tagged [controller]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
0answers
40 views

Help with understanding Controller routing

I'm building a module, and all is going well. I can access all "routes" except actionIndex. I have a controller named SendController.php And, I can access the method below using "...
0
votes
0answers
11 views

Handling CSRF errors gracefully in forms

I have a question regarding the handling of CSRF errors. By default, a CSRF error will result in a very basic / generic error screen. This is problematic for CSRF-protected forms since it interupts ...
1
vote
1answer
37 views

Set flash message after redirect

I’m trying to display a flash message in the CP after being redirect from a controller. Some context: when a user registers from a front-end, the account is set to “pending” and the admin gets a ...
0
votes
0answers
20 views

Live site/server has different data to local site

I've been looking at a Craft site for a friend which suddenly started reported incorrect numbers for sales (they're using Craft Commerce). They noticed that one day they had an item that had 62 sales, ...
2
votes
1answer
76 views

What value does actionInput provide?

What is the value in using a hidden actionInput vs an action attribute on a form? <form method="post"> {{ actionInput('path/to/controller-action') }} </form> vs <form ...
0
votes
0answers
9 views

Echo locale title in controller (craft cms 2)

I want to echo the translated title of an entry in the controller of a plugin. How can i acces the locale data?
0
votes
0answers
34 views

How can I get field values for the sections that I created

New to Craft CMS. We decided to make Craft headless and have an api fetch the data. I have 5 (simple) sections that represent 5 pages and they all have some fields in them with some texts or images. ...
0
votes
0answers
41 views

Request didn’t meet the user agent and IP requirement for maintaining a user session when website posts to our action URL

We have a module that has an action controller method that a third party website posts data to. We can see that often, we can't save the data and there is an error "Request didn’t meet the user ...
0
votes
0answers
11 views

How can I override the language and locale before rendering a template?

I render a template by a controller and it supposed to be rendered by a specific language and locale formatting regardless of current user's language or locale. Is it possible to override the language ...
0
votes
0answers
15 views

Proper way to pass matrix fields to Javascript

I'm working on a semi-headless solution with Vue frontend. The problem is the Matrix field. How to properly pass this from the Controller in PHP to Javascript/Vue frontend? With all its possible extra ...
1
vote
1answer
39 views

Prevent adding users with same email addresses

I am adding new users inside of the Craft controller as part of the frontend user import script. This is the code: $user = new User(); $user->pending = true; $user->username = $email; $user->...
0
votes
0answers
18 views

Display debug toolbar in controllers

I created a controller that returns XML and is not related to Twig rendering in any way. Can I still display the debug toolbar when I enter this controller URL to check if my database queries are ...
0
votes
1answer
50 views

$this->renderTemplate() breaks the CP navigation

I'm locally working on a Craft Plugin with a Page in the Control Panel where I have a form that posts to a controller. <form action="/actions/import-products/product/create" method="...
4
votes
1answer
115 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
23 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
162 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
47 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
253 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"...
1
vote
1answer
71 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 ...
1
vote
1answer
22 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
1answer
52 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
46 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
18 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
149 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
56 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
61 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
74 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
141 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
207 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
535 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
292 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
200 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
910 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
739 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
82 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
275 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
108 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
2k 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
319 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?
2
votes
2answers
463 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
169 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
556 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
429 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
1answer
593 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
234 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
368 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 ...