Questions tagged [controller]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
17 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
69 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. ...
5
votes
4answers
1k views

How can I set the HTTP status code?

I'm trying to set a 404 HTTP status response code for an ajax controller action in a plugin. Yii has a response object where the code can be set, but I can't find a way to access it from craft.
1
vote
1answer
585 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 ...
0
votes
0answers
37 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
13 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
38 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
17 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
49 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
99 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
22 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
131 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
230 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
51 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
20 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
67 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
21 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, ...
1
vote
1answer
152 views

Paypal IPN controller logic? [closed]

Has anybody got a controller (or whatever plugin aparatus is needed) to process Paypal IPN? Edit: Years later, I have accomplished this, and have some information which could be helpful if someone ...
0
votes
1answer
48 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
44 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
132 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
55 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($...
1
vote
1answer
197 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 ...
2
votes
1answer
60 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
68 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
134 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 ...
4
votes
2answers
937 views

Twig Filter in Plugin/PHP?

Is it possible to access twig filters in a plugin? I want to be able to preview how text will look in a textarea using Markdown for a discussion board, it'd be awesome to use ajax to send the content ...
3
votes
1answer
521 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
269 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
191 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
883 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
707 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
79 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->...
2
votes
2answers
406 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....
3
votes
2answers
2k views

Controller action redirection when called via route

I have a route set up in routes.php that calls a controller action using something similar to what is described here: https://straightupcraft.com/articles/how-do-i-setup-a-route-to-point-to-a-...
1
vote
2answers
255 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, ...
2
votes
1answer
100 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 ...
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
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
309 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
455 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
166 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
543 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://...