How to access HTML input values from Twig and vice versaHow to return integer in text formCannot install custom Twig extension pluginUse subdomain for S3 assets in multi-site Craft installationCraft or Twig converting html tags to alt charactersContact Form sent via Ajax with file upload returns 302 instead of 200 status codeTranslating Craft form error message labelsConnection between twig template and website contentSearching for Multiple Categories and TagsOutput raw html from if statement and combining strings?Entry form with field translated accross multiple sites
Team goes to lunch frequently, I do intermittent fasting but still want to socialize
Looking for a new job because of relocation - is it okay to tell the real reason?
How do I change the output voltage of the LM7805?
Plausibility of Ice Eaters in the Arctic
Can you use the Fly spell to move underwater at a speed of 60 feet?
Why are the inside diameters of some pipe larger than the stated size?
What are good ways to improve as a writer other than writing courses?
Could one become a successful researcher by writing some really good papers while being outside academia?
Where to pee in London?
Short story about a teenager who has his brain replaced with a microchip (Psychological Horror)
Shabbat clothing on shabbat chazon
Dereferencing a pointer in a for loop initializer creates a seg fault
Ex-contractor published company source code and secrets online
Pandas: fill one column with count of # of obs between occurrences in a 2nd column
What is the best way to cause swarm intelligence to be destroyed?
Look mom! I made my own (Base 10) numeral system!
Is it double speak?
Can a PC attack themselves with an unarmed strike?
Acceptable to cut steak before searing?
Why are physicists so interested in irreps if in their non-block-diagonal form they mix all components of a vector?
Replace data between quotes in a file
How to help new students accept function notation
How would I as a DM create a smart phone-like spell/device my players could use?
Improving software when the author can see no need for improvement
How to access HTML input values from Twig and vice versa
How to return integer in text formCannot install custom Twig extension pluginUse subdomain for S3 assets in multi-site Craft installationCraft or Twig converting html tags to alt charactersContact Form sent via Ajax with file upload returns 302 instead of 200 status codeTranslating Craft form error message labelsConnection between twig template and website contentSearching for Multiple Categories and TagsOutput raw html from if statement and combining strings?Entry form with field translated accross multiple sites
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.
- I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.
- I want to change the "clicked" boolean, whenever the submit button is clicked.
The myFunc is a function that I am using from a custom plugin so it is not relative.
I have commented what I've last tried and does not work for me.
I am using Craft 3, if that helps.
% block body %
% set clicked = false %
<form name="search" action="% set clicked = true %">
<label for="foo">Foo</label>
<input name="foo" type="text"/>
<input type="submit" value="Get Json"/>
# <a href=" set clicked = true "#
</form>
% if clicked %
% set json = jsonator_myFunc(search.foo.vars.value) %
% endif %
% endblock %
EDIT/SOLUTION:
A few more days into Craft CMS and chill and I realize how silly my question is.
Thank you for the replies. The solution which I was looking for is:
craft.request.getParam('foo')
templating craft3 php yii twigextension
add a comment |
I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.
- I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.
- I want to change the "clicked" boolean, whenever the submit button is clicked.
The myFunc is a function that I am using from a custom plugin so it is not relative.
I have commented what I've last tried and does not work for me.
I am using Craft 3, if that helps.
% block body %
% set clicked = false %
<form name="search" action="% set clicked = true %">
<label for="foo">Foo</label>
<input name="foo" type="text"/>
<input type="submit" value="Get Json"/>
# <a href=" set clicked = true "#
</form>
% if clicked %
% set json = jsonator_myFunc(search.foo.vars.value) %
% endif %
% endblock %
EDIT/SOLUTION:
A few more days into Craft CMS and chill and I realize how silly my question is.
Thank you for the replies. The solution which I was looking for is:
craft.request.getParam('foo')
templating craft3 php yii twigextension
2
For clarity, Twig is a wrapper for PHP, a server-side language. Twig/PHP gets parsed down to regular HTML before it gets sent to the browser. Essentially, you'd interact with Twig in the exact same way as you'd interact with PHP.
– Lindsey D♦
Jul 29 at 15:15
add a comment |
I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.
- I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.
- I want to change the "clicked" boolean, whenever the submit button is clicked.
The myFunc is a function that I am using from a custom plugin so it is not relative.
I have commented what I've last tried and does not work for me.
I am using Craft 3, if that helps.
% block body %
% set clicked = false %
<form name="search" action="% set clicked = true %">
<label for="foo">Foo</label>
<input name="foo" type="text"/>
<input type="submit" value="Get Json"/>
# <a href=" set clicked = true "#
</form>
% if clicked %
% set json = jsonator_myFunc(search.foo.vars.value) %
% endif %
% endblock %
EDIT/SOLUTION:
A few more days into Craft CMS and chill and I realize how silly my question is.
Thank you for the replies. The solution which I was looking for is:
craft.request.getParam('foo')
templating craft3 php yii twigextension
I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.
- I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.
- I want to change the "clicked" boolean, whenever the submit button is clicked.
The myFunc is a function that I am using from a custom plugin so it is not relative.
I have commented what I've last tried and does not work for me.
I am using Craft 3, if that helps.
% block body %
% set clicked = false %
<form name="search" action="% set clicked = true %">
<label for="foo">Foo</label>
<input name="foo" type="text"/>
<input type="submit" value="Get Json"/>
# <a href=" set clicked = true "#
</form>
% if clicked %
% set json = jsonator_myFunc(search.foo.vars.value) %
% endif %
% endblock %
EDIT/SOLUTION:
A few more days into Craft CMS and chill and I realize how silly my question is.
Thank you for the replies. The solution which I was looking for is:
craft.request.getParam('foo')
templating craft3 php yii twigextension
templating craft3 php yii twigextension
edited Aug 6 at 9:24
ves
asked Jul 29 at 11:40
vesves
184 bronze badges
184 bronze badges
2
For clarity, Twig is a wrapper for PHP, a server-side language. Twig/PHP gets parsed down to regular HTML before it gets sent to the browser. Essentially, you'd interact with Twig in the exact same way as you'd interact with PHP.
– Lindsey D♦
Jul 29 at 15:15
add a comment |
2
For clarity, Twig is a wrapper for PHP, a server-side language. Twig/PHP gets parsed down to regular HTML before it gets sent to the browser. Essentially, you'd interact with Twig in the exact same way as you'd interact with PHP.
– Lindsey D♦
Jul 29 at 15:15
2
2
For clarity, Twig is a wrapper for PHP, a server-side language. Twig/PHP gets parsed down to regular HTML before it gets sent to the browser. Essentially, you'd interact with Twig in the exact same way as you'd interact with PHP.
– Lindsey D♦
Jul 29 at 15:15
For clarity, Twig is a wrapper for PHP, a server-side language. Twig/PHP gets parsed down to regular HTML before it gets sent to the browser. Essentially, you'd interact with Twig in the exact same way as you'd interact with PHP.
– Lindsey D♦
Jul 29 at 15:15
add a comment |
2 Answers
2
active
oldest
votes
You can do it without JavaScript (if you don't mind the page refreshing) by accessing the request variable:
https://docs.craftcms.com/api/v3/craft-web-twig-variables-request.html#public-methods
craft.app.request.getParam('foo') # Should be the value of the input named 'foo' #
This is exactly what I ended up using. Thanks anyways! The only thing that bothers me is that I only managed to get it work with a form with a "get" method and the parameters are visible in the address bar. Do you know a way to hide them?
– ves
Jul 29 at 15:04
1
You can set the form's method to 'post' and the server should still be able to access the request variables, without showing them in the address bar.
– missmatsuko
Jul 29 at 18:38
add a comment |
Twig (at least within the context of Craft) doesn't work this way I'm afraid. The Twig template is processed on the server and HTML is returned to the browser.
You're trying to change the Twig based on an event in the Browser, but that at that time, there is no longer Twig, just HTML.
So your solution will need to involve Javascript to change the HTML/DOM rather than the approach you're going for here.
Thanks! I'am solving it right now with js but I was hoping there will be a "simpler" solution.
– ves
Jul 29 at 12:47
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "563"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f31097%2fhow-to-access-html-input-values-from-twig-and-vice-versa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do it without JavaScript (if you don't mind the page refreshing) by accessing the request variable:
https://docs.craftcms.com/api/v3/craft-web-twig-variables-request.html#public-methods
craft.app.request.getParam('foo') # Should be the value of the input named 'foo' #
This is exactly what I ended up using. Thanks anyways! The only thing that bothers me is that I only managed to get it work with a form with a "get" method and the parameters are visible in the address bar. Do you know a way to hide them?
– ves
Jul 29 at 15:04
1
You can set the form's method to 'post' and the server should still be able to access the request variables, without showing them in the address bar.
– missmatsuko
Jul 29 at 18:38
add a comment |
You can do it without JavaScript (if you don't mind the page refreshing) by accessing the request variable:
https://docs.craftcms.com/api/v3/craft-web-twig-variables-request.html#public-methods
craft.app.request.getParam('foo') # Should be the value of the input named 'foo' #
This is exactly what I ended up using. Thanks anyways! The only thing that bothers me is that I only managed to get it work with a form with a "get" method and the parameters are visible in the address bar. Do you know a way to hide them?
– ves
Jul 29 at 15:04
1
You can set the form's method to 'post' and the server should still be able to access the request variables, without showing them in the address bar.
– missmatsuko
Jul 29 at 18:38
add a comment |
You can do it without JavaScript (if you don't mind the page refreshing) by accessing the request variable:
https://docs.craftcms.com/api/v3/craft-web-twig-variables-request.html#public-methods
craft.app.request.getParam('foo') # Should be the value of the input named 'foo' #
You can do it without JavaScript (if you don't mind the page refreshing) by accessing the request variable:
https://docs.craftcms.com/api/v3/craft-web-twig-variables-request.html#public-methods
craft.app.request.getParam('foo') # Should be the value of the input named 'foo' #
answered Jul 29 at 14:43
missmatsukomissmatsuko
561 bronze badge
561 bronze badge
This is exactly what I ended up using. Thanks anyways! The only thing that bothers me is that I only managed to get it work with a form with a "get" method and the parameters are visible in the address bar. Do you know a way to hide them?
– ves
Jul 29 at 15:04
1
You can set the form's method to 'post' and the server should still be able to access the request variables, without showing them in the address bar.
– missmatsuko
Jul 29 at 18:38
add a comment |
This is exactly what I ended up using. Thanks anyways! The only thing that bothers me is that I only managed to get it work with a form with a "get" method and the parameters are visible in the address bar. Do you know a way to hide them?
– ves
Jul 29 at 15:04
1
You can set the form's method to 'post' and the server should still be able to access the request variables, without showing them in the address bar.
– missmatsuko
Jul 29 at 18:38
This is exactly what I ended up using. Thanks anyways! The only thing that bothers me is that I only managed to get it work with a form with a "get" method and the parameters are visible in the address bar. Do you know a way to hide them?
– ves
Jul 29 at 15:04
This is exactly what I ended up using. Thanks anyways! The only thing that bothers me is that I only managed to get it work with a form with a "get" method and the parameters are visible in the address bar. Do you know a way to hide them?
– ves
Jul 29 at 15:04
1
1
You can set the form's method to 'post' and the server should still be able to access the request variables, without showing them in the address bar.
– missmatsuko
Jul 29 at 18:38
You can set the form's method to 'post' and the server should still be able to access the request variables, without showing them in the address bar.
– missmatsuko
Jul 29 at 18:38
add a comment |
Twig (at least within the context of Craft) doesn't work this way I'm afraid. The Twig template is processed on the server and HTML is returned to the browser.
You're trying to change the Twig based on an event in the Browser, but that at that time, there is no longer Twig, just HTML.
So your solution will need to involve Javascript to change the HTML/DOM rather than the approach you're going for here.
Thanks! I'am solving it right now with js but I was hoping there will be a "simpler" solution.
– ves
Jul 29 at 12:47
add a comment |
Twig (at least within the context of Craft) doesn't work this way I'm afraid. The Twig template is processed on the server and HTML is returned to the browser.
You're trying to change the Twig based on an event in the Browser, but that at that time, there is no longer Twig, just HTML.
So your solution will need to involve Javascript to change the HTML/DOM rather than the approach you're going for here.
Thanks! I'am solving it right now with js but I was hoping there will be a "simpler" solution.
– ves
Jul 29 at 12:47
add a comment |
Twig (at least within the context of Craft) doesn't work this way I'm afraid. The Twig template is processed on the server and HTML is returned to the browser.
You're trying to change the Twig based on an event in the Browser, but that at that time, there is no longer Twig, just HTML.
So your solution will need to involve Javascript to change the HTML/DOM rather than the approach you're going for here.
Twig (at least within the context of Craft) doesn't work this way I'm afraid. The Twig template is processed on the server and HTML is returned to the browser.
You're trying to change the Twig based on an event in the Browser, but that at that time, there is no longer Twig, just HTML.
So your solution will need to involve Javascript to change the HTML/DOM rather than the approach you're going for here.
answered Jul 29 at 12:41
foamcowfoamcow
1,3185 silver badges16 bronze badges
1,3185 silver badges16 bronze badges
Thanks! I'am solving it right now with js but I was hoping there will be a "simpler" solution.
– ves
Jul 29 at 12:47
add a comment |
Thanks! I'am solving it right now with js but I was hoping there will be a "simpler" solution.
– ves
Jul 29 at 12:47
Thanks! I'am solving it right now with js but I was hoping there will be a "simpler" solution.
– ves
Jul 29 at 12:47
Thanks! I'am solving it right now with js but I was hoping there will be a "simpler" solution.
– ves
Jul 29 at 12:47
add a comment |
Thanks for contributing an answer to Craft CMS Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f31097%2fhow-to-access-html-input-values-from-twig-and-vice-versa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
For clarity, Twig is a wrapper for PHP, a server-side language. Twig/PHP gets parsed down to regular HTML before it gets sent to the browser. Essentially, you'd interact with Twig in the exact same way as you'd interact with PHP.
– Lindsey D♦
Jul 29 at 15:15