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;








3















I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.



  1. I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.

  2. 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')









share|improve this question





















  • 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

















3















I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.



  1. I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.

  2. 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')









share|improve this question





















  • 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













3












3








3








I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.



  1. I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.

  2. 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')









share|improve this question
















I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours.



  1. I want to access the value of "foo" input field inside the twig delimiters to set the "json" variable.

  2. 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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










2 Answers
2






active

oldest

votes


















4














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' #





share|improve this answer

























  • 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


















3














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.






share|improve this answer

























  • 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













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
);



);













draft saved

draft discarded


















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









4














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' #





share|improve this answer

























  • 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















4














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' #





share|improve this answer

























  • 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













4












4








4







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' #





share|improve this answer













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' #






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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













3














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.






share|improve this answer

























  • 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















3














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.






share|improve this answer

























  • 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













3












3








3







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림