i have a Form with different inputs. Now I call GET and want to give all information to another site.
<form action="/listShifts" method="GET">
<div class="row">
<div class="m-1 col-sm-3">
<label class="control-label"><spring:message
code="shifts.startdate"/></label>
<input type="date" class="form-control" value="">
</div>
<div class="m-1 col-sm-3">
<label class="control-label"><spring:message
code="shifts.enddate"/></label>
<input type="date" class="form-control" value="">
</div>
<div class="m-1 col-sm-3">
<label class="control-label"><spring:message
code="shiftstatus.name"/></label>
<select name="stateId" class="form-control">
<option value=""><spring:message code="shifts.selectshiftstate"/></option>
<option value=""><spring:message code="shifts.allstates"/></option>
<c:forEach items="${states}" var="state">
<option value="${state.stateId}">${state.stateName}</option>
</c:forEach>
</select>
</div>
<button type="submit" class="mt-4 btn btn-outline-info align-self-center"><spring:message
code="shifts.filter2"/></button>
</form>
The state ID is written to the URL. The date not. How can i change this? Don´t know how to fix that problem.
You need to add name parameter to your inputs to submit through forms.
If you want to submit date, Just add name attribute to your date field.
<div class="m-1 col-sm-3">
<label class="control-label">
<spring:message code="shifts.startdate"/>
</label>
<input type="date" class="form-control" value="" name="start_date">
</div>
<div class="m-1 col-sm-3">
<label class="control-label">
<spring:message code="shifts.enddate"/>
</label>
<input type="date" class="form-control" value="" name="end_date">
</div>
Now, you are getting only state, Because you added name attribute only to your state dropdown.
<select name="stateId" class="form-control">
...
Related
Good day all I have a simple laravel project that takes some information about actors and saves it in a json file after the user fills in the form.My problem is that I save simple data like name, surname, nationality ,age I need a Id something like "edf33e5751b2ea2fd25ad118edbc647e" to save the data in a json file by using arrays.How do I take the user input data from the form add an ID to the data so I can save it to a json file and later use the data by ID?
This is my form where I get my data and send it to my controller to be saved.
<form method="POST" action="{{route('actor.store')}}">
#csrf
<div class="form-row">
<div class="form-group col-md-6">
<label for="input">Actor Name</label>
<input type="text" class="form-control" placeholder="Actor Name" name ="name" required="required" minlength="3" maxlegnth="30">
</div>
<div class="form-group col-md-6">
<label for="input">Actor Surname</label>
<input type="text" required="required" minlength="3" maxlegnth="30" class="form-control" id="actorSurname" placeholder="Actor Surname" name ="surName">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="input">Actor Nationallity</label>
<select id="nationallity" class="form-control" name ="nationallity" required="required" minlength="3" maxlegnth="30" >
<option selected>--Select Actor Nationallity.</option>
<option>South African</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="input">Actor Age</label>
<input type="number" required="required" class="form-control" id="actorAge" placeholder="Actor Age" name ="age">
</div>
</div>
<a class="btn btn-primary" href="/actor/index" role="button">Back to List</a>
<button type="submit" class="btn btn-primary">Create</button>
</form>
I am using an html with div tag to do a booking system asking user input for city, date, and pet type then check the criteria from users to the SQL database, I know how to deal with just html but I am totally lost when dealing with html div tags.
Can anyone show me how to take the user inputs (city, date, and pet type) using php in the right place so i can pass it to the database to check
<div class="form-group">
<span class="form-label">Where do you work? </span>
<input class="form-control" type="text" placeholder="Please enter your city">
</div>
<!-- date picker -->
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Please take care of my pet on</span>
<input class="form-control" type="date", id="pickup" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Pet?</span>
<select class="form-control">
<option>Cat</option>
<option>Dog</option>
<option>Others</option>
</select>
<span class="select-arrow"></span>
</div>
</div>
</div>
<div class="form-btn">
<button class="submit-btn">Check availability</button>
</div>
First of all, your inputs ,buttons,select,radio buttons..etc must be inside a form tag
<form method="post/get" action="file.php">
Secondly, all your inputs need to have a name to retrieve their values. For exemple :
<input type="text" name="firstname">
And finally, it's better to giver every option in select tag a value:
<select class="form-control" name="pet">
<option value="cat">Cat</option>
<option value="dog">Dog</option>
<option value="others">Others</option>
</select>
Changed work :
<form method="post" action"file.php">
<div class="form-group">
<span class="form-label">Where do you work? </span>
<input class="form-control" type="text" placeholder="Please enter your city" name="city">
</div>
<!-- date picker -->
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Please take care of my pet on</span>
<input class="form-control" type="date", id="pickup" name="pickup" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Pet?</span>
<select class="form-control" name="pet">
<option value="cat">Cat</option>
<option value="dog">Dog</option>
<option value="others">Others</option>
</select>
<span class="select-arrow"></span>
</div>
</div>
</div>
<div class="form-btn">
<button class="submit-btn">Check availability</button>
</div>
</form>
In your file.php you need to retrieve data with $_POST :
<?php
$city=$_POST['city'];
$date=$_POST['pickup'];
$pet=$_POST['pet'];
?>
First of all, you have to wrap all this code in <form></form> tag:
<form method="post" action="path_to_your_php_handler">
<div class="form-group">
<!-- other stuff -->
<button type="submit" class="submit-btn">Check availability</button>
</div>
</form>
Also, all your inputs should have an unique attribute name, like <input class="form-control" type="date", id="pickup" name="date" required>
Than, in your php file, you can find your input values in array $_POST, like $_POST['date'] from the input with name 'date'.
I'm trying to write a php script that takes the input from this form and creates an array with a unique key for each input box/text boxes content.
<div class="container">
<div class="row">
<div class="col-3 mx-auto">
<form action="adminhandler.php">
<div class="form-group">
<label for="product name">Enter product name</label>
<input type="text" class="form-control" id="productName" aria-describedby="emailHelp" placeholder="" name="productname">
</div>
<div class="form-group">
<label for="product name">Select product category</label>
<select name="select" class=" custom-select">
<option selected>Open this select menu</option>
<option value="1">Formal Shoes</option>
<option value="2">Sneakers</option>
<option value="3">Tracksuits</option>
<option value="3">Clothing</option>
<option value="3">Accessories</option>
</select>
</div>
<div class="form-group">
<label for="product price">Enter product price(Naira)</label>
<input type="text" class="form-control" id="productPrice" aria-describedby="emailHelp" placeholder="" name="price">
</div>
<div class="form-group">
<label for="product name">Select image</label>
<input type="file" class="form-control-file" id="productimage" aria-describedby="emailHelp" placeholder="">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
I think you want to use a form as an array and then pass the same data as an array.If you are using the $_POST, you will need to use the name attribute of HTML. And use something like this :
<input name="person[1][first_name]" value="jane" />
This when passing through PHP will be sent as Array.
Here is the reference :
http://php.net/manual/en/reserved.variables.post.php
An Excerpt from one of the contributors :
<form>
<input name="person[0][first_name]" value="john" />
<input name="person[0][last_name]" value="smith" />
<input name="person[1][first_name]" value="jane" />
<input name="person[1][last_name]" value="jones" />
</form>
When Trying To Process Values using PHP
<?php
var_dump($_POST['person']);
//will get you something like:
array (
0 => array('first_name'=>'john','last_name'=>'smith'),
1 => array('first_name'=>'jane','last_name'=>'jones'),
)
?>
I've read the other answers to my question regarding combining both the select and text fields, but when I try to apply any of the solutions to my form it does not work.
Can someone modify my form so that you end up with a dropdown containing both the select options and a text input field?
Please include the appropriate jquery script as well.
Here is my form code:
<form id="ajax-contact-form" action="drumming_for_jared_registration.php" method="post">
<div class="row">
<div class="span12">
<div class="control-group">
<label class="control-label" for="inputName">Date:</label>
<div class="controls">
<input class="span4" type="text" id="inputName" name="Date" placeholder="Date:" style="color:white" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='Date:' ) this.value=''">
</div>
</div>
</div>
<div class="row"></div>
<div class="span4">
<div class="control-group">
<label class="control-label" for="inputName">New To Studio?</label>
<div class="controls">
<select input class="span14" type="text" id="inputLevel" name="New_to_Studio">
<option>New To Studio?</option>
<option>Yes</option>
<option>No</option>
</select>
</div>
</div>
</div>
<div class="row"></div>
</div>
<button type="submit" class="submit">Send</button>
</form>
I am working on a website which I didn't create and to which I do not have full access (I can create a page and add html scripts but not much more)
I am trying to add a form which will send data to be processed by a third-party servlet.
I am trying to include in this form the client ID, which I saw can be retrieved using the php functionsession_id().
My question is, how to send this information along with the rest of the input data.
my form for now is this:
<form class="form-horizontal" action = "url" method="POST" target="_blank">
<fieldset>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Culture</label>
<div class="col-md-4">
<select id="Crop" name="Crop" class="form-control">
<option value="1">Maïs</option>
<option value="2">Ble</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Produit</label>
<div class="col-md-4">
<select id="Product" name="Product" class="form-control">
<option value="Iodure d'azote">Iodure D'azote</option>
<option value="Desherbant">Desherbant</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="area">Surface</label>
<div class="col-md-4">
<input id="Area" name="Area" type="text" placeholder=" " class="form-control input-md" required="">
<span class="help-block">en Ha</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="dose">Dosage</label>
<div class="col-md-4">
<input id="Dose" name="Dose" type="text" placeholder="" class="form-control input-md" required="">
<span class="help-block">en L/Ha</span>
</div>
</div>
<div class="form-group">
<!--need to get the actual id-->
<input type="hidden" value="1" name = "ID"/>
<input type="submit" value="Ajouter" />
</div>
</fieldset>
</form>
Since this is my first time handling web apps, is there something obvious i'm missing?
OK i was lacking basic understanding of php. sorry for bothering,
the answer was here
i just had to write
<input type="hidden" value="<?php echo session_id();?>" name = "ID"/>
instead of
<input type="hidden" value="1"name = "ID"/>