storing variable in twig? - twig

i am starting to play with twig, but I am very noob at it.
So sorry if the question sounds utterly stupid, but well.. i looked a bit everywhere, and i didn't find anything.
So, how can i store a string input by the user into a variable in twig?
like in my template I have:
<input type="text" name="name"/>
what shall I do to store the "value" of this input into a variable?
Is here direct way to do it?
or shall i do something completely different?
if so, what should I look for?

You need to pass the variable from your controller back to your template,
<?php
$twig->render('template.twig', [
'name' => isset($_POST['name']) ? $_POST['name'] : '',
]);
template.twig
<input type="text" name="name" value="{{ name }}" />

Related

Array field post Node js but after show only first value

I am using post array field name but show only first please help.
<input type="text" name="brand[]" id="brand">ADD more
<input type="text" name="brand[]" id="brand">
Use this but post this data only get first value.
Both the input tags in your html have same name attribute. As far as HTML is concerned, it simply ignores the fields in a form with duplicate names.
If you want your inputs to be parsed as array by nodehs body parser, you will need to include the indices in the input tag name.
<input type="text" name="brand[0]" id="brand0">ADD more
<input type="text" name="brand[1]" id="brand1">
EDIT::
All the ids on a page are also expected to be unique.

Add "Return to" to FOSUserBundle login form

The title already says everything.
What code do I have to enter where?
If you dont understand the title, I mean to give a template something like this
Link
and the output should be... (example)
<a href="http://localhost/login?redir=http://localhost/blog/index"
and i think the controller would need something like...
/*
* #Route('/login', defaults={"redir" = "blog_default_index"})
*/
Please help. I actually have no idea
Try to build the href in two steps:
Link
Alternatively if you add a _target_path hidden input to the login form, the user will be redirect to that path:
<form>
...
<input type="hidden" name="_target_path" value="{{ path('blog_default_index') }}" />
</form>

How can I pass "type" attribute within <html:text> in struts1

When I try to write something like this: <html:text styleId="Istituto" type="number"> in the struts1 it gives me an error
Attribute type invalid for tag text according to TLD
How can I add "type" attribute to <html:text> tag?
I know this is old, but I'm currently working on a super old application that uses Struts 1 framework, and today I had the same problem. Here's the solution I'm using that works:
<input type="number" name="budgetValue"
value="<bean:write name="applicantForm" property="budgetValue"/>">
Where:
budgetValue - is the Form property; applicantForm - is the Form
Thanks to Milebza for the answer, but for me only this way has worked.
<input type="number" name="budgetValue" value="${applicantForm.budgetValue}" />

AngularJS: Why ng-model scope's variable is not shown in inspector if input field is empty?

I have an input form like this:
<form name="userForm">
<md-input-container>
<label>Username</label>
<input name="username" ng-model="userLogin.username" required>
<div ng-messages="userLogin.username.$error" ng-show="userLogin.username.$dirty">
<div ng-message="required">This is required!</div>
</div>
</md-input-container>
</form>
<div layout="row" layout-align="center">
<md-button class="md-raised md-primary md-padding button-margin" ng-click="handleLoginResult()" ng-disabled="!userForm.$valid">Login</md-button>
</div>
The problem is that until I don't write anything in the input field (= user interaction), the userLogin.username variable doesn't appear in the $scope (I'm using AngularJS' addon for Chrome dev console).
Indeed if I try to print it I get erro (userLogin is not defined >> username can't be read).
Any clue?
Typically, in an AngularJS controller, if you do not create the property implicitly on the $scope object it will not be defined until a bound element attempts to update it. This is just the nature of how AngularJS works and the nature of dynamic Javascript. Is there a reason you need to get to the property if it isn't defined yet? From your question I am assuming that you were just prodding it with the console. If you really need to use it in a function before it is defined use the OR logical operator in Javascript represented by two pipe characters:
$scope.userLogin || '';

Clone entry in expressionengine with safecracker

I have an expressionengine template for frontend users using safecracker to create entries. ex: http://domain.com/index.php/create. After user creates an entry, the entry can be edited by going to http://domain.com/index.php/create/my_entry where my_entry is the entry user created. My question is can i provide the user an option to clone an entry. What is the best way to clone. I can't think of an easy way to do this.
I haven't tried this, but you could try creating a new template - say, /index.php/clone/ - that you'd link to with the url_title of the entry to be cloned after it (e.g., /index.php/clone/my_entry). Then use a channel:entries tag with url_title="{segment_2}" to get the values of all the existing entry's fields, and nest an {exp:safecracker} tag inside of it?
{exp:channel:entries channel="my_channel" url_title="{segment_2}"}
{exp:safecracker channel="my_channel"}
<input name="title" type="text" value="{title} />
<input name="my_custom_field" type="text" value="{my_custom_field}" />
... etc ...
<input type="submit" value="Submit" />
{/exp:safecracker}
{/exp:channel:entries}
Worth a shot anyway.

Resources