codeigniter form not submitting fields - php

I'm a newbie for codeigniter. I'm stuck at a problem, that my form is not posting values, I dont know why.
Current site works fine on local server and my testing server. As I transferred complete site on clients server, this problem occurred.
I have checked, htaccess is enabled. I'm also pasting my view, and controller.
Please help me
VIEW
<form name="form1" method="post" action="index.php/search/make_url">
<div class="search_form">
<label for="shop"></label>
<select name="category" id="select">
<option value="0">-- Shops / Webshops --</option>
<?php
$cats=load_categories();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->cat_name_en."---".$cat->catId;?>"><?php echo $cat->cat_name_en;?></option>
<?php }?>
</select>
<select name="product">
<option value="0">-- <?php echo $this->lang->line("text_select_prod");?> --</option>
<?php
$cats=load_products();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->p_name_en;?>---<?php echo $cat->pId;?>"><?php echo $cat->p_name_en;?></option>
<?php }?>
</select>
<label for="select2"></label>
<select name="brand" id="brand">
<option value="0">-- <?php echo $this->lang->line("text_select_chose_brand");?> --</option>
<?php
$cats=load_brands();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->brand_name_en;?>---<?php echo $cat->brandId;?>"><?php echo $cat->brand_name_en;?></option>
<?php }?>
</select>
<label for="select3"></label>
<select name="country" id="country" onchange="getCity(this.value);">
<option value="0">-- <?php echo $this->lang->line("text_select_country");?> ---</option>
<?php
$cats=load_country();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->cn_name;?>---<?php echo $cat->cnId;?>"><?php echo $cat->cn_name;?></option>
<?php }?>
</select>
<label for="select4"></label>
<div id="cityBlock">
<select name="city" id="city">
<option value="0">-- <?php echo $this->lang->line("text_select_city");?> --</option>
</select>
</div>
<input type="submit" name="btn" value="<?php echo $this->lang->line("text_btn_submit");?>">
</div>
</form>
CONTROLLER
public function make_url()
{
$url=$this->uri->assoc_to_uri($_POST);
redirect(base_url()."index.php/search/for/". $url);
}
Thanks in advance

Check out this way:
<?=form_open('immovable/personal/add_personal');?>
<input type='text' id='fname' name='fname' required />
<input type='text' id='lname' name='lname' required />
<input type='submit' value='Submit' />
<?=form_close()?>

I solved this problem later. Problem was base tag used in Head tag. I simply removed it, and website was functional.

$config[suffix] is the solution for the above problem
Refer this link for better explanation

Related

sql queries on ajax php page

i am trying to get content inside a div using ajax, on the php page that am accessing using ajax, i want to fill dropdown options using another query but it just closes the select tag before the options.
<select class="form-control data" data-t="integer" name='role' required/>
<option value="">--Select--</option>
<?php
foreach($con -> query("select id,name,permissions from role") as $role){
?>
<option value="<?php echo $role['id']; ?>"><?php echo $role['name']; ?></option>
<?php
}
?>
</select>
But here is what i get inside the div
<select class="form-control data" data-t="integer" name="role"
required=""></select>
<option value='1' >option1</option>
<option value='2' >option2</option>
<option value='3' >option3</option>
please remove forward / at the end of opening select tag as below:
<select class="form-control data" data-t="integer" name='role' required>
<option value="">--Select--</option>
<?php
foreach($con -> query("select id,name,permissions from role") as $role){
?>
<option value="<?php echo $role['id']; ?>"><?php echo $role['name']; ?></option>
<?php
}
?>
</select>

Dependent dropdown getting ids not name

I am trying to get user selection from php form but instead of name I am getting id of elements. instead of ids I want to get names. Please help
here is the url
http://efinancec.com/d/drop4/index.php
and here is the code
<form action="../form/form1.php" method="post" enctype="multipart/form-data">
<div class="frmDronpDown">
<div class="row">
<label>Training:</label><br/>
<select name="training" id="training-list" class="demoInputBox" onChange="getCourse(this.value);">
<option value="">Select Training</option>
<?php
foreach($results as $training) {
?>
<option value="<?php echo $training["id"]; ?>"><?php echo $training["training"]; ?></option>
<?php
}
?>
</select>
</div>
<div class="row">
<label>Course:</label><br/>
<select name="course" id="course-list" class="demoInputBox" onChange="getCountry(this.value);">
<option value="">Select Course</option>
</select>
</div>
<div class="row">
<label>Country:</label><br/>
<select name="country" id="country-list" class="demoInputBox" onChange="getCity(this.value);">
<option value="">Select Country</option>
</select>
</div>
<div class="row">
<label>City:</label><br/>
<select name="city" id="city-list" class="demoInputBox" onChange="getDates(this.value);">
<option value="">Select City</option>
</select>
</div>
<div class="row">
<label>Dates:</label><br/>
<select name="dates" id="dates-list" class="demoInputBox" onChange="getPrice(this.value);">
<option value="">Select Dates</option>
</select>
</div>
<div class="row">
<label>Online Onsite Price:</label><br/>
<select name="price" id="price-list" class="demoInputBox">
<option value="">Select Online or Onsite</option>
</select>
</div>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
and this is how I am getting the values from sql database
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_POST["training_id"])) {
$query ="SELECT * FROM course WHERE training_id = '" . $_POST["training_id"] . "'";
$results = $db_handle->runQuery($query);
?>
<option value="">Select Course</option>
<?php
foreach($results as $course) {
?>
<option value="<?php echo $course["id"]; ?>"><?php echo $course["course"]; ?></option>
<?php
}
}
?>
Change this line:
onChange="getCourse(this.value);">
To this :
onChange="getCourse(this.text);">
You are passing id of the course as the value of dropdown and calling that value which is fine but you need to call the text of select option to get the course name.
I changed this.value to this.text as suggested and created the new page and it stoped working at all now it is not pulling the records from database except the first one. Here is the link
http://efinancec.com/d/drop4/index1.php
where as my earlier page is still working fine.
http://efinancec.com/d/drop4/index.php
I think I could not convey my problem earlier. My depended dropdown is working fine but when a user submits the form in the email I receive the ids instead of name. Thats the problem.
For example I myself made some selections on index.php and submitted form Here is the email I got
training: 1
course : 101
country: 1001
city: 5005
Basically I am getting the the respective ids instead of name.

