This is my HTML:
<form action="http://example.com/rezervari/index.html#/hotelbooking" method="get">
<input type="hidden" name="hotel" value="<?= $hotel ?>" class="form-control">
<input type="hidden" name="roomtypegroups" value="<?= $roomtypegroups ?>" class="form-control">
<div class="form-row">
<div class="col">
<div class="form-group">
<label>Sosire</label>
<div class="input-group mb-3">
<input id="from" type="text" name="from" value="<?= $arrival == 'CURRENT' ? date('Y-m-d') : $arrival ?>" class="form-control datepicker1">
<div class="input-group-append datepicker1-h">
<span class="input-group-text" id="basic-addon2"><i class="fa fa-calendar-check-o" aria-hidden="true"></i></span>
</div>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<label>Plecare</label>
<div class="input-group mb-3">
<input id="to" type="text" name="to" value="<?= $arrival == 'CURRENT' ? date('Y-m-d', strtotime(date('Y-m-d') . ' ' . $departure . ' day')) : date('Y-m-d', strtotime($arrival . ' ' . $departure . ' day')) ?>" class="form-control datepicker2">
<div class="input-group-append datepicker2-h">
<span class="input-group-text" id="basic-addon2"><i class="fa fa-calendar-times-o" aria-hidden="true"></i></span>
</div>
</div>
</div>
</div>
</div>
When I submit the form, the URL loses the "#" and messes it up, and that's no good because the query doesn't work on the secondary website, as it becomes:
http://example.com/rezervari/index.html?hotel=14315&roomtypegroups=44332&from=2020-11-23&to=2020-11-24&roomscount=1&adult=1#/hotelbooking
Instead, it should be:
http://example.com/rezervari/index.html#/hotelbooking?hotel=14315&roomtypegroups=44332&from=2020-09-91&to=2020-09-14&adult=1&numchild1=1&numchild2=1&numchild3=1
How can I pass on the link without the "#" getting removed and the whole URL messed up? Thanks!
Fragment IDs are supposed to link to a specific part of a webpage and are resolved client-side.
Consequently they must go after the query string.
When you submit a GET method form, it will replace everything after the start of the query string in the action with the newly generated query string.
If you have some kind of hack which reads the fragment ID client-side, and you need to put the query string inside the fragment ID so that that code can read it, you can't use the standard form submission logic.
You'll need to add a submit event handler to the form with JavaScript, prevent the default action, build the URL yourself and then navigate to it (e.g. by assigning it to location).
Related
I have this code that I receive from database a formated data of a social security number.
<div class="col-md-3">
<h5>Social Security #:<span class="text-danger">*</span></h5>
<div class="controls">
<div id="show-create">
<input type="number" id="social-security" name="social-security" class="form-control" value="123-45-6789">
</div>
</div>
</div>
When I check Element on Chrome, I have the value="123-45-6789", but is not showing on front end.
You have an <input type="number">, which is used only for numbers. But "123-45-6789" is not a number:
<input type="number" value="123-45-6789">
Since you're trying to display a text value, use an <input type="text"> instead:
<input type="text" value="123-45-6789">
Basically, just because text contains number characters does not mean that it is a number. Social security numbers, phone numbers, address components, etc.
HTML input with type='number' only allow numeric values such as 50, -10, or -45.3. Since your input value 123-45-6789 contains a dash in the middle, it's not a numeric value but a string. Change the input type from number to text, and it will work.
From
type="number"
To
type="text"
Full code
<div class="col-md-3">
<h5>Social Security #:<span class="text-danger">*</span></h5>
<div class="controls">
<div id="show-create">
<?php foreach ($peoples as $row) { ?>
<input type="text" id="social-security" name="social-security" class="form-control" value="<?php echo htmlspecialchars ($row['social-security'])?>">
<?php } ?>
</div>
</div>
</div>
My view:
<div class="col-md-3">
<div class="form-group">
<label>Employee Id</label>
<input type="text" class="form-control" placeholder="Enter employee id" name="empid">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Employee Name</label>
<input type="text" class="form-control" placeholder="Enter employee name" name="empname">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Order Number</label>
<input type="number" class="form-control" placeholder="Enter order number" name="ordernumber" value="<?php echo $order_number;?>">
</div></div>
<div class="col-md-3">
<div class="form-group">
<label></label>
<a onclick="myFunctionfirst()" class="form-control">Proceed to order Create</a>
</div></div>
Once you click on 'proceed to order create' the second row is created. I want this to happen only when the first 3 fields in first row are filled. Please suggest on this
And this is my controller:
public function index()
{
$empid = $_POST['empid'];
If ($empid == ""){
$this->load->model('invoice_model');
$data['stat']= $this->invoice_model->get_stationary();
$data['order_numbers']= $this->invoice_model->get_countnumber();
$data['order_number']= $data['order_numbers'][0]->count+1;
$data['page']='invoice/invoice_view';
$this->load->view("template",$data);
}
}
And it's throwing an error undefined index empid
Welcome to stackoverflow. what you can do is save the input as a variable Store input from a text field in a PHP variable
this method is however a bit unsafe. to secure the input you can use https://www.w3schools.com/php/func_string_htmlspecialchars.asp
https://www.php.net/manual/en/function.htmlspecialchars.php
and once you have the variables just simply check if the variable is empty or not
public function index()
{
$firstname = $_POST['firstname'];
If ($firstname != ""){
$this->load->model('invoice_model');
$data['stat']= $this->invoice_model->get_stationary();
$data['order_numbers']= $this->invoice_model->get_countnumber();
$data['order_number']= $data['order_numbers'][0]->count+1;
$data['page']='invoice/invoice_view';
$this->load->view("template",$data);
}
}
$_POST is how the data is being send. here they explain the difference between POST and GET https://www.quora.com/What-is-the-difference-between-PHPs-get-method-post-method
'firstname' is the name of the input. in your case its <input type="text" class="form-control" placeholder="Enter employee id" name="empid"> so it should be $_POST['empid']
the data is being send with the submit button. instead of using the <a> tag you should use the <button type="submit"> tag also, wrap the inputs in a form tag.
I am trying to send the data from the database to the Html form, but I'm getting an error like this
TypeError: 'ImmutableMultiDict' objects are immutable
this is the flask code for editing the data
#app.route('/edit-project/<string:id>', methods = ['GET', 'POST'])
def edit_project(id):
project = Project.query.get(id)
request.form['title'] = project.title
request.form['link'] = project.link
request.form['description'] = project.description
if request.method == 'POST':
title = request.form['title']
link = request.form['link']
description = request.form['description']
image = request.files['image']
image.save(os.path.join(app.config["IMAGE_UPLOADS"], 'project/'+ project.image))
return render_template('project/edit_project.html')
The Html template 'edit_project.html' is shown below
<div class="container">
<form method="POST" id="project-form" enctype="multipart/form-data">
<div class="form-group">
<input type="text" name="title" class="form-control" id="title" placeholder="Title">
</div>
<div class="form-group">
<input type="text" name="link" class="form-control" id="title" placeholder="Project Link">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Description</label>
<textarea id = project-form name="description" class="form-control" id="description" rows="3"></textarea>
</div>
<div class="input-group" style="width: 30%;">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
</div>
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
<label class="custom-file-label" for="inputGroupFile01">Upload image</label>
</div>
</div>
<div class="form-group" style="padding-top: 2rem;">
<button type="submit" class="btn btn-primary">Publish</button>
</div>
</form>
</div>
Is there is any way to display the data in the form without using WTForms or do I've to use WTForms instead?
Thanks in advance.
Can you use jinja templating?
render_template() takes data argument. You can pass the data from your DB to that call and use jinja templates in HTML to render it. Setting the values of your input will do.
For example:
Your data is data = {title:"apple"}
And, return render_template("project/edit_project.html", data=data) will provide you data object in HTML file.
There, you can use jinja like this:
<div class="form-group">
<input type="text" name="title" class="form-control" id="title" placeholder="Title" value={{data.text}}>
</div>
Hope it helps!
I am trying to create a search form similar to the one found on eBay
using bootstrap. I would like to combine my input and select fields so that they look as the input and select fields in the eBay search bar, but I can't seem to format it to make it look like it.
This is what I have so far:
<form class="form-inline text-center" style="padding-top:50px" role="form" method="get" action="addauction.php">
<fieldset style="padding-top:50px">
<!-- Search Name -->
<div class="form-group">
<label class="sr-only" for="item-name">Product Name</label>
<input id="item-name" name="item-name" placeholder="Product Name" class="form-control">
</div>
<!-- Search Category -->
<div class="form-group">
<label class="sr-only" for="item-category">Product Category</label>
<select id="item-category" name="item-category" class="form-control">
<option selected disabled hidden>Category</option>
<?php
$sql = 'SELECT * FROM Category';
foreach ($db -> query($sql) as $row) { ?>
<option value = "<?php echo $row['category_id']; ?>"><?php echo $row['category']; ?></option>
<?php } ?>
</select>
</div>
<!-- Search Auction -->
<div class="form-group">
<label class="sr-only" for="submit">Ready to Submit?</label>
<button type="submit" class="btn btn-primary"><span
class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
</div>
</fieldset>
</form>
And this is how it looks:
https://jsfiddle.net/DTcHh/17749/
I have been reading about using input-group but from what I have gathered it makes it way harder to get the selected value. Any help on how to amend my code so that it looks like the eBay search form by only modifying the HTML or CSS would be deeply appreciated.
Thanks in advance!
I'm using this code for a form in HTML:
<div class="login-wrapper">
<form>
<div class="popup-header">
<span class="text-semibold"><i class="fa fa-sign-in"></i> Logging in</span>
</div>
<div class="well">
<div class="form-group has-feedback">
<label>Username</label>
<input type="text" name="user" class="form-control" placeholder="e.g. andre#mail.de">
<i class="icon-users form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Password">
<i class="icon-lock form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<label>reCaptcha</label>
<div class="g-recaptcha" data-sitekey="..."></div>
</div>
<div class="form-actions text-right">
<input type="submit" id="loginbutton" name="loginbutton" value="Login" class="btn btn-primary">
</div>
</div>
</form>
</div>
<!-- /login wrapper -->
However, when I press the submit button, it does nothing but giving me a very strange url in my browser's address bar:
http://localhost/?user=&password=&g-recaptcha-response=&loginbutton=Login
Whenever I fill out fields, it kind of puts the content into the URL:
http://localhost/?user=peter%40griffin.com&password=somepass&g-recaptcha-response=&loginbutton=Login
The intended PHP code which should be run when pressing the button won't even run or load, since this HTML stuff apparently screws things up. I don't know what I have done the wrong way. Any suggestions?
In order for the form to submit somewhere else, you need to set the form elements action parameter.
<form action="some_file.php">
Alternatively, you can take the query string and append it directly to the file path to test your script.
http://localhost/some_file.php?user=peter%40griffin.com&password=somepass&g-recaptcha-response=&loginbutton=Login
Inside of some_file.php, you would then pull out each of the variables like
$user = $_GET['user'];
$password = $_GET['password'];
The very strange url is actually the result of a GET request.
The parameters are separated by an & so you have:
user=peter%40griffin.com&password=somepass&g-recaptcha-response=
"User" is the attribute name of your input and "peter%40griffin.com" is the value
First you need to send your form to an action using the attribute action="save.php", for example an pass the parameters using the method="POST", so the user can't see the values in the URL.
<form action="save.php" method="post">