yii2 remove optgroup from dropdownlist - forms

How can i remove the optgroup from a checkbox field
<?= $form->field($model, 'survey_type')->dropDownList([$surveyTypeList],['prompt'=>'Select Survey Type','id'=>'Survey_Type_dropdown']) ?>
provides following html
<label class="control-label" for="Survey_Type_dropdown">Type</label>
<select id="Survey_Type_dropdown" class="form-control" name="Surveys[survey_type]">
<option value="">Select Survey Type</option>
<optgroup label="0">
<option value="2D">2D</option>
<option value="3D">3D</option>
</optgroup>
</select>
<div class="help-block"></div>

You have to send $surveyTypeList as a variable, not a array.
Just remove [].

Related

Load dropdown item but disable for selection

So I want to be able to load the 'Choose' dropdown option, but disable it as soon as a change is made on the drop-down.
I've attempted adding a disabled attribute tag on the selection, but it loads on 'Alabama' and I don't want that.
How would I be able to tackle this?
<div class="row mt-3">
<div class="col-md">
<label for="resident">I am a resident of:</label>
</div>
</div>
Adding hidden and selected to the first option should do the trick.
<div class="row mt-3">
<div class="col-md">
<label for="resident">I am a resident of:</label>
<select class="custom-select" id="resident" required>
<option hidden selected value="">Choose...</option>
<option>Alabama</option>
<option>Alaska</option>
<option>Colorado</option>
<option>New York</option>
<option>South Dakota</option>
</select>
<div class="invalid-feedback">
Select state of residence.
</div>
</div>
</div>
If you want to still see the "Choose..." after the user has made a selection, replace hidden with disabled.
Why don't you disable the first option? (no javascript is needed and the result is like what you want to achieve I think):
<div class="row mt-3">
<div class="col-md">
<label for="resident">I am a resident of:</label>
<select class="custom-select" id="resident" required>
<option value="" disabled>Choose...</option>
<?php foreach (Vars::states() as $abbr => $state): ?>
<option value="<?= $abbr; ?>"><?= $state; ?></option>
<?php endforeach; ?>
</select>
<div class="invalid-feedback">
Select state of residence.
</div>
</div>
</div>
And a demo code snippet of what it looks like:
<select required>
<option value="" disabled selected>Select your option</option>
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">...</option>
</select>

Codeigniter - Error While Passing Variables From Container to View