Convert a JS array into JSON n display it

I am new in programming i just want that the value i choose in drop downs must retain selected when i click the search button ...
here is the code
<select name="campaigntype" id="campaigntype" class="text dropDownNewsletter" onchange="GetCampaigns()" style="float:left; margin-right:15px;">
<option value="">Select Campaign</option>
<option value="1" >OB Campaign</option>
<option value="2">Casbo Campaign</option>
</select>
<div id="selected_campaigns" style="float:left">
<select name="campaignid" id="campaignid" class="text dropDownNewsletter">
<option value="">Select Campaign</option>
<?php foreach($campaigns as $key=>$row){?>
<option value="<?php echo $row['id'];?>" <?php if( $row['id'] == $campaign_id) {?> selected="selected" <?php } ?> ><?php echo $row['id'].'-'.$row['title'];?></option>
<?php }?>
</select>

How to retain Select option after submitting the form in php

I looked at several community forums, and I am unable to figure it out on how to retain select option value after validation fails.
Here is the code that works for me, but values disappear when submit button is submitted.
<select id="service" name="service" class="searchoption">
<option value="">-- Select Service Name --</option>
<?php
$resultservice = mysqli_query($con,"Select * from services") ?>
<?php
while ($line = mysqli_fetch_array($resultservice)) {
?>
<option value="<?php echo $line['serviceid'];?>"> <?php echo $line['service'];?> </option>
<?php
}
?>
</select>
Here is what I tried and doesn't work for me:
<select id="service" name="service" class="searchoption">
<option value="">-- Select Service Name --</option>
<?php
$resultservice = mysqli_query($con,"Select * from services") ?>
<?php
while ($line = mysqli_fetch_array($resultservice)) {
?>
<option value="<?php echo $line['serviceid']; if ($_POST['service'] == $service) {echo 'selected="selected"'} echo $line['serviceid']; ?>"> <?php echo $line['service'];?> </option>
<?php
}
?>
</select>
<form action="" method="POST">
<select name="list" id="list">
<option value="item1">item1</option>
<option value="item2">item2</option>
<option value="item3">item3</option>
</select>
<input type="submit" />
</form>
<script type="text/javascript">
document.getElementById('list').value = "<?php echo $_POST['list']?>";
</script>
May be a small error but noticed a invalid > in the following code
<option value="<?php echo $line['serviceid']; if ($_POST['service'] == $service) {echo 'selected="selected"'} echo $line['serviceid']; ?>"> <?php echo $line['service'];?> </option>
Try this
<option value="<?php echo $line['serviceid']; if ($_POST['service'] == $service) {echo 'selected="selected"'}?> echo $line['serviceid']; <?php echo $line['service'];?>" </option>
hope this helps

simplest php dropdown box

I have a simple dropdow box, I want to get the value of the selected item with php. If anyone can help me with it please.
<form id="s" method="post">
<select name="size">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select>
<input type="submit" name="Submit" value="Send">
</form>
<?php
---
echo "selected size".$selected;
?>
Provided you put everything in one file:
<form id="s" method="post">
<select name="size">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select>
<input type="submit" name="Submit" value="Send">
</form>
<?php
if(isset($_POST['size'])) {
echo "selected size: ".htmlspecialchars($_POST['size']);
}
?>
<select name="rider_select">
<option value="">Select Rider</option>
<?php
foreach ($riderlist as $rows) {
$rname = $rows['name'];
$rnum = $rows['number'];
$rider_full = $rname.'-'.$rnum;
?>
<option value="<?php echo $rname.'-'.$rnum; ?>"
<?= (($rider_fromdb == $rider_full) ? 'selected="selected"' : ''); ?>>
<?php echo $rname.'-'.$rnum; ?></option>
<?php } ?>
</select>

Categories