HTML:
<div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_1" name="pin_selection_1" class="is-pulled-right"> <option value="0"> 0 </option> <option value="1"> 1 </option> <option value="2"> 2 </option> <option value="3"> 3 </option> <option value="4"> 4 </option> <option value="5"> 5 </option> <option value="6"> 6 </option> <option value="7"> 7 </option> <option value="8"> 8 </option> <option value="9"> 9 </option> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_2" name="pin_selection_2" class="is-pulled-right"> <option value="0"> 0 </option> <option value="1"> 1 </option> <option value="2"> 2 </option> <option value="3"> 3 </option> <option value="4"> 4 </option> <option value="5"> 5 </option> <option value="6"> 6 </option> <option value="7"> 7 </option> <option value="8"> 8 </option> <option value="9"> 9 </option> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_3" name="pin_selection_3" class="is-pulled-right"> <option value="0"> 0 </option> <option value="1"> 1 </option> <option value="2"> 2 </option> <option value="3"> 3 </option> <option value="4"> 4 </option> <option value="5"> 5 </option> <option value="6"> 6 </option> <option value="7"> 7 </option> <option value="8"> 8 </option> <option value="9"> 9 </option> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_4" name="pin_selection_4" class="is-pulled-right"> <option value="0"> 0 </option> <option value="1"> 1 </option> <option value="2"> 2 </option> <option value="3"> 3 </option> <option value="4"> 4 </option> <option value="5"> 5 </option> <option value="6"> 6 </option> <option value="7"> 7 </option> <option value="8"> 8 </option> <option value="9"> 9 </option> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_5" name="pin_selection_5" class="is-pulled-right"> <option value="0"> 0 </option> <option value="1"> 1 </option> <option value="2"> 2 </option> <option value="3"> 3 </option> <option value="4"> 4 </option> <option value="5"> 5 </option> <option value="6"> 6 </option> <option value="7"> 7 </option> <option value="8"> 8 </option> <option value="9"> 9 </option> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_6" name="pin_selection_6" class="is-pulled-right"> <option value="0"> 0 </option> <option value="1"> 1 </option> <option value="2"> 2 </option> <option value="3"> 3 </option> <option value="4"> 4 </option> <option value="5"> 5 </option> <option value="6"> 6 </option> <option value="7"> 7 </option> <option value="8"> 8 </option> <option value="9"> 9 </option> </select> </div>
PHP:
if ($request->input('pin_severity') != 'disabled') {
$user->pin_code =
$request->input('pin_selection_6') .
$request->input('pin_selection_5') .
$request->input('pin_selection_4') .
$request->input('pin_selection_3') .
$request->input('pin_selection_2') .
$request->input('pin_selection_1');
}
$user->save();
echo 'pin_selection_1: ' . $request->input('pin_selection_6') . '<br>';
echo 'pin_selection_2: ' . $request->input('pin_selection_5') . '<br>';
echo 'pin_selection_3: ' . $request->input('pin_selection_4') . '<br>';
echo 'pin_selection_4: ' . $request->input('pin_selection_3') . '<br>';
echo 'pin_selection_5: ' . $request->input('pin_selection_2') . '<br>';
echo 'pin_selection_6: ' . $request->input('pin_selection_1') . '<br>';
exit();
I use 6 different select dropdowns to pick a 6 digit pin code, when saving it using the PHP code I am receiving some issues. My database column is an int with length 6 NOT NULL.
When saving the pin as something like 123456 or 223344 it works perfectly and saves correctly. Earlier I tried doing something more complicated, 020304
It went through, but saved in the database as 20304, the strange thing is, my echo displayed it exactly as I entered it, but it saved in the database incorrectly?
Your echos are displayed correctly because they act as strings.
But when you save the pin in your database, Laravel/mysql converts the string to an integer, hence, the mismatch.
If you want it to be inserted as is, change the datatype of your pin_code column to varchar
Related
I'm not sure why in the desktop is working, but on the phone, it showed like this 2 hrs + 2 oz
It seems like it loaded the default value 2. Even if the Chrome simulator showed the wrong only the mobile view. It's a float in the database.
see its value inside the db
Update
public function settingsUpdate($id){
$baby = Baby::where('uuid',$id)->first();
if($baby){
$baby->name = Request::get('name','');
$baby->phone = Request::get('phone','');
$baby->email = Request::get('email','');
$baby->babyName = Request::get('babyName','');
$baby->babyDob = Request::get('babyDob','').' '.Request::get('babyHob','').':00';
$baby->adminCode = Request::get('adminCode','');
$baby->readOnlyCode = Request::get('readOnlyCode','');
$baby->feedingInterval = (float) Request::get('feedingInterval',''); <<<---------- ✨
$baby->feedingAmount = (float) Request::get('feedingAmount',''); <<<---------- ✨
$baby->displayMode = Request::get('displayMode','');
$baby->save();
return Redirect::to('/baby/'.$baby->uuid.'?code='.$baby->adminCode);
} else {
return Redirect::to('/');
}
}
HTML/View
<div class="form-group">
<div class="col-xs-6">
<label for="feedingInterval"><h5>Feeding Interval <small class="helpText">(hours)</small></h5></label>
<select class="form-control" id="feedingInterval" name="feedingInterval">
<option value="2">2 hrs </option>
<option value="2.5">2.5 hrs </option>
<option value="3">3 hrs </option>
<option value="3.5">3.5 hrs </option>
<option value="4">4 hrs </option>
<option value="4.5">4.5 hrs </option>
<option value="5">5 hrs </option>
<option value="5.5">5.5 hrs </option>
<option value="6">6 hrs </option>
</select>
</div>
<div class="col-xs-6">
<label for="feedingAmount"><h5>Feeding Amount <small class="helpText">(ounces)</small></h5></label>
<select class="form-control" id="feedingAmount" name="feedingAmount">
<option value="2">2 oz </option>
<option value="2.5">2.5 oz </option>
<option value="3">3 oz </option>
<option value="3.5">3.5 oz </option>
<option value="4">4 oz </option>
<option value="4.5">4.5 oz </option>
<option value="5">5 oz </option>
<option value="5.5">5.5 oz </option>
<option value="6">6 oz </option>
</select>
</div>
</div>
GET
$('#feedingInterval').val(`{{$baby->feedingInterval}}`.toString());
$('#feedingAmount').val(`{{$baby->feedingAmount}}`.toString());
I have a form where users have dropdowns.. The form have a get method so that the output values is used for processing.. But the problem is i get all the three values which is not able to be used..
<form method="get" action="finish.php">
<select name="case" >
<option value="">*Grimsborough Case*</option>
<option value="1" >001</option>
<option value="2" >002</option>
<option value="3" >003</option>
</select>
<select name="case" >
<option value="">*Pacific Bay Case*</option>
<option value="201" >PB01</option>
<option value="202" >PB02</option>
<option value="203" >PB03</option>
</select>
<select name="case" >
<option value="">*World Edition Case*</option>
<option value="301" >WE01</option>
<option value="302" >WE02</option>
<option value="303" >WE03</option>
</select>
These are the forms that I have the output while i select is something like this..
finish.php?case=&case=&case=302&submit=%3D%3D>+submit+<%3D%3D
I will like to get output like this
finish.php?case=302&submit=%3D%3D>+submit+<%3D%3D
Please help :)
You need to name your select elements differently
<form method="get" action="finish.php">
<select name="case1" >
<option value="">*Grimsborough Case*</option>
<option value="1" >001</option>
<option value="2" >002</option>
<option value="3" >003</option>
</select>
<select name="case2" >
<option value="">*Pacific Bay Case*</option>
<option value="201" >PB01</option>
<option value="202" >PB02</option>
<option value="203" >PB03</option>
</select>
<select name="case3" >
<option value="">*World Edition Case*</option>
<option value="301" >WE01</option>
<option value="302" >WE02</option>
<option value="303" >WE03</option>
</select>
And from your php script, you to do this:
$case1 = $_GET["case1"];
$case2 = $_GET["case2"];
$case3 = $_GET["case3"];
If i understood it right you want something like that:
<select name="case" >
<optgroup label="Grimsborough Case">
<option value="1" >001</option>
<option value="2" >002</option>
<option value="3" >003</option>
</optgroup>
<optgroup label="Pacific Bay Case">
<option value="201" >PB01</option>
<option value="202" >PB02</option>
<option value="203" >PB03</option>
</optgroup>
<optgroup label="World Edition Case">
<option value="301" >WE01</option>
<option value="302" >WE02</option>
<option value="303" >WE03</option>
</optgroup>
</select>
I have this one form and the saving will be using Ajax. The form using Ajax validates well if the input fields are empty. Now my problem is how will I be able to save it into the database.
Here is my form:
<form action="travelrequirementsadd" method="post" class="ajax-form">
<div class="col col-clear-right">
<label for="">Title<em>(required)</em></label>
<input type="text" name="title" id="title" value="">
</div>
<div class="col col6 col-padright-10">
<label for="">From<em>(required)</em></label>
<input type="text" name="from" id="from" value="" placeholder="e.g Cebu">
</div>
<div class="col col6 col-padleft-10">
<label for="">To<em>(required)</em></label>
<input type="text" name="to" id="to" value="" placeholder="e.g Manila">
</div>
<div class="col col6 col-padright-10">
<label for="">Departure<em>(required)</em></label>
<div class="input-group date">
<input type="text" name="departureDate" id="departureDate" class="form-control" placeholder="Select Departure Date">
<span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
<div class="col col6 col-padleft-10">
<label for="">Return<em>(required)</em></label>
<div class="input-group date">
<input type="text" class="form-control" name="returnDate" id="returnDate" placeholder="Select Return Date">
<span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
<div class="col col4 col-padright-15">
<label for="">Adults 12 + Yrs<em>(required)</em></label>
<select class="form-control" name="adults" id="adults">
<option value="Select">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div class="col col4 col-padright-5 col-padleft-5">
<label for="">Children 2 - 12 Yrs<em>(required)</em></label>
<select class="form-control" name="children" id="children">
<option value="Select">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div class="col col4 col-padleft-15">
<label for="">Infants 0 - 2 Yrs<em>(required)</em></label>
<select class="form-control" name="infants" id="infants">
<option value="Select">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div class="col col4 col-padright-15">
<label for="sel1">Preferred Airline<em>(required)</em></label>
<select class="form-control" id="sel1" name="preferredAirline" id="preferredAirline">
<option value="Select">Any</option>
<option value="1">Aer Lingus </option>
<option value="2">Aeroflot </option>
<option value="3">Aerolineas Argentinas </option>
<option value="4">Aeromexico</option>
<option value="5">Air Canada</option>
<option value="6">Air China</option>
<option value="7">Air Europa </option>
<option value="8">Air France </option>
<option value="9">Air India </option>
<option value="10">Air India Express </option>
<option value="11">Air New Zealand </option>
<option value="12">Air Tahiti Nui </option>
<option value="13">Air Transat </option>
<option value="14">Air Vanuatu </option>
<option value="15">AirAsia </option>
<option value="16">AirAsia X </option>
<option value="17">Airberlin </option>
<option value="18">Alaska Airlines </option>
<option value="19">Alitalia </option>
<option value="20">Allegiant </option>
<option value="21">American Airlines </option>
<option value="22">ANA </option>
<option value="23">Asiana </option>
<option value="24">AtlasGlobal </option>
<option value="25">Austrian </option>
<option value="26">Avianca </option>
<option value="27">Bangkok Airways </option>
<option value="28">British Airways </option>
<option value="29">Brussels Airlines </option>
<option value="30">Cathay Pacific </option>
<option value="31">CEBU Pacific Air </option>
<option value="32">China Airlines </option>
<option value="33">China Eastern </option>
<option value="34">China Southern </option>
<option value="35">Condor </option>
<option value="36">Copa Airlines </option>
<option value="37">Czech Airlines </option>
<option value="38">Delta </option>
<option value="39">Dragonair </option>
<option value="40">EasyJet </option>
<option value="41">EL AL </option>
<option value="42">Emirates </option>
<option value="43">Ethiopian Airlines </option>
<option value="44">Etihad </option>
<option value="45">EVA Air </option>
<option value="46">Fiji Airways </option>
<option value="47">Finnair </option>
<option value="48">Frontier </option>
<option value="49">Garuda Indonesia </option>
<option value="50">Germanwings </option>
<option value="51">Gol </option>
<option value="52">Gulf Air </option>
<option value="53">Hainan Airlines </option>
<option value="54">Iberia </option>
<option value="55">Icelandair </option>
<option value="56">IndiGo Airlines </option>
<option value="57">Japan Airlines </option>
<option value="58">Jet Airways </option>
<option value="59">JetBlue </option>
<option value="60">Jetstar </option>
<option value="61">Kenya Airways </option>
<option value="62">KLM </option>
<option value="63">Korean Air </option>
<option value="64">LAN Airlines </option>
<option value="65">Lion Airlines </option>
<option value="66">LOT Polish Airlines </option>
<option value="67">Lufthansa </option>
<option value="68">Malaysia Airlines </option>
<option value="69">Monarch </option>
<option value="70">Nok Air </option>
<option value="71">Norwegian </option>
<option value="72">Oman Air </option>
<option value="73">OpenSkies </option>
<option value="74">Peach </option>
<option value="75">Philippine Airlines </option>
<option value="76">Porter </option>
<option value="77">Qantas </option>
<option value="78">Qatar Airways </option>
<option value="79">Regional Express </option>
<option value="80">Royal Brunei </option>
<option value="81">Royal Jordanian </option>
<option value="82">Ryanair </option>
<option value="83">S7 Airlines </option>
<option value="84">SAS </option>
<option value="85">Saudia </option>
<option value="86">Scoot Airlines </option>
<option value="87">Singapore Airlines </option>
<option value="88">Skylanes </option>
<option value="89">South African Airways </option>
<option value="90">Southwest </option>
<option value="91">SpiceJet </option>
<option value="92">Spirit </option>
<option value="93">Spring Airlines </option>
<option value="94">Spring Japan </option>
<option value="95">SriLankan Airlines </option>
<option value="96">Sun Country </option>
<option value="97">SWISS </option>
<option value="98">TACA </option>
<option value="99">TAM </option>
<option value="100">TAP Portugal </option>
<option value="101">THAI </option>
<option value="102">Thomas Cook Airlines </option>
<option value="103">Thomson </option>
<option value="104">Tigerair </option>
<option value="105">Tuifly </option>
<option value="106">Turkish Airlines </option>
<option value="107">United </option>
<option value="108">Vanilla Air </option>
<option value="109">Virgin America </option>
<option value="110">Virgin Atlantic </option>
<option value="111">Virgin Australia </option>
<option value="112">Volaris </option>
<option value="113">Vueling Airlines </option>
<option value="114">WestJet </option>
<option value="115">Wizzair </option>
<option value="116">WOW air </option>
</select>
</div>
<div class="col col4 col-padleft-15">
<label >Senior Citizen<em>(required)</em></label>
<select name="seniorCitizen" id="seniorCitizen"class="form-control">
<option value="select">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</div>
<div class="col col4 col-padright-5 col-padleft-5">
<label for="">Visa needed<em>(required)</em></label>
<select name="visaNeeded" id="visaNeeded" class="form-control">
<option value="select">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div class="col col4 col-padright-5 col-padleft-5">
<label for="">Passport needed<em>(required)</em></label>
<select name="passportNeeded" id="passportNeeded" class="form-control">
<option value="select">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div class="col col4 col-padleft-15">
<label for="checktourpackage" >Travel requirements<em>(required)</em></label>
<select name="travelRequirements" id="travelRequirements" class="form-control">
<option value="select">Select</option>
<option value="1">Tour only</option>
<option value="2">Tickets only</option>
<option value="3">Tour and Tickets</option>
</select>
</div>
<div class="col col4 col-padleft-5">
<label for="checktourpackage" >Hotel<em>(required)</em></label>
<select name="hotel" id="hotel" class="form-control">
<option value="select">Select</option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>
</div>
<div class="col">
<label for="">Other travel details<em>(required)</em></label>
<textarea name="otherTravelDetails" id="otherTravelDetails"></textarea>
</div>
<div class="post-quotation-footer">
Cancel
<input type="submit" value="Post Travel Requirements" class="btn btn-success" />
</div>
</form>
I'm using a class="ajax-form" to call the Ajax function to validate and to be saved also.
Here is my code:
//travel requirements add
function ajax_travelrequirementsadd(){
if (Auth::guest()) exit;
$title = $_POST['title'];
$from = $_POST['from'];
$to = $_POST['to'];
$departureDate = $_POST['departureDate'];
$returnDate = $_POST['returnDate'];
$adults = $_POST['adults'];
$children = $_POST['children'];
$infants = $_POST['infants'];
$preferredAirline = $_POST['preferredAirline'];
$seniorCitizen = $_POST['seniorCitizen'];
$visaNeeded = $_POST['visaNeeded'];
$passportNeeded = $_POST['passportNeeded'];
$travelRequirements = $_POST['travelRequirements'];
$hotel = $_POST['hotel'];
$otherTravelDetails = $_POST['otherTravelDetails'];
//$user = User::find(Auth::user()->id);
//$travelForm = TravelRequirement::find(Auth::user()->id);
$data = array(
'title' => $title,
'from' => $from,
'to' => $to,
'departureDate'=>$departureDate,
'returnDate' =>$returnDate,
'adults' =>$adults,
'children'=>$children,
'infants'=>$infants,
'preferredAirline'=>$preferredAirline,
'seniorCitizen'=>$seniorCitizen,
'visaNeeded'=>$visaNeeded,
'passportNeeded'=>$passportNeeded,
'travelRequirements'=>$travelRequirements,
'hotel'=>$hotel,
'otherTravelDetails'=>$otherTravelDetails
);
$rules = array(
'title' => "required",
'from' => "required",
'to' => "required",
'departureDate' => "required",
'returnDate' => "required",
'adults' => "required|Numeric",
'children' => "required|Numeric",
'infants' => "required|Numeric",
'preferredAirline'=>"required|Numeric",
'seniorCitizen'=>"required|Numeric",
'visaNeeded'=>"required|Numeric",
'passportNeeded'=>"required|Numeric",
'travelRequirements'=>"required|Numeric",
'hotel'=>"required|Numeric",
'otherTravelDetails'=>"required"
);
$validator = Validator::make($data, $rules);
if($validator->passes()){
//$travelForm = new TravelRequirements();
//$travelForm->save();
}else{
json_message($validator->errors()->toArray(), false);
}
}
Can someone help me how will I be able to save into the database?
Any help is appreciated.
one way is
if($validator->passes()){
TravelRequirement::create($data);
}
another way is
if($validator->passes()){
$travelRequirement = new TravelRequirement;
$travelRequirement->title = $title;
$travelRequirement->from = $from;
$travelRequirement->to = $to;
$travelRequirement->departureDate= $departureDate;
$travelRequirement->returnDate = $returnDate;
$travelRequirement->adults = $adults;
$travelRequirement->children= $children;
$travelRequirement->infants= $infants;
$travelRequirement->preferredAirline= $preferredAirline;
$travelRequirement->seniorCitizen= $seniorCitizen;
$travelRequirement->visaNeeded= $visaNeeded;
$travelRequirement->passportNeeded= $passportNeeded;
$travelRequirement->travelRequirements= $travelRequirements;
$travelRequirement->hotel= $hotel;
$travelRequirement->otherTravelDetails= $otherTravelDetails;
$travelRequirement->save();
}
I have a form with dropdown choice
<select id="ubytovanie" name="ubytovanie">
<option value=""> </option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
<option value="6"> 6 </option>
<option value="7"> 7 </option>
<option value="8"> 8 </option>
<option value="9"> 9 </option>
<option value="10"> 10 </option>
<option value="11"> 11 </option>
<option value="12"> 12 </option>
</select>
In my form you can choose room number in which you would like to stay. But there can be only 6 people in one room, so I need to limit the option so max 6 people can choose same room number. After that, the option with room number would be disabled for other people filling out the form.
Is there a way to do this, ideally with PHP?
Thanks for answer
My html code is like below
<select multiple="multiple" size="2" name="exServer[]">
<option value="1"> host.newcybage.alabanza.com </option>
<option value="2"> host2.newcybage.alabanza.com </option>
<option value="3"> host3.newcybage.alabanza.com </option>
<option value="5"> host3.devel.php5.qa.alabanza.com </option>
<option value="7"> centos5host2.alabanza.com </option>
<option value="8"> centos5host.template.alabanza.com </option>
</select>
<input type="submit" value="Apply" name="exSubmit" class="button">
And my php code is like below
$arr=$_POST['exServer'];
print_r($_POST['exServer']);
print_r($arr);
Both print statements are giving me no results.
I dont know where i am wrong in getting selected multiple dropdown values.
I verified using HttpFox that data is getting posted properly on server side.
When i am printing value of exSubmit, it is giving me proper values.
print "Exsubmit:".$_POST['exSubmit']; //Result Exsubmit:Apply
Please help.
you code is working. I tried this and got all the selected values in PHP
<?php
$arr=$_POST['exServer'];
print_r($_POST['exServer']);
print_r($arr);
?>
<form method="post">
<select multiple="multiple" size="2" name="exServer[]">
<option value="1"> host.newcybage.alabanza.com </option>
<option value="2"> host2.newcybage.alabanza.com </option>
<option value="3"> host3.newcybage.alabanza.com </option>
<option value="5"> host3.devel.php5.qa.alabanza.com </option>
<option value="7"> centos5host2.alabanza.com </option>
<option value="8"> centos5host.template.alabanza.com </option>
</select>
<input type="submit" value="Apply" name="exSubmit" class="button">
</form>
This should work
<select multiple="multiple" size="2" name="exServer[]">
<option value="1"> host.newcybage.alabanza.com </option>
<option value="2"> host2.newcybage.alabanza.com </option>
<option value="3"> host3.newcybage.alabanza.com </option>
<option value="5"> host3.devel.php5.qa.alabanza.com </option>
<option value="7"> centos5host2.alabanza.com </option>
<option value="8"> centos5host.template.alabanza.com </option>
</select>
My suggestion is to print the array $_POST and see the values passed in the backend.
<?php
print_r($_POST);
?>