Hi I want to Pass input elements values while clicking button using post method and pass values to next view using CI. When submitting the button with values in input elements and redirecting it works well. But When I'm refreshing after redirecting the page the values of input elements are lost and shows blank page/the page i display when the value becomes null.
1st View
<form action="<?php echo base_url() ?>Mapcontrol/display_garage_by_location" method="post">
<div class="section_1">
<select id="cmbcity" name="cmbcity" class="frm-field required">
<option value="null">Select Your City</option>
<option value="1">fghfghfghf</option>
<option value="2">fghfghfgh</option>
<option value="3">fghfgh</option>
<option value="4">ffffffff</option>
<option value="5">hhhh</option>
<option value="6">dddd</option>
<option value="7">treee</option>
<option value="8">kiu</option>
</select>
</div>
</div>
<div class="col-md-3 dropdown-button">
<div class="input-group">
<span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span>
<input type="text" id="txtPlaces" placeholder="Enter a location" />
<input type="hidden" id="city2" name="city2" />
<input type="hidden" id="cityLat" name="cityLat" />
<input type="hidden" id="cityLng" name="cityLng" />
</div>
</div>
<div class="col-md-3 dropdown-button">
<div class="section_1">
<select id="cmbvehicletype" name="cmbvehicletype" class="frm-field required">
<option value="null">Type</option>
<option value="cr">dd</option>
<option value="mb">ghjghjd</option>
<option value="tk">ghjghj</option>
<option value="ar">hgjghj</option>
<option value="bi">gggh</option>
<option value="ov">gg</option>
</select>
</div>
</div>
<div class="col-md-3 dropdown-button">
<div class="section_1">
<select id="cmbservice" name="cmbservice" class="frm-field required">
<option value="null">Select</option>
<option value="vr">vr</option>
<option value="oc">oc</option>
<option value="br">br</option>
<option value="vs">vc</option>
<option value="sp">cc</option>
<option value="os">cd</option>
</select>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="col-md-2 submit_button">
<input type="submit" id="searchindex" value="SEARCH"/>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
Controller
public function display_garage_by_location()
{
// Loading Library
$this->load->library('googlemaps');
//Initialize our map. Here you can also pass in additional parameters for customising the map
$this->googlemaps->initialize();
// Create the map. This will return the Javascript to be included in our pages <head></head> section and the HTML code to be
// placed where we want the map to appear.
$data['map'] = $this->googlemaps->create_map();
// Load our view, passing the map data that has just been created
//$this->load->view('my_view', $data);
$data['locationvalue']=$this->input->post('city2');
$data['latvalue']=$this->input->post('cityLat');
$data['longvalue']=$this->input->post('cityLng');
$data['vehicleid']=$this->input->post('cmbvehicletype');
$data['serviceid']=$this->input->post('cmbservice');
$this->garage_location_markers($data);
}
public function garage_location_markers($data)
{
$this->load->view('templates/_header');
$this->load->view('content/locations-in-marker-view',$data);
$this->load->view('templates/footer');
}
2nd View
// In Second View I want to display if location value is null then dispaly no data found else display search results ..
The Problem is When location is not null it displays the details but when i refresh the page again control go back to the controller and results no data found.. How to Solve this?
Try Like this
In View
View user
In Controller
public function FunctionName($id) # determine function that receiving incoming parameter
{
if (empty($id)) {
echo "Token Missed Matched";
}
else{
# get data from model
$result = $this->model_name->model_function($id);
if(empty($result))
{
echo "No data found";
}
else{
$this->load->view('view_name');
}
}
}

How to put glyphicon in bootstrap form?

I have a bootstrap form and want to add a glyphicon before the SELECT fields.
However, it makes a breakline somewhy.
<form role="form" id="registration-form" onsubmit="return onSubmitContinueButton()">
<div class="row">
<div class="form-group col-md-6">
<label class="sr-only" for="xxx"></label>
<span class="glyphicon glyphicon-name"></span> <!-- <-- there is a breakline after this.... why?-->
<select class="form-control" name="aaa">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="sr-only" for="xxx"></label>
<span class="glyphicon glyphicon-name"></span> <!-- <-- there is a breakline after this.... why?-->
<select class="form-control" name="aaa">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
</div>
</form>
I want the glyphicon to be just near the select field and not above it.
How can I fix it?
Thanks
If you want to add icons in front of the select field make it an input group like this
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-plus"></span></span>
<select class="form-control" name="aaa">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
For more information look right here: Bootstrap input groups

