I have the following set up below.
My issue is I'm not sure how to convert an inline echo $_GET. Is it just the same as {{ fn( echo $_GET['units'] === 'Miles' ? 'selected' : null ) }}??
<form method="get" action="{{ post.link }}">
<div>
<span>Find a Store within</span>
<input name="proximity" type="number" placeholder="15" value="<?php echo $_GET['proximity'] ?>" />
<select name="units">
<option value="Miles" <?php echo $_GET['units'] === 'Miles' ? 'selected' : null; ?>>Miles</option>
<option value="K" <?php echo $_GET['units'] === 'K' ? 'selected' : null; ?>>Km</option>
</select>
<span>from</span>
<input name="origin" type="text" placeholder="Your Address" value="<?php echo $_GET['origin'] ?>" />
</div>
<div>
<input type="submit" value="Search" />
Reset
</div>
</form>
Thanks to #DarkBee for pointing the above out: Passing PHP global variables via Twig/Timber
To access $_POST variables, use this:
{{ request.post.name_of_var }}
To access $_GET variables, use this:
{{ request.get.name_of_var }}
So that would make this:
<input name="origin" type="text" placeholder="Your Address" value="<?php echo $_GET['origin'] ?>" />
Be this:
<input name="origin" type="text" placeholder="Your Address" value="{{ request.get.origin}}
Related
I want to assign value to input field. When I console.log I get the output as title is welocme to the app. Content is hello world. But only welcome is assigned to title input and only hello is assigned to content input. Only the first word is assigned. Please help.
post.ejs
<%- include('./partials/header');-%>
<%- include('./partials/flash');-%>
<form action="/posts/<%= post._id %>/edited" method="POST">
<%= console.log("title is "+post.Title +" ."+"content is "+post.Content); %>
<h1><input type="text" name="title" id="title" value=<%= post.Title %>></h1>
<p><input type="text" name="content" id="content" value=<%= post.Content %>></p>
<button class="btn btn-primary" type="submit">Publish</button>
</form>
<%- include('./partials/footer');-%>
Enclose ejs variable inside quotes.
//enclose like this
value="<%= post.Title %>"
value="<%= post.Content %>"
<h1><input type="text" name="title" id="title" value="<%= post.Title %>"></h1>
<p><input type="text" name="content" id="content" value="<%= post.Content %>"></p>
i don't know why i have this error, i can't find the '/' can anyone help me please.
or tell me why this error can occurs, i spend all the day trying to resolve it ...
<% include ./partials/messages %>
<form action="/register" method="POST">
<div class="form-group">
<label for="first_name">First Name</label>
<input
type="name"
id="first_name"
name="first_name"
class="form-control"
placeholder="Enter first name"
value="<%= typeof first_name != 'undefined' ? first_name : '' %>"
/>
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input
type="name"
id="last_name"
name="last_name"
class="form-control"
placeholder="Enter last name"
value="<%= typeof last_name != 'undefined' ? last_name : '' %>"
/>
</div> ...
Finnaly the error was catched, '<%- include('partials/messages.ejs') %>' this is the correct form to include a partial in ejs.
I can't check the empty or null when I click submit.
When pressing the spacebar, the empty value will be sent to the database.
button can submit pass to sent data to database
Please help.
<form #Register="ngForm">
<div style="width: 500px">
<br/>
<h4>New Reegister</h4>
<br/>
<div class="form-group">
<dt><label for="name">Name</label></dt>
<input [(ngModel)]="name" name="name" type="text" class="form-control" placeholder="input your name" data-bv-notempty-message="The name is required" required>
</div>
<div class="form-group">
<dt><label for="lastname">LastName</label></dt>
<input [(ngModel)]="lastname" name="lastname" type="text" class="form-control" placeholder="input your lastname" data-bv-notempty-message="The lastname is required" required>
</div>
<div class="form-group">
<dt><label for="email2">E-mail</label></dt>
<input [(ngModel)]="email2" name="email2" type="text" class="form-control" placeholder="input your email" data-bv-notempty-message="email" required [pattern]="emailRegex" >
<div class= "p-2 text-danger"> <small>* Require Example : xxxxx#gmail.com</small> </div>
</div>
<div class="form-group">
<dt><label for="password2">Password</label></dt>
<input [(ngModel)]="password2" name="password2" type="password" class="form-control" placeholder="input your password" minlength="4" required>
<div class= "p-2 text-danger"> <small>* Enter atleast 4 characters</small> </div>
</div>
<!--
<div class="form-group">
<label for="password3">Password Confirm</label>
<input [(ngModel)]="password3" name="password3" type="password" class="form-control" placeholder="input your password" required>
</div>
-->
<div class="form-group">
<dt><label for="passwordhint">Password Hint</label></dt>
<input [(ngModel)]="passwordhint" name="passwordhint" type="password" class="form-control" placeholder="input your password" minlength="4" required>
<div class= "p-2 text-danger"> <small>* Enter atleast 4 characters</small> </div>
</div>
<button type="submit" type="reset" class="btn btn-danger" [disabled]="!Register.valid" (click)="Regis()">Save</button>
</div>
</form>
cannot check data null
When pressing the spacebar, the empty value will be sent to the database.
button can submit pass to sent data to database
Please help.
Data " " is a valid data but it's empty, not null. You can make a check by trim function before saving it into database.
For example:
let str = ' ';
console.log(str.length) // Length = 1
str = str.trim();
// Here str = '' and you can check length of it
console.log(str.length) // Length = 0
More detail: trim
This has to go in the submit button.
In this case if the variable 'name' contain only spaces the function 'trim' will reduce its length to 0.
So the database call will happen only if the variable 'name' has a value.
this.name = this.name.trim();
if(name.length) {
// do the database call
} else {
// prompt a message to let the user know that the particular field is empty
}
<form (ngSubmit)="submit(feedbackForm)" #feedbackForm="ngForm">
<div class="form-group" *ngFor="let ques of questions;">
<label for="comment">{{ques.question}}</label>
<textarea
class="form-control"
rows="5"
id = "comment"
name="feedbackAnswers"
ngModel
required>
</textarea>
</div>
<button
type="submit"
class="btn btn-info"
*ngIf=!sendingEmail
[disabled]="!feedbackForm.valid">Save</button>
</form>
on ,
console.log(feedbackForm),
the 'values' property only shows first input. How can I get an array having name i.e 'feedbackAnswers' and having value what use did input.
You have to make the name attribute unique so that the template driven form will create a control for each input in the loop... try the following change. [name]="ques.question"
<form (ngSubmit)="submit(feedbackForm)" #feedbackForm="ngForm">
<div class="form-group" *ngFor="let ques of questions;">
<label for="comment">{{ques.question}}</label>
<textarea
class="form-control"
rows="5"
id = "comment"
[name]="ques.question"
ngModel
required>
</textarea>
</div>
<button
type="submit"
class="btn btn-info"
*ngIf=!sendingEmail
[disabled]="!feedbackForm.valid">Save</button>
</form>
Hello I need to put searching option and value in the URL. I know it's very basic but I have never implement the search function before ever always used the templates one but this time I need to use it. below is my code please help me.
Right now I am getting this in the link
list/%7Boption%7D/%7Bvalue%7D
but I want this in the link list/Hello/thisishelloworld or this may be list/option?Hello/value?thisishelloworld but I think I can get the second option using Get instead of Post method
AND YA ITS IN LARAVEL 5.2
<center>
<div class="form-group">
<label>Select your option from below</label>
<select class="form-control" id="options" name="options" style="width:100%" type="checkbox">
<option>Hello</option>
<option>World</option>
<option>it's Me</option>
</select>
</div>
<div class="col-md-4" id="value">
<div class="panel panel-warning">
<div class="panel-heading">
Enter your Search below
</div>
<form role="form" action="/list/{option}/{value}" method="post">
{{ csrf_field() }}
<div class="form-group has-success">
<input class="form-control" placeholder="Search" type="text" name="{{ value }}" id="value">
<input type="submit" class="btn btn-primary" name="submit" value="Search">
</div>
</form>
</div>
</div>
</center>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function hide() {
$("#value").hide();
$("#h").hide();
$("#search").hide();
}
function show() {
$("#value").show();
$("#h").show();
$("#search").show();
}
function initHandlers() {
$("#options").change(function() {
show();
});
}
hide();
initHandlers();
</script>
Laravel 5. 2
Step 1:
First you have to create a route.
Routes.php :
Route::get('/list', function(){
// do process
})->name('search');
HTML :
something.blade.php :
{!! Form::open('search', ['route' => 'search', 'method' => 'GET']) !!}
<div class="form-group has-success">
<input class="form-control" placeholder="Search" type="text" name="search" id="value">
<input type="submit" class="btn btn-primary" name="submit" value="Search">
</div>
</form>