Display Update button & save values in database - save

We are displaying table grid as below image, in last column you can see commission as 10 & 0.
i need to provide an Update button below that and provide an option to edit 10 & 0 , so if we click on "update" button, it should save in database.
we are using below code to display table grid.
php
function getDesignerCollection()
{
$user_home = new USER();
$stmt = $user_home->runQuery("SELECT * FROM tbl_users");
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->execute();
$i=0;
while($data = $stmt->fetch())
{
$responce[$i]=array($data['userID'],
ucfirst($data['name']),
$data['commission1'],
$data['joining_date']);
$i++;
}
echo json_encode($responce);
}
script
var __TEST_DATA__=eval('<?php echo getDesignerCollection();?>');
var grid_demo_id = "myGrid" ;
var dsOption= {
fields :[
{name : 'userID' },
{name : 'name' },
{name : 'commission1'},
{name : 'joining_date'}
],
recordType : 'array',
data : __TEST_DATA__
}
function my_renderId(value ,record,columnObj,grid,colNo,rowNo)
{
var no= record[columnObj.fieldIndex];
return "<input type='checkbox' value='"+record[0]+"' name='userID'/>";
}
var colsOption = [
{id: 'userID' , header: "Customer Id" , width :"90",renderer : my_renderId},
{id: 'name' , header: "Designer Name" , width :"140"},
{id: 'commission1' , header: "commission1" , width :"120"},
{id: 'joining_date' , header: "Customer Since" , width :"120"}
];
now to provide an update button , i am trying below code :
form
<form method="post" name="update" action="updateform.php" />
commission1:
<input type="text" name="commission1" />
<input type="submit" name="Submit" value="update" />
</form>
updateform.php
$sql = "UPDATE tbl_users SET commission1 = '$commission1' WHERE userID= :uid";
$result = $conn->query($sql);
where i need to use form code to display "update" button below values 10 & 0
I am new to php & tried lot before posting here, but did't got any idea related to my code.

Related

Angular 5 - How to fill a FormArray