Why isn't newly selected option sent to server when form is submitted? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 months ago.
Improve this question
I have a select tag that is built like this:
<%= f.select(:id, category_options, include_blank:true) %>
The form displays fine and the appropriate model item's option tag is selected. However, when the user selects a different option and submits the form, the new option is not passed to the server. Instead, the originally selected value is passed to the server.
The rails log shows the old values being submitted, not the new ones. The values for this input appear to be cached.This happens in development and production, and in development cache_classes = false.
The rails log like this:
Started PUT "/posts/1999" for 127.0.0.1 at 2012-09-11 13:42:51 -0400
Processing by GalleriesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "gallery"=>{"publish_on"=>"2012-09-18", "poster_file_temp"=>"", "thumb_file_temp"=>"", "models_attributes"=>{"0"=>{"id"=>"116", "_destroy"=>"false"}, "1"=>{"id"=>"6409", "_destroy"=>"false"}}, "categories_attributes"=>{"0"=>{"id"=>"59", "_destroy"=>"false"}}, "thumb_zip_input"=>"", "medium_zip_input"=>"", "large_zip_input"=>"", "website_url"=>"", "commit"=>"Upload", "id"=>"1999"}
The form looks like this:
<form accept-charset="UTF-8" action="/galleries/1999" class="edit_gallery" enctype="multipart/form-data" id="edit_gallery_1999" method="post" name="edit_gallery_1999">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put"><input name="authenticity_token" type="hidden" value="...">
</div>
<div class="vert">
<label for="gallery_publish_on">Publish on</label> <input id="gallery_publish_on" name="gallery[publish_on]" size="30" type="text" value="2012-09-18"> <label for="gallery_poster_file">Poster file</label> <input id="gallery_poster_file_temp" name="gallery[poster_file_temp]" type="hidden"><input id="gallery_poster_file" name="gallery[poster_file]" size="30" type="file">
<div class='formSection'>
<img alt="Brandy" src="/content/gallery/poster_file/0000/1999/brandy.jpg">
</div><label for="gallery_thumb_file">Thumb file</label> <input id="gallery_thumb_file_temp" name="gallery[thumb_file_temp]" type="hidden"><input id="gallery_thumb_file" name="gallery[thumb_file]" size="30" type="file">
<div class='formSection'>
<img alt="Thumb" src="/content/gallery/thumb_file/0000/1999/thumb.jpg">
</div>
<div id="models">
<label for="Models">Models</label>
<div>
<select id="gallery_models_attributes_0_id" name="gallery[models_attributes][0][id]">
<option value="6409">
April
</option>
<option value="6366" selected="selected">
Brandy
</option>
<option value="9036">
Charlie
</option>
<option value="7490">
Craig
</option>
<option value="9881">
Donna
</option>
</select> <input id="gallery_models_attributes_0__destroy" name="gallery[models_attributes][0][_destroy]" type="hidden" value="false"> remove
</div><input id="gallery_models_attributes_0_id" name="gallery[models_attributes][0][id]" type="hidden" value="6366"> add model
</div>
<div id="categories">
<label for="Categories">Categories</label>
<div>
<select id="gallery_categories_attributes_0_id" name="gallery[categories_attributes][0][id]">
<option value="1">
Amateur
</option>
<option value="2">
Animals
</option>
<option value="49">
Articles
</option>
<option value="3">
Art
</option>
<option value="7">
Blog
</option>
</select> <input id="gallery_categories_attributes_0__destroy" name="gallery[categories_attributes][0][_destroy]" type="hidden" value="false"> remove
</div><input id="gallery_categories_attributes_0_id" name="gallery[categories_attributes][0][id]" type="hidden" value="59"> add category
</div>
<div id='photoset_files'>
<fieldset>
<legend>Zip Files</legend> <label for="gallery_thumb_zip_input">thumb zip</label> <select id="gallery_thumb_zip_input" name="gallery[thumb_zip_input]">
<option value="/Library/WebServer/Documents/uploads/thumb copy.zip">
thumb copy.zip
</option>
<option value="/Library/WebServer/Documents/uploads/thumb.zip">
thumb.zip
</option>
</select> [ thumb.zip ]<br>
<label for="gallery_medium_zip_input">medium zip</label> <select id="gallery_medium_zip_input" name="gallery[medium_zip_input]">
<option value="/Library/WebServer/Documents/uploads/medium copy 10.zip">
medium copy 10.zip
</option>
<option value="/Library/WebServer/Documents/uploads/medium copy 9.zip">
medium copy 9.zip
</option>
<option value="/Library/WebServer/Documents/uploads/medium copy.zip">
medium copy.zip
</option>
<option value="/Library/WebServer/Documents/uploads/medium.zip">
medium.zip
</option>
</select> [ medium.zip ]<br>
<label for="gallery_large_zip_input">large zip</label> <select id="gallery_large_zip_input" name="gallery[large_zip_input]">
<option value="/Library/WebServer/Documents/uploads/large copy 10.zip">
large copy 10.zip
</option>
<option value="/Library/WebServer/Documents/uploads/large copy 9.zip">
large copy 9.zip
</option>
<option value="/Library/WebServer/Documents/uploads/large copy.zip">
large copy.zip
</option>
<option value="/Library/WebServer/Documents/uploads/large.zip">
large.zip
</option>
</select> [ large.zip ]<br>
</fieldset>
</div><label for="gallery_website_url">Website url</label> <input class="wider" id="gallery_website_url" name="gallery[website_url]" size="30" type="text" value=""> <input id="tluo" name="tluo" type="hidden" value="aHR0cDovL2tmLmRldi9nYWxsZXJpZXMvbGlzdA==">
<div id="submit">
<input data-disable-with="Uploading..." name="commit" type="submit" value="Upload"> Cancel
</div>
</div>
</form>
This is because you are repeating the id and name attribute of select . This is not recommended to have two html elements with same id values
try to change name of select or if you want to use this as array then specifying name this way may help you out
gallery[categories_attributes][0][id][]
This one I used to collect checked radio button values, it may work in your case

