Skip to main content

Questions tagged [controller]

The tag has no usage guidance.

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

Not able to query by id

I don't get, how i should query for an entry by ID in Craft CMS 5. I have an entry in my "Article Comments" section: The Section contains the entry type "Comments Content". The ...
smaniren's user avatar
1 vote
1 answer
20 views

getBodyParam('email') is empty on live server

Trying to debug a form issue which is only happening on a live server (it works on our local environments). The form makes a fetch request (using Javascript) to a route in routes.php which goes to a ...
Jaytrix's user avatar
  • 337
1 vote
1 answer
56 views

Can plugins have their own routes?

I'm writing a plugin. I'd like it so that a request to view the page is processed via a Controller rather than goes straight to a template (following an MVC pattern). So a GET request to the URL of ...
Chuck Le Butt's user avatar
1 vote
2 answers
159 views

Uploading (multiple) assets to assets controller via front end with Craft 4

I'm trying to upload assets directly to a volume using the 'assets/upload' controller in a front-end form. There must have been some changes since Craft 3 and I'm running into 2 issues: Issue 1: ...
MetaMachine's user avatar
0 votes
0 answers
38 views

Creating a User without email requirement and auto-activation from a Controller

I'm working on a project where I use Craft CMS to manage user sessions and store user preferences such as site version and preferred language. However, for privacy reasons (GDPR compliance), I'm not ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
41 views

Is there a way to determine an element by its path or full url instead of the uri?

I'm using Craft in headless mode. It's a multisite setup different languages. I know that's it's possible to query an element by it's uri. Is there a way to check if a full path or an absolute url ...
user14370's user avatar
1 vote
1 answer
35 views

How to run Sprout Forms action from a controller to implement Google reCAPTCHA?

I'm using Sprout Forms V3 on Craft 3. I'm trying to handle the submit within a controller. This choice is made to add a custom logic, to implement a Google reCAPTCHA (as the official Sprout's plugin ...
Romain P.'s user avatar
  • 1,852
1 vote
2 answers
273 views

Sprig: how to redirect to a URL after submitting to a custom controller?

I have a multi-pages form which is submitting using Sprig plugin. The action is targeting a controller in a custom module. Each step of the form is loading using the current step stored in session. ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
904 views

Set "Access-Control-Allow-Origin: *" header in a controller action (CORS issues)

I send a POST request from a headless frontend to a craft controller action but the request is not going trough because of: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the ...
Merc's user avatar
  • 211
1 vote
1 answer
929 views

Using EventStream doesn't work because MimeType from Controller Action is always text/html

I'm trying to listen to SSE events from a controller action. I am setting the headers in the controller action with: Craft::$app->response->headers ->set('Content-Type: text/event-...
Tudor-Radu Barbu's user avatar
0 votes
1 answer
50 views

How can I troubleshoot why a user's initial password is being deleted after a front-end registration? [answer: it was not set in the first place]

We have a front-end registration form that was working as expected for months, and now mysteriously when someone registers they can't log in because their password is empty. Using a front-end password ...
Kirk Roberts's user avatar
0 votes
2 answers
386 views

Setting up and understanding a controller

I'm trying to set up a module with a controller as bit of a learning tool. The learning is not going well so far. Here is my setup: - modules - - site - - - playing - - - - Playing.php - - - - ...
supazu's user avatar
  • 526
0 votes
1 answer
119 views

How to use twig macro inside controller?

I want to use the macro I defined in twig inside a controller or a module. Is that possible?
user's user avatar
  • 63
0 votes
1 answer
115 views

How to query a user by username on controller level?

How to query a user by username on controller level? In twig I can do: {% set user = craft.users.username('username') %} How to do that in controller? Thank you for your help.
user's user avatar
  • 63
1 vote
1 answer
185 views

How to Extend Craft CMS frontend controller?

How to extend craft's front end controllers? I don't want to use twig. I like twig but I don't want to use it in craft. Respect my decision and help me. Is there a good way to do that?. So I can ...
user's user avatar
  • 63
1 vote
1 answer
107 views

Can't access Cookie from controller in plugin

In the frontend my website sets a cookie wich i need during a controller action. When calling the controller action from my plugin this Cookie gets duplicated and the value is replaced with an ...
Mathies Gielen's user avatar
1 vote
1 answer
44 views

Is there a way to trigger a user account creation from a different CMS?

I'm a junior web developer working with Craft CMS. I was wondering if there was a way to trigger a controller I have for my Craft CMS from an outside CMS. We have more than one website that offers ...
wannabecraftwiz's user avatar
1 vote
1 answer
69 views

Craft 3 paginate not working when fetched with a controller

I'm loading a paginate via Craft::$app->getView()->renderTemplate(), this is being executed within a controller. But my pageInfo.nextUrl is now the url of my controller (/actions/controllername/...
Kevon's user avatar
  • 160
0 votes
1 answer
345 views

CP Module: saving, editing, and reading a form

I read the docs multiple times but I'm stuck. I need to create a module that shows a form in the CP where an admin can input and save answers to 2 questions. It will always be just one single form. I ...
mauricio's user avatar
  • 187
0 votes
2 answers
430 views

How to access 'setRouteParams' model in form validation

I created a module that adds a password protection to a site I'm testing craft on (I'm new to Craft and Yii, so please bear with me). In the front end there's a form where users enter a password and ...
mauricio's user avatar
  • 187
