I cannot update by inserting details from a popup form - codeigniter

When I click the insert link in the second row it passes the ID of the first. Only the first row is updated.
My controller: money_c:
function addrow()
{
$this->load->view('header');
$this->load->view('manualupdate',$result);
$this->load->view('footer');
}
My view page: manualupdate.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Popup contact form using only CSS - Demo | CodingCrazy</title>
<link href="<?php echo base_url();?>assets/css/styleform.css" rel="stylesheet" type="text/css"/>
<link href='http://fonts.googleapis.com/css?family=Electrolize' rel='stylesheet' type='text/css' />
<!--CC-->
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/fonts.css"/>
</head>
<!--<link rel="stylesheet" href="<?php // echo base_url();?>assets/css/special.css" type="text/css" />-->
<div class="bal" style="margin-left: 627px;
padding: 15px;">
<table border="1">
<tr>
<th>Date</th>
<th>Description</th>
<th>Category</th>
<th>Debit</th>
<th>Credit</th>
<th>Bal.AMT</th>
<th>Insert</th>
<th> EDit/Delete</th></tr>
<?php foreach($query2 as $row)
{
$date=$row->date;
$desc=$row->description;
$credit=$row->credit;
$deb=$row->debit;
$bal=$row->bal;
$cat=$row->category;
$id=$row->id;
?>
<tr><td><?php echo $date;?></td>
<td><?php echo $desc;?></td>
<td><?php echo $credit;?></td>
<td><?php echo $deb;?></td>
<td><?php echo $bal;?></td>
<td><?php echo $cat;?></td>
<td><a href="#pop" >Insert<div id="pop" class="box">////here pop up will come////pop up starts
</tr>
<?php
}
?></table>
</tbody>
</table>
Popup:
<div class="smart-green">
<?php
echo
form_open('money_c/manualupdatesave/'.$id)?>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>//////pop up ends///////////
<!--</form>-->
<div id="close">
model: money_m:
function transaction($a,$b,$c,$d,$e,$id)
{
$this->db->where('id',$id);
$this->db->set('date',$a);
$this->db->set('description',$b);
$this->db->set('debit',$d);
$this->db->set('credit',$e);
// $data=array('date'=>$a,'description'=>$b,'debit'=>$d,'credit'=>$e);
$this->db->update('manualupdate');
}
In form_open('money_c/manualupdatesave/'.$id) I get only the first row ID, not the ID of the second row.

<a href="#pop" >Insert<div id="pop" class="box">
change this line to
<a href="#pop-<?php echo $id;?>" >Insert<div id="pop" class="box">
You you popup code is still not complete (assuming it should look like this)
<div id="#pop-<?php echo $id;?>">
<?php
echo
form_open('money_c/manualupdatesave/'.$id)?>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>//////pop up ends///////////
<!--</form>-->
<div id="close">

Related

Preserve values in modified object Thymeleaf

I'm creating an Object in GET method and initialize it with nulls. Then I set some values and send it to the POST method, but after this process all of values that I set earlier are nulls. How could I repair it? I've tried to use hidden fields, but it didn't help.
HTML code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet" th:href="#{/styles.css}" />
</head>
<body>
<form method="POST" th:action="#{sendorder}" th:object="${details}">
<label for="name">Name: </label>
<input type="text" th:field="*{name}"/>
<br/>
<input type="hidden" th:field="*{order}" id="order"><label for="surname">Surname: </label>
<input type="text" th:field="*{surname}"/>
<br/><label for="room">Room: </label>
<input type="text" th:field="*{room}"/>
<br/>
<br/>
<h2>Please, choose your company:</h2>
<select th:field="*{company}">
<option th:each="i : ${companies}" th:value="${i.id}" th:text="${i.name}">
</option>
</select>
</div>
</div>
<input type="submit" value="Submit Order"/>
</form>
</body>
</html>

Having problem with this form and the select option and also the email is not send

