I have a project with multiple language when I try to share it on facebook I got this error.
File: path/Language.php: 15 function:_error_handler.
function switch_lang($language = "") {
$language = ($language != "") ? $language : "english";
$this->session->set_userdata('site_lang', $language);
setcookie('site_lang', $language, time() + (86400 * 30), "/");
redirect($_SERVER['HTTP_REFERER']);//This is Line 15
//When I remove the redirect above it work.
}
And this is how the switch_language function get call.
<select class="form-control" onchange="javascript:window.location.href='<?php echo base_url(); ?>language/switch_lang/'+this.value;">
<option value="korean" <?php if($this->session->userdata('site_lang') == 'korean') echo 'selected="selected"'; ?> > 한국어 </option>
<option value="chinese" <?php if($this->session->userdata('site_lang') == 'chinese') echo 'selected="selected"'; ?> > 中文 </option>
</select>
I sovel the problem by using javascript history.back function instead of php redirect
echo '<script> window.history.back();</script>';
Related
But when i select drop down value and any error related firstname etc. and on update button it remove selected value and show old value.
<td align=left>Select Month:<select name=month id="month">
<?php
$date = $row->birth;
$stamp = strtotime($date);
?>
<?php
echo '<option .date("m", $stamp). '.$selected.'>'.date("m", $stamp).'</option>';
?>
<option name=""></option>
<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='12'>December</option>
</select>
<?php echo form_error('month','<div style="color:red">', '</div>'); ?>
<span class="error"></span>
</td>
You can use codeigniter's set_select function to keep the selection if form validation fails:
Select Month:<select name=month id="month">
<option name=""></option>
<option value='01' <?php echo set_select('month', '01'); ?>>January</option>
<option value='02' <?php echo set_select('month', '02'); ?>>February</option>
<option value='03' <?php echo set_select('month', '03'); ?>>March</option>
<option value='12' <?php echo set_select('month', '12'); ?>>December</option>
</select>
See also: https://www.codeigniter.com/userguide3/helpers/form_helper.html#set_select
If you have a value you'd like to set in the dropdown when the page first loads, you can use the third argument:
Select Month:<select name=month id="month">
<?php
$date = $row->birth;
$stamp = strtotime($date);
$month = date("m", $stamp);
?>
<option name=""></option>
<option value='01' <?php echo set_select('month', '01', $month == '01'); ?>>January</option>
<option value='02' <?php echo set_select('month', '02', $month == '02'); ?>>February</option>
<option value='03' <?php echo set_select('month', '03', $month == '03'); ?>>March</option>
<option value='12' <?php echo set_select('month', '12', $month == '12'); ?>>December</option>
</select>
What I'm I doing wrong?
application/views/pegawai_read.php
<select name="" id="" class="form-control">
<?php
foreach($nm_berkas_jn->result() as $j){
?>
<option value="<?php echo $j->id_berkas_jn;?>"><?php echo $j->nm_berkas_jn;?></option>
<?php } ?>
</select>
application/controllers/pegawai.php
public function read($id) {
$id_berkas_jn=$this->session->userdata('id_berkas_jn');
$text = "SELECT * FROM kpg_berkas_jn";
$d['nm_berkas_jn'] = $this->app_model->manualQuery($text);
$d['level']=$this->session->userdata('level');
}
application/models/app_model.php
function manualQuery($q) {
return $this->db->query($q);
}
Add the following line to the bottom of your controller. This send the data to the view
$this->load->view('pegawai_read', $d);
I have page called no.tpl, in this page am displaying customer name in select dropdown
this is the code:
no.tpl
<select name="customer_id" id="customer" style="width: 325px;margin-bottom:10px" class="form-control">
<?php foreach($customerData as $customer){ ?>
<option value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option>
<?php }?>
</select>
In controller page i have to filter selected customer list
$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='6'");
$selectedCustomer = $queryCustomer->row;
$selectedCustomerId = $selectedCustomer['customer_id'];
$selectedCustomerName = $selectedCustomer['name'];
$selectedCustomerEmail = $selectedCustomer['email'];
I want customer_id='6' as selected customer_id. I mean pass the select value to controller page
Try this code in view page
<select name="customer_id" id="input-sales-person" style="width: 325px;margin-bottom:10px" class="form-control">
<?php foreach($customerData as $customer){ ?>
<option id="temp" value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option>
<?php }?>
</select>
<input type="submit" id="noOrder" Onclick="return ConfirmDelete();" value="Submit" class="btn btn-primary">
Use this following script
<script type="text/javascript">
$('#noOrder').on('click', function() {
var temp1=$( "#input-sales-person option:selected" ).val();
var temp2=$( "#input-sales-person option:selected" ).text();
document.cookie = "selectedCustomerId=" +temp1;
document.cookie = "selectedCustomerName=" +temp2;
location="index.php?route=sale/no";
});
</script>
In controller pass the customer_id as $selectedCustomerId=$_COOKIE['selectedCustomerId'];
$selectedCustomerId=$_COOKIE['selectedCustomerId']; /*customer_id=6*/
$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='".$selectedCustomerId."'");
I couldn't find a solution on here, thought I wasn't sure what to search for. I have a select box that is populated from my database using PDO. However I was unsure on how to set the selected value to a team that has already been set from the DB.
Update The code only shows the team that matches the variable, however I need to show all teams in the drop down.
<option <?php if($row4['team_id'] == $team_id) { ?>
selected="selected" > <?php }
echo $row4['team_name'];?>
</option>
<?php } ?>
OLD code
$stmt4 = $conn ->prepare('SELECT team_id, team_name FROM team_tbl ORDER BY team_name');
$stmt4->execute();
while($row4 = $stmt4->fetch(PDO::FETCH_ASSOC)) {
echo '<option <? if ($row4['team_id'] == $team_id){?> selected="selected"<? } ?>>'.$row4['team_name'].'</option>';
}
?>
<option <?php if($row4['team_id'] == $team_id) { ?> selected="selected" <?php } ?>></option>
Add the above code to the option field.
I am using a captcha in a form. When the user submits an invalid answer to the captcha, the page reloads repopulating the fields with the user data. My question is, is there a better (or easier) way to check which dropdown value was selected.
This is what I have now that works:
php
<?php
$state = $sf_params->get('state');
?>
html
<span>State </span>
<select size="1" name="state">
<option value="" selected="selected"></option>
<option value="AL" <?php if ($state == "AL") { echo "selected = 'selected'"; } ?>>Alabama</option>
<option value="AK" <?php if ($state == "AK") { echo "selected = 'selected'"; } ?>>Alaska</option>
<option value="AZ" <?php if ($state == "AZ") { echo "selected = 'selected'"; } ?>>Arizona</option>
<option value="AR" <?php if ($state == "AR") { echo "selected = 'selected'"; } ?>>Arkansas</option>
Is there another solution to getting the GET variable, then parsing the options, looking for the matched value?
Well, it's not really a good practice to build a form on your own. Usually you should use widget from sfForm class, etc ..
But, if you really want to build this kind of stuff, you should bring back a good helper from sf1.0 that helps you building form tag. In your case, the function options_for_select and select_tag might be useful:
options_for_select:
Returns a formatted set of <option> tags based on optional $options array variable.
select_tag:
Returns a <select> tag, optionally comprised of <option> tags.
options_for_select took as second parameter, the selected value you want.
So just, create a file called lib/helper/FormHelper.php and put these two functions inside. Don't forget to load the helper in your view :
<?php use_helper('Form') ?>
And use options_for_select & select_tag to build your select.
First move the values of the select to an array in the Controller like
$states = array('AL' => 'Alabama', ... );
Then you can use the Helper j0k mentioned or go by feet:
By assigning the vars in the controller.
$this->states = $states;
In the Template:
<?php foreach ($states as $key => $value): ?>
<option value="<?php echo $key ?>" <?php if ($state == $value) { echo "selected = 'selected'"; } ?>><?php echo $value ?></option>
<?php endforeach; ?>
But I also recommend to use the Helper.