1 vote
0 answers
633 views

Invalid Route in module

I'm new to craft and slowly learning how to use more advanced features. I'm trying to write a module with a controller. When the route is invoked on a fetch call I get the following error: HTTP 404 – ...
mauricio's user avatar
  • 187
1 vote
1 answer
414 views

Posting data from CP to Plugin controller results in server error 500

I am currently trying to write my 1st Craft plugin. The goal (simplified): Backend users select a bunch of pages in the CP, and create a PDF. The result is an annual report that's optimized for print (...
Zeix's user avatar
  • 21
2 votes
1 answer
507 views

404 Error Controller Action From Jquery But Not Url

I'm able to call my controller action directly from a url in the browser and get the proper response but when I call it from a page with js I get a 404 error. I'm working off the solution found here ...
Ryan Sneesby's user avatar
2 votes
1 answer
409 views

How to handle custom PHP logic in CraftCMS

I come from a "traditional" PHP paradigm where views are mixed with processing logic. And now switching from WordPress to CraftCMS (which so far is a beautiful experience) I am having ...
Álvaro Franz's user avatar
1 vote
0 answers
82 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 "...
Dario Zadro's user avatar
2 votes
1 answer
627 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 ...
gioppe's user avatar
  • 414
2 votes
1 answer
362 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 ...
Trevor Davis's user avatar
1 vote
0 answers
936 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 ...
John's user avatar
  • 974
1 vote
1 answer
69 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->...
Mato's user avatar
  • 229
0 votes
1 answer
99 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="...
Kap1tein's user avatar
4 votes
1 answer
492 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 ...
Brimby's user avatar
  • 343
2 votes
1 answer
782 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 ...
foamcow's user avatar
  • 2,029
1 vote
2 answers
894 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"...
Garrett's user avatar
  • 417
1 vote
1 answer
212 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 ...
Rohan's user avatar
  • 217
1 vote
1 answer
80 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, ...
Piotr Pogorzelski's user avatar
0 votes
1 answer
204 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 ...
jamesSeb's user avatar
1 vote
2 answers
94 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 ...
Mitchell's user avatar
0 votes
0 answers
24 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 ...
Piotr Pogorzelski's user avatar
0 votes
1 answer
388 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 ...
Myles Hyson's user avatar
2 votes
1 answer
356 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($...
Lukigi's user avatar
  • 565
2 votes
1 answer
487 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 ...
owenmelbz's user avatar
  • 149
1 vote
0 answers
242 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 ...
Tim Kelty's user avatar
  • 3,081
1 vote
1 answer
324 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 ...
Jessica Talzor's user avatar
1 vote
1 answer
754 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 ...
Chad Crowell's user avatar
4 votes
1 answer
752 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 ...
Ben Parizek's user avatar
  • 13.5k
1 vote
1 answer
501 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 ( ...
inrsaurabh's user avatar
3 votes
1 answer
411 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. ...
Lea Hayes's user avatar
  • 241
1 vote
1 answer
1k 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 ...
Steven Thate's user avatar
1 vote
1 answer
1k 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: (...
Hopstad's user avatar
  • 25
2 votes
1 answer
159 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->...
inrsaurabh's user avatar