I want this form to send email but i don't work, i don'y know where is the problem but i think the problem is in the model, also this form has a select function i cannot make it work when i choose something in the select option to send it with email
This is the controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Offer extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('admin_model');
$this->load->helper(array('form', 'url', 'text'));
}
public function index() {
$this->load->view('header.php');
$this->load->view('offer.php');
$this->load->view('footer.php');
}
public function sendOffer(){
if(isset($_POST['companyname']) && isset($_POST['sendername']) && isset($_POST['email']) && isset($_POST['number']) && isset($_POST['interest']) && isset($_POST['message'])){
$data['companyname'] = $_POST['companyname'];
$data['sendername'] = $_POST['sendername'];
$data['email'] = $_POST['email'];
$data['number'] = $_POST['number'];
$data['interest'] = $_POST['interest'];
$data['message'] = $_POST['message'];
$data['created_at'] = date("Y-m-d H:i:s");
$this->admin_model->sendOfferEmail($data);
$this->db->insert('offer',$data);
$true = "Message Sent Successfully ...";
$this->session->set_flashdata('true', $true);
redirect(base_url()."offer");
}else{
$error = "Failed To Send, Please check all inputs and try again !!!";
$this->session->set_flashdata('error', $error);
redirect(base_url()."offer");
}
}
}
This is the model
public function sendOfferEmail($data){
$MailTo = "menna.ashour#thetranslationgate.com";
$subject = "The Translation Gate Website offer".$data['created_at'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
//$headers .= "Cc: amr.hussein#europelocalize.com". "\r\n";
$headers .= 'From: The Translation Gate Website'."\r\n";
$message = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Falaq| Site Manager</title>
<style>
body {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 1.428571429;
color: #333;
}
section#unseen
{
overflow: scroll;
width: 100%
}
</style>
<!--Core js-->
</head>
<body>
<div class="panel-body">
<div class="adv-table editable-table ">
<div class="clearfix">
<div class="btn-group">
<span class=" btn-primary" style="">
</span>
</div>
</div>
<div class="space15"></div>
<table class="table table-striped table-hover table-bordered" id="" style="overflow:scroll;border: 1px solid;width: 100%;text-align: center">
<tbody>
<tr>
<td style="background-color: #ddd;">Company Name</td>
<td style="background-color: #f9f9f9;">'.$data['companyname'].'</td>
</tr>
<tr>
<td style="background-color: #ddd;">Full Name</td>
<td style="background-color: #f9f9f9;">'.$data['sendername'].'</td>
</tr>
<tr>
<td style="background-color: #ddd;">Email</td>
<td style="background-color: #f9f9f9;">'.$data['email'].'</td>
</tr>
<tr>
<td style="background-color: #ddd;">Phone Number</td>
<td style="background-color: #f9f9f9;">'.$data['number'].'</td>
</tr>
<tr>
<td style="background-color: #ddd;">Message</td>
<td style="background-color: #f9f9f9;">'.$data['message'].'</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>';
mail($MailTo,$subject,$message,$headers);
}
public function getInterest($interest){
$result = $this->get_where('interest',array('id' => $interest))->row();
if(isset($result->name)){
return $result->name;
}else{
return '';
}
}
}
?>
This is the view
<section id="pageBar">
<div class="container">
<div class="row">
<h1 class="page-title pull-left">Offers</h1>
<ol class="breadcrumb pull-right">
<li>Home</li>
<li>Offers</li>
</ol>
</div>
</div>
</section>
<!-- Page-Bar -->
<!-- Login Form -->
<div id="login">
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2 col-xs-offset-0">
<form class="login-form" method="post" action="<?=base_url()?>offer/sendOffer" enctype="multipart/form-data">
<div class="form-group input-block">
<label for="name">Company Name</label>
<input type="text" name="companyname" class="form-control" id="companyname" required>
</div>
<div class="form-group input-block">
<label for="name">Full Name</label>
<input type="text" name="sendername" class="form-control" id="sendername" required>
</div>
<div class="form-group input-block">
<label for="email" style="top: 24px; font-size: 16px;">Email</label>
<input type="email" name="email" class="form-control" id="email" required="" autocomplete="off">
</div>
<div class="form-group input-block">
<label for="name" style="top: 24px; font-size: 16px;">Phone Number</label>
<input type="text" name="number" class="form-control" id="number" required="" autocomplete="off">
</div>
<div class="select-group">
<select class="form-control selectpicker" >
<option disabled="disabled" selected="" value="">Interest</option>
<option value="1">Arabic</option>
<option value="2">DTP</option>
<option value="3">Both</option>
</select>
</div>
<div class="">
<textarea name="message" id="message" class="form-control" rows="6" placeholder="Message" required="" autocomplete="off"></textarea>
</div>
<div class="text-center">
<button type="submit" class="btn btn-gray">
Submit
</button>
</div>
</form> </div>
</div>
</div>
</div>
You have disabled to blank value the select box.So you are not able select.
Remove disabled="disabled" from select box.
For mail service turn on development mode and check the error you got.

How to fill List<string> field in Thymeleaf + Spring