Why my form is skipping every other item

I'm doing a project for a class, basically trying to do a survey to match people with a dorm based on their desired lifestyle. I copied the syntax for the form and some of them pop up correctly-the question appears with a drop down menu, but then the questions "how often do you plan on going to red lion" and "how do you plan on eating most of your meals" dont show up, and the options that should be in the drop down menu appear as text on the page, not as a drop down menu. any ideas? Heres the code:
<!DOCTYPE html>
<html>
<head>
<title> Find the right dorm for you </title>
<h1>Find out what dorm fits your lifestyle!</h1>
</head>
<body>
<p> Please fill out a few quesitons so we can help you figure out which dorm is best for you. </p>
<form method="get" action="slutsky1-results.php">
I enjoy (check all that apply):<br>
<input type="checkbox" name="act1" value="8">Working Out<br>
<input type="checkbox" name="act2" value="3">Bowling<br>
<input type="checkbox" name="act3" value="3">Live Music<br>
<input type="checkbox" name="act4" value="5">Shopping<br>
<input type="checkbox" name="act5" value="7">Food<br>
<input type="checkbox" name="act6" value="9">Bars <br>
<input type="checkbox" name="act7" value="9">Frat Parties <br>
<input type="checkbox" name="act8" value="8">Sports <br>
<input type="checkbox" name="act9" value="3">Library <br>
Is being close to the quad important to you?:
<select name= "Quad">
<option value="1">Not important</option>
<option value="3">Kind of important</option>
<option value="6">Very Important</option>
<option value="3">Only thing that matters</option> <br>
How often do you plan on going to Red Lion?:
<select name= "Lion">
<option value="1">Never</option>
<option value="5">Sometimes</option>
<option value="10">Over 3 times a week</option> <br>
Would you rather go to the ARC or CRCE?:
<select name= "Gym">
<option value="10">Arc</option>
<option value="1">CRCE</option>
<br>
How do you plan on eating most of your meals?:
<select name= "Gym">
<option value="5">Ordering delivery</option>
<option value="8">Walking To Green St.</option>
<option value="5">Making my own food</option>
<br>
Private or Public dorm?:
<select name= "Gym">
<option value="10">Private</option>
<option value="5">Public</option>
<br>
<input type="submit" value="get my results!">
</form>
</body>
</html>
You need to close your select tags (using </select>) after the option lists:
<select name= "Gym">
<option value="10">Arc</option>
<option value="1">CRCE</option>
</select>
Do that to every list.
You aren't closing your select tags. So the browser is trying to guess what you are trying to accomplish. Remember that all tags should be closed.
<select name= "Quad">
<option value="1">Not important</option>
<option value="3">Kind of important</option>
<option value="6">Very Important</option>
<option value="3">Only thing that matters</option>
</select>
For help finding these sorts of issues, run your page against an html validator.