I will fill the customerNumberContainers which looks like this:
this.form = new FormGroup({
customerNumberContainers: new FormArray([
new FormGroup({
contactTenant: new FormControl('', [Validators.required, Validators.minLength(2)]),
customerNumber: new FormControl('', [Validators.required, Validators.minLength(2)])
}),
]),
Therefore I do this after I get the values over
this.contactService.findContactById(this.id).subscribe(response => { ...
Set values into form:
let customerNumberContainersFormArray: FormArray = this.form.controls.customerNumberContainers as FormArray;
customerNumberContainersFormArray.controls["0"].controls.contactTenant.value = 'TestValue';
but it is not shown with:
in Controller:
get customerNumberContainers(): FormArray {
return this.form.get("customerNumberContainers") as FormArray;
}
in Template:
<div formArrayName="customerNumberContainers">
<div *ngFor="let customerNumberContainer of customerNumberContainers.controls; index as i" [formGroupName]="i">
<mat-input-container class="full-width-input">
<input matInput formControlName="contactTenant">
</mat-input-container>
</div>
Does anyone known what I am doing wrong. It seems for me that values with *ngFor arn't refreshed.
why dont You just patch whole form with model ? like this:
set up your model, for example:
export class Tenants {
id: number;
customerNumberContainers: TenantContact[];
}
export class TenantContact {
contactTenant: string;
customerNumber: string;
}
fetch it from service like u always do but it should match above models and patch whole form (or setValue)
this.contactService.findContactById(this.id).subscribe((tenats: Tenants) => {
this.form.patchValue(tenats);
});

Opencart custom page foreach not showing

Am creating a custom page using Opencart. Here am using foreach for displaying customer details.
But customer details not showing.
Following codes:
.tpl
<?php foreach($dealerData as $invoice){ ?>
<label> <b>Dealer Name:</b> <?php echo $invoice['name']; ?></label><br>
<label><b>Dealer TIN Number:</b> <?php echo $invoice['tin_number'];?></label><br>
<?php } ?>
Controller
$query13 = $this->db->query("select concat(firstname, ' ', lastname) as name, tin_number from ".DB_PREFIX."customer where customer_id='".$customer_id."'");
$dataDelar = $query13->rows;
foreach ($dataDelar as $dealer) {
$data['dealerData'][] = array(
'name' => $dealer['name'],
'tin_number' => $dealer['tin_number']
);
}
Why are you putting queries in your controller? You have models van database related functions. An foreach on the variable $invoiceData1 should work, you can see in the print_r that there is 1 array in the array. Did you put the print_r in your controller? So yes, look bellow that, maybe you are overriding $invoiceData1.
EDIT
You are not creating an empty array to put your values in:
$query13 = $this->db->query("select concat(firstname, ' ', lastname) as name, tin_number from ".DB_PREFIX."customer where customer_id='".$customer_id."'");
$dataDelar = $query13->rows;
$data['dealerData'] = [];
foreach ($dataDelar as $dealer) {
$data['dealerData'][] = array(
'name' => $dealer['name'],
'tin_number' => $dealer['tin_number']
);
}

How to display an image in webgrid

I need to display an image in the column of a webgrid. Webgrid is filled using the list returned from the controller.I used the below code in view and controller respectively:
#using (Html.BeginForm(null, null, FormMethod.Post ))
{
<div id ="DivGrid">
#{
WebGrid grid = new WebGrid(source: Model);
#grid.GetHtml(htmlAttributes: new { id = "DataTable" }, columns: grid.Columns(
grid.Column(format: #<img src="#Href("vPath")"/>),
grid.Column("title","Product Name"),
grid.Column("user_ID","User ID"),
grid.Column("", format: #<text>#Html.ActionLink("Edit", "EditOrder", "OrderStatus", new { id = item.ID})</text>)));
// grid.Column("", format: #<text>#Html.ActionLink("Delete", "DeleteOrder", "OrderStatus", new { id = item.ID}, new { onclick = "return confirm('Are you sure you wish to delete this Order status?');" })</text>)));
}
</div>
using (APM context = new APM())
{
lstorder = (from s in context.T_Order
join p in context.T_OrderDetails on s.ID equals p.Order_ID
join t in context.T_OrderDetailSpecification on p.ID equals t.OrderDetails_ID
join r in context.M_Product on p.Product_ID equals r.ID
where s.OrderStatus_ID == 1 && p.IsPreviewRequired == 1 && p.OrderStatus_ID == 1
select new orderList
{
ID = p.ID,
vPath = r.VirtualPath,
product_ID = r.ID,
title = r.Title,
amount = t.Value,
user_ID= (int)s.User_ID,
sel_ID= (int)p.SelectionList_ID
}).ToList();
return View(lstorder);
}
But the code 'grid.Column(format: #<img src="#Href("vPath")"/>),' not displaying the image .it simply showing the path something like /views/PreviewRequest/vPath
Try this :
I changed
grid.Column(format: #<img src="#Href("vPath")"/>)
to
grid.Column(format: #<img src="#Href(item.vPath)"/>),

Can't get extra form fields when the form is submitted

My automatic generated base form class is as follows:
abstract class BaseGestorForm extends BaseFormDoctrine {
public function setup() {
$this->setWidgets(array(
'persona_fk' => new sfWidgetFormInputHidden(),
'unitat_fk' => new sfWidgetFormInputHidden(),
'baixa' => new sfWidgetFormDateTime(),
));
$this->setValidators(array(
'persona_fk' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('persona_fk')), 'empty_value' => $this->getObject()->get('persona_fk'), 'required' => false)),
'unitat_fk' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('unitat_fk')), 'empty_value' => $this->getObject()->get('unitat_fk'), 'required' => false)),
'baixa' => new sfValidatorDateTime(array('required' => false)),
));
$this->widgetSchema->setNameFormat('gestor[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
$this->setupInheritance();
parent::setup();
}
public function getModelName() {
return 'Gestor';
}
}
In the form I added two extra fields (totes_unitats and unitats_a_gestionar). The first field is a drop down list where users select one or more choices and using jquery when a user press a button the options selected are added to unitats_a_gestionar drop down list. At the same time, these options are removed from totes_unitats list.
class GestorForm extends BaseGestorForm {
public function configure() {
unset($this['baixa']);
$this->widgetSchema['persona_fk'] = new sfWidgetFormChoice(array(
'choices' => UsuariLdap::getAllUsuaris()
));
$this->widgetSchema['totes_unitats'] = new sfWidgetFormChoice(array(
'choices' => UnitatTable::findAllUnitatsPerOrdreArray(),
'multiple' => true
));
$this->widgetSchema['unitats_a_gestionar'] = new sfWidgetFormChoice(array(
'choices' => array(),
'multiple' => true
));
$this->widgetSchema->setLabels(array(
'persona_fk' => 'Gestor',
'unitat_fk' => 'Unitat',
'totes_unitats' => 'Totes les unitats',
'unitats_a_gestionar' => 'Unitats a gestionar'
));
$this->validatorSchema->setOption('allow_extra_fields', true);
$this->validatorSchema['persona_fk'] = new sfValidatorString(array('required' => true), array('required' => 'Requerit'));
}
}
Where I find the problem is in the actions file. First of all, I call the executeNouGestor method that renders the form. Then when the user press to proceed and create the Gestor object, it calls executeValidaGestor that validates the form. This last method calls processFormGestor where there is no way to retrieve the unitats_a_gestionar extra field.
public function executeNouGestor(sfWebRequest $request) {
$this->gestorForm = new GestorForm();
}
public function executeValidaGestor(sfWebRequest $request) {
$this->forward404Unless($request->isMethod(sfRequest::POST));
$this->gestorForm = new GestorForm();
$this->processFormGestor($request, $this->gestorForm);
$this->setTemplate('nouGestor');
}
protected function processFormGestor(sfWebRequest $request, sfForm $gestorForm) {
$gestorForm->bind($request->getParameter($gestorForm->getName()), $request->getFiles($gestorForm->getName()));
if ($gestorForm->isValid()) {
var_dump($_POST);
var_dump($request->getParameterHolder()->getAll());
...
}
}
These two var_dump shows me the following information:
var_dump($_POST):
array(2) {
["gestor"]=>
array(2) {
["persona_fk"]=>
string(3) "330"
["_csrf_token"]=>
string(32) "91e18aa0570bfc7558d21ebb4b98f512"
}
["Desar"]=>
string(5) "Desar"
}
var_dump($request->getParameterHolder()->getAll()):
array(4) {
["gestor"]=>
array(2) {
["persona_fk"]=>
string(3) "330"
["_csrf_token"]=>
string(32) "91e18aa0570bfc7558d21ebb4b98f512"
}
["Desar"]=>
string(5) "Desar"
["module"]=>
string(13) "administracio"
["action"]=>
string(12) "validaGestor"
}
So, as you can see, in ["gestor"] there is no track neither totes_unitats nor unitats_a_gestionar extra form fields. I have no idea why. The way I show the form fields in the template is as usual:
<?php echo $gestorForm['persona_fk']->renderLabel(); ?>
<div class="input"><?php echo $gestorForm['persona_fk']->render(); ?></div>
<div class="error-input"><?php echo $gestorForm['persona_fk']->renderError(); ?></div>
<?php echo $gestorForm['totes_unitats']->renderLabel(); ?>
<div class="input multiple"><?php echo $gestorForm['totes_unitats']->render(); ?></div>
<div class="error-input"><?php echo $gestorForm['totes_unitats']->renderError(); ?></div>
<?php echo $gestorForm['unitats_a_gestionar']->renderLabel(); ?>
<div class="input multiple"><?php echo $gestorForm['unitats_a_gestionar']->render(); ?></div>
<div class="error-input"><?php echo $gestorForm['unitats_a_gestionar']->renderError(); ?></div>
I also add the jquery code that manage the options added or removed between the two drop down lists with multiple selection:
function afegirTreureUnitats() {
var boto_afegir = $("#btn-multiple-afegir");
var boto_treure = $("#btn-multiple-treure");
boto_afegir.click(function() {
var selectedItems = $("#gestor_totes_unitats option:selected");
var output = [];
$.each(selectedItems, function(key, e)
{
output.push('<option value="' + e.value + '">' + e.text + '</option>');
});
$("#gestor_unitats_a_gestionar").append(output.join(""));
ordenaOptionsSelect("gestor_unitats_a_gestionar");
selectedItems.remove();
});
boto_treure.click(function() {
var selectedItems = $("#gestor_unitats_a_gestionar option:selected");
var output = [];
$.each(selectedItems, function(key, e)
{
output.push('<option value="' + e.value + '">' + e.text + '</option>');
});
$("#gestor_totes_unitats").append(output.join(""));
ordenaOptionsSelect("gestor_totes_unitats");
selectedItems.remove();
});
}
function ordenaOptionsSelect(idSelect)
{
var options = $('#' + idSelect + ' option');
options.sort(function(a, b)
{
if (a.text > b.text)
return 1;
else if (a.text < b.text)
return -1;
else
return 0;
});
$('#' + idSelect).empty().append(options);
}
$(document).ready(function() {
afegirTreureUnitats();
});
The form rendered has this appearance:
https://drive.google.com/file/d/0B0Mz720p9Q_DN1RnYWIyR0pXOTQ/edit?usp=sharing
I have also found a curious fact. If I select one of the options in the drop down list, either totes_unitats or unitats_a_gestionar they are sent through POST method, but only one (if I select more than one I only can get one of the options selected).
When you use <select> elements on the form, or <input> of type radio or checkbox the browser will send their values on form submission only when the fields have any options selected.
The list of options in the <select> tag is not sent back to the server. Only the values of the options which are actually selected.
You can resolve your problem in two ways:
Either create a JS which will modify your form just before sending it and will select all the items on both your lists. This way your form will send the values and you will be able to work with them on the server side.
Other option is to add two hidden fields which will keep the lists of the options and modify these lists together with the <select> fields.

Cascading DropDownListView not calling read.action?

I'm using Visual Studio 2012 Internet Application that I've enabled for Kendo UI. This is a MVC4 C# and Razor View Project.
I have more then 6 models i'm eventually going to cascade with these dropdowns
I have been following The Tutorial step by step ( actually copied it and renamed in code ).
When page loads the UI looks great, but NO data is bound to the DropdownLists(/comboboxes)
I'm really only focused on the first DropDownList atm wich is
<p>
<label for="clients">Clients:</label>
#(Html.Kendo().DropDownList()
.Name("clients")
.HtmlAttributes(new { style = "width:300px" })
.OptionLabel("Select Client...")
.DataTextField("Client")
.DataValueField("ClientID")
.DataSource(source => {
source.Read(read => {
read.Action("GetCascadeClients", "ComboBox");
});
})
)
</p>
when the code reaches
.DataSource(source => {
source.Read(read => {
read.Action("GetCascadeClients", "ComboBox");
});
})
it's supposed to call this action, but does not this action is located in the controller for this view
public JsonResult GetCascadeClients()
{
var Clients = db.Clients.AsQueryable();
return Json(db.Clients.Select(c => new { ClientID = c.ClientID, Client = c.Client }), JsonRequestBehavior.AllowGet);
}
My question is what am I doing wrong, it almost has to be something stupid.... ( Yes data is in the database, yes in other controls they bind fine.)
EDIT: Thought it was a little peculiar that the 2 dropdownboxes below show text and the top one doesnt?
Breakpoints not being hit here:
Also i have this scripttag that runs, possibly could be something wrong with it Keep in mind im only looking to fill the first ( if first works the rest should fall in )
<script>
$(document).ready(function () {
var clients = $("#clients").data("kendoDropDownList"),
countys = $("#countys").data("kendoDropDownList"),
townShips = $("#townShips").data("kendoDropDownList");
$("#get").click(function () {
var clientsInfo = "\nclients: { id: " + clients.value() + ", name: " + clients.text() + " }",
countysInfo = "\ncountys: { id: " + countys.value() + ", name: " + countys.text() + " }",
townShipsInfo = "\ntownShips: { id: " + townShips.value() + ", name: " + townShips.text() + " }";
alert("Select Tract To Upload:\n" + clientsInfo + countysInfo + townShipsInfo);
});
});
</script>
#Don Thomas Boyle,I was able to copy your code and use my controller to return json data and I get the Option Label to show "Select Client...". Are you able to get the json string returned by manually calling it in the browser address bar? What is the name of your Controller? "Combobox" sounds like a suspicious controller name to me.
<p>
<label for="clients">Clients:</label>
#(Html.Kendo().DropDownList()
.Name("clients")
.HtmlAttributes(new { style = "width:300px" })
.OptionLabel("Select Client...")
.DataTextField("SiteName")
.DataValueField("ID")
.DataSource(source => {
source.Read(read => {
read.Action("GetSites", "PlayGround");
});
})
)
Here is my controller:
namespace MyWebApp.Controllers
{
public class PlayGroundController : Controller
{
readonly MyEntities context = new MyEntities();
public JsonResult GetSites()
{
var sites = context.vSites.Select(s => new SitesVM
{
ID = s.ID,
SiteName = s.SiteName
}).OrderBy(s => s.SiteName);
return Json(sites, JsonRequestBehavior.AllowGet);
}
}
this line :
.DataTextField("Client")
should be:
.DataTextField("ClientName")

Resources