here is my form
<!--destinationList List-->
<div class="form-group">
<div class="col-sm-3">
<label for="Destination">Destination</label>
</div>
<div class="col-sm-9">
<input type="text" class="form-control" th:field="*{destinationList[0]}" />
<input type="text" class="form-control" th:field="*{destinationList[1]}" />
<input type="text" class="form-control" th:field="*{destinationList[2]}" />
<input type="text" class="form-control" th:field="*{destinationList[3]}" />
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<button type="submit" class="btn btn-primary btn-block">Calculate</button>
</div>
</div>
</form>
And I'm going to fill following model
public class PriceSearchDTO {
private List<String> destinationList;
public List<String> getDestinationList() {
return destinationList;
}
public void setDestinationList(List<String> destinationList) {
this.destinationList = destinationList;
}
}
I can do this. But I hard coded number of input fields in the list as above in the view. I need to genarate them dynamically and make the number of element in the list is airbitary.
Try this:
<div class="col-sm-9">
<input type="text" class="form-control" th:each="destination : ${destinationList}" th:field="*{destination}" />
</div>
You are using Iteration in Thymeleaf. In fact, there is a quite complete set of objects that are considered iterable by a th:each attribute.
Like this :
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="all"
href="../../../css/gtvg.css" th:href="#{/css/gtvg.css}" />
</head>
<body>
<h1>Product list</h1>
<table>
<tr>
<th>NAME</th>
<th>PRICE</th>
<th>IN STOCK</th>
</tr>
<tr th:each="destination: ${destinations}">
<td th:text="${destination}">Onions</td>
</tr>
</table>
<p>
Return to home
</p>
</body>
</html>
And Controller in Spring framework.
#RequestMapping(value = "/")
public ModelAndView showView(ModelAndView mav) {
List<String> destinations = new ArrayList<String>();
destinations.add("elementA");
destinations.add("elementB");
destinations.add("elementC");
mav.addObject("destinations", destinations);
mav.setViewName("/viewName");
return mav;
}

echo form_open('user_authentication/new_user_registration'); rendered wrong url

I have problem about the form_open or any url in my site, maybe this is the new update of codeigniter or what. when I use its rendered a confusing syntax like http://::1/ and my form not working correctly or take me to a blank page. also my css dont work.
here is my php code.
<html>
<?php
if (isset($this->session->userdata['logged_in'])) {
header("location: http://localhost/login/index.php/user_authentication/user_login_process");
}
?>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
if (isset($logout_message)) {
echo "<div class='message'>";
echo $logout_message;
echo "</div>";
}
?>
<?php
if (isset($message_display)) {
echo "<div class='message'>";
echo $message_display;
echo "</div>";
}
?>
<div id="main">
<div id="login">
<h2>Login Form</h2>
<hr/>
<?php echo form_open('user_authentication/user_login_process'); ?>
<?php
echo "<div class='error_msg'>";
if (isset($error_message)) {
echo $error_message;
}
echo validation_errors();
echo "</div>";
?>
<label>UserName :</label>
<input type="text" name="username" id="name" placeholder="username"/><br /><br />
<label>Password :</label>
<input type="password" name="password" id="password" placeholder="**********"/><br/><br />
<input type="submit" value=" Login " name="submit"/><br />
To SignUp Click Here
<?php echo form_close(); ?>
</div>
</div>
</body>
</html>
then here is the view page source. im using google chrome browser
<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="http://::1/login/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="main">
<div id="login">
<h2>Login Form</h2>
<hr/>
<form action="http://::1/login/index.php/user_authentication/user_login_process" method="post" accept-charset="utf-8">
<div class='error_msg'></div> <label>UserName :</label>
<input type="text" name="username" id="name" placeholder="username"/><br /><br />
<label>Password :</label>
<input type="password" name="password" id="password" placeholder="**********"/><br/><br />
<input type="submit" value=" Login " name="submit"/><br />
To SignUp Click Here
</form> </div>
</div>
</body>
</html>
as you can see the url of css and form are rendered a wrong url. href="http://::1/login/css/style.css"> instead of href="css/style.css">. also the form_open(). whats wrong with this?
Its because of your base_url is empty
How to set base_url()??
In config/config.php set $config['base_url'] = ''; the project URL.
Keeping base_url() empty any harm??
When you in local its ok and fine. But when you host that just add your site URL to it.
$config['base_url'] = 'www.stackoverflow.com';
Take look at this answer
and Possible duplicate of This Question

Only the first row of a table updates after new details are inserted in a popup form

In each row of a table, I have an “insert” link. When a user clicks this link, a popup window appears containing a form. When the user clicks the “save” button for the form, the form update works only for the first row of the parent table. It takes only the first row ID.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Popup contact form using only CSS - Demo | CodingCrazy</title>
<link href="<?php echo base_url();?>assets/css/styleform.css" rel="stylesheet" type="text/css"/>
<link href='http://fonts.googleapis.com/css?family=Electrolize' rel='stylesheet' type='text/css' />
<!--CC-->
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/fonts.css"/>
</head>
</body>
</html>
<!--<link rel="stylesheet" href="<?php // echo base_url();?>assets/css/special.css" type="text/css" />-->
<div class="bal" style="margin-left: 627px;
padding: 15px;">
Balance Amount:<input type="text" name="bal">
<?php echo form_open('money_c/addrow')?>
<input type="submit" style="padding:7px;" name="sub" value="add row">
<?php echo form_close();?></div>
<table border="1">
<tr>
<th>Date</th>
<th>Description</th>
<th>Category</th>
<th>Debit</th>
<th>Credit</th>
<th>Bal.AMT</th>
<th>Insert</th>
<th> EDit/Delete</th></tr>
<?php foreach($query2 as $row)
{
$date=$row->date;
$desc=$row->description;
$credit=$row->credit;
$deb=$row->debit;
$bal=$row->bal;
$cat=$row->category;
$id=$row->id;
?>
<tr><td><?php echo $date;?></td>
<td><?php echo $desc;?></td>
<td><?php echo $credit;?></td>
<td><?php echo $deb;?></td>
<td><?php echo $bal;?></td>
<td><?php echo $cat;?></td>
<td><a href="#pop" >Insert<div id="pop" class="box">
<?php
?>
<!--<form action="" method="post" class="smart-green">-->
<div class="smart-green">
<?php
echo form_open('money_c/manualupdatesave/'.$id)?>///here updation happens only for first row id;
<h1>
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Category:</span><select name="selection">
<?php foreach($query1 as $row1)
{
$cat=$row1->category;
?>
<!--<option value="Job Inquiry">Job Inquiry</option>-->
<option value="<?php echo $cat;?>"><?php echo$cat;?></option>
<?php
}
?>
</select>
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>
<!--</form>-->
<div id="close">
<td><img src="<?php echo base_url();?>assets/images/del.jpg" width="60" height="40"></td>
</tr>
<?php
}
?></table>
</tbody>
</table>
My controller:
money_c
function manualupdatesave($id)
{
$a=$this->input->post('dat');
$b=$this->input->post('desc');
$c=$this->input->post('cat');
$d=$this->input->post('deb');
$e=$this->input->post('credit');
$this->money_m->transaction($a,$b,$c,$d,$e,$id);
$this->load->view('header');
$result['query2'] = $this->money_m->selecttrans();
$this->load->view('manualupdate',$result);
$this->load->view('footer');
}
view page: manualupdate.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Popup contact form using only CSS - Demo | CodingCrazy</title>
<link href="<?php echo base_url();?>assets/css/styleform.css" rel="stylesheet" type="text/css"/>
<link href='http://fonts.googleapis.com/css?family=Electrolize' rel='stylesheet' type='text/css' />
<!--CC-->
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/fonts.css"/>
</head>
<!--<link rel="stylesheet" href="<?php // echo base_url();?>assets/css/special.css" type="text/css" />-->
<div class="bal" style="margin-left: 627px;
padding: 15px;">
Balance Amount:<input type="text" name="bal">
<?php echo form_open('money_c/addrow')?>
<input type="submit" style="padding:7px;" name="sub" value="add row">
<?php echo form_close();?></div>
<table border="1">
<tr>
<th>Date</th>
<th>Description</th>
<th>Category</th>
<th>Debit</th>
<th>Credit</th>
<th>Bal.AMT</th>
<th>Insert</th>
<th> EDit/Delete</th></tr>
<?php foreach($query2 as $row)
{
$date=$row->date;
$desc=$row->description;
$credit=$row->credit;
$deb=$row->debit;
$bal=$row->bal;
$cat=$row->category;
$id=$row->id;
?>
<tr><td><?php echo $date;?></td>
<td><?php echo $desc;?></td>
<td><?php echo $credit;?></td>
<td><?php echo $deb;?></td>
<td><?php echo $bal;?></td>
<td><?php echo $cat;?></td>
<td><a href="#pop" >Insert<div id="pop" class="box">
<?php
?>
<!--<form action="" method="post" class="smart-green">-->
<div class="smart-green">
<?php
echo form_open('money_c/manualupdatesave/'.$id)?>
<h1>
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Category:</span><select name="selection">
<?php foreach($query1 as $row1)
{
$cat=$row1->category;
?>
<!--<option value="Job Inquiry">Job Inquiry</option>-->
<option value="<?php echo $cat;?>"><?php echo$cat;?></option>
<?php
}
?>
</select>
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>
<!--</form>-->
<div id="close">
<td><img src="<?php echo base_url();?>assets/images/del.jpg" width="60" height="40"></td>
</tr>
<?php
}
?></table>
</tbody>
</table>
My popup form:
<?php
echo form_open('money_c/manualupdatesave/'.$id)?>
<h1>
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Category:</span><select name="selection">
<?php foreach($query1 as $row1)
{
$cat=$row1->category;
?>
<!--<option value="Job Inquiry">Job Inquiry</option>-->
<option value="<?php echo $cat;?>"><?php echo$cat;?></option>
<?php
}
?>
</select>
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>

Resources