Image validation in cakephp not working properly - php

I am trying to add image server side validation in cakephp but they are not working properly could anyone help me...i am new in cakephp...here is my view and model file code:-
I am using custom plugin name "Account"
Account.php
class Account extends AccountAppModel {
public $useTable = 'users';
public $name = "Account";
public $validate = array(
'name' => array(
'rule1' => array(
'rule' => 'notEmpty',
'message' => 'Please enter your name!'
),
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'message' => 'Name must be alphabetic or number!'
),
'between' => array(
'rule' => array('between', 3, 20),
'on' => 'create',
'message' => 'Name must be between 5to20 character!'
),
'isUnique' => array(
'rule' => 'isUnique',
'on' => 'create',
'message' => 'Name already taken! please choose another-one!'
)
),
'email'=>array(
'notEmpty'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter Mail ID!'
),
'email'=>array(
'rule'=>'email',
'message'=>'Please enter a valid mail id!'
)
),
'region'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter Region!'
),
'city'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter City!'
),
'password'=>array(
'notEmpty'=>array(
'rule'=>'notEmpty',
'message'=>'please enter password'
),
'between'=>array(
'rule'=>array('between', 5,20),
'message'=>'password must be between 5 to 20 character'
)
),
'cpassword'=>array(
'compare' => array(
'rule'=>array('confirmPassword'),
'message' => 'Password do not match please try again!'
)
),
'photo'=>array(
'mimeType'=>array(
'rule'=>array('mimeType',"photo","photo"),
'message'=>'Please enter a valid image!'
),
'fileSize'=>array(
'rule' => array('fileSize', '<=', '1MB'),
'message'=>'Image is too big please try again!'
),
'uploadError'=>array(
'rule'=>'uploadError',
'message'=>'File upload field!'
)
),
'photo_id'=>array(
'mimeType'=>array(
'rule'=>array('mimeType','photo_id','photo_id'),
'message'=>'Please enter a valid image!'
),
'fileSize'=>array(
'rule'=>array('fileSize','<=','1MB'),
'message'=>'Image is too big please try again!'
),
'uploadError'=>array(
'rule'=>'uploadError',
'message'=>'File upload field!'
)
)
);
function confirmPassword()
{
return $this->data['Account']['password']==$this->data['Account']['cpassword'];
}
public function mimeType($field = null,$cfield = null){
//pr($cfield) or die;
if(isset($field[$cfield]["tmp_name"]) && !empty($field[$cfield]["tmp_name"]))
{
$size = #getimagesize($field[$cfield]["tmp_name"]);
//pr($size) or die;
$imgType = array('image/jpeg','image/jpg');
if(in_array($size['mime'],$imgType)){
$return = true;
}
else{
$return = false;
}
return $return;
}
}
}
and here is add.ctp file code:-
<?php echo $this->Form->create('Account',array('type'=>"file")); ?>
<table width='800px' border='0' align='center'>
<tr>
<td>Name :</td>
<td>
<?php
echo $this->Form->input('name',array('label'=>false,'data-rule-required'=>true,'lettersonly'=>true,"required"=>false));
?>
</td>
<td>E-Mail :</td>
<td>
<?php
echo $this->Form->input('email',
array('label'=>false,'required'=>false,'type'=>'text'));
?>
</td>
</tr>
<tr>
<td>Region :</td>
<td>
<?php
echo $this->Form->input('region',
array('type'=>'select',
'empty'=>'Select Region',
'options'=>$strlt,
'label'=>false,
'id'=>'name',
'data-rule-required'=>true,'required'=>false));
?>
</td>
<td>City :</td>
<td>
<?php
echo $this->Form->input('city',
array('type'=>'select',
'empty'=>'Select City',
'options'=>'',
'label'=>false,
'id'=>'slct',
'data-rule-required'=>true,'required'=>false
)
);
?>
</td>
</tr>
<tr>
<td>Password :</td>
<td>
<?php
echo $this->Form->input('password',
array('type'=>'password',
'label'=>false,
'data-rule-required'=>true,
'id'=>'pass_id',
'required'=>false));
?>
</td>
<td>Confirm Password :</td>
<td>
<?php
echo $this->Form->input('cpassword',
array('type'=>'password',
'label'=>false,
'data-rule-required'=>true,
'equalTo'=>'pass_id','required'=>false));
?>
</td>
</tr>
<tr>
<td>Address</td>
<td>
<?php
echo $this->Form->input('address',
array('label'=>false,
'data-rule-required'=>true,'required'=>false));
?>
</td>
<td>Zip-Code :</td>
<td>
<?php
echo $this->Form->input('zip',
array('label'=>false,
'data-rule-required'=>true,'required'=>false));
?>
</td>
</tr>
<tr>
<td>About Me :</td>
<td>
<?php
echo $this->Form->textarea('about_me',
array('label'=>false,
'data-rule-required'=>true,'required'=>false));
?>
</td>
<td>Contact No :</td>
<td>
<?php
echo $this->Form->input('contact_no',
array('label'=>false,
'data-rule-required'=>true,'required'=>false));
?>
</td>
</tr>
<tr>
<td>Upload Photo :</td>
<td>
<?php
echo $this->Form->input('photo',
array('type'=>'file',
'label'=>false,
'data-rule-required'=>true,'required'=>false));
?>
</td>
<td>Photo ID :</td>
<td>
<?php
echo $this->Form->input('photo_id',
array('type'=>'file',
'label'=>false,
'data-rule-required'=>true,'required'=>false));
?>
</td>
</tr>
<tr>
<td>Show Info :</td>
<td>
<?php
echo $this->Form->input('show_info',
array('type'=>'checkbox',
'label'=>false));
?>
</td>
<td>Premium Member :</td>
<td>
<?php
echo $this->Form->input('membership',
array('type'=>'checkbox',
'label'=>false,'required'=>false));
?>
</td>
</tr>
<tr>
<td>Unit / Company :</td>
<td>
<?php
echo $this->Form->input('user_type', array(
'type' => 'select',
'options' => array('unit' => 'Unit', 'company' => 'Company'),
'selected' => 'Unit',
'label'=>false,
'data-rule-required'=>true,'required'=>false
));
?>
</td>
<td>Status :</td>
<td>
<?php
echo $this->Form->input('status',
array('type'=>'select',
'options'=>array('1'=>'Active',
'0'=>'Inactive'),
'label'=>false,
'data-rule-required'=>true,'required'=>false));
?>
</td>
</tr>
<tr><td colspan=2>
<?php echo $this->Form->input('submit',
array('type'=>'submit',
'label'=>false,'class'=>'btn btn-default','id'=>'sb'));
?>
<?php
echo $this->Html->link('Cancel',
array('plugin'=>'account',
'controller'=>'accounts',
'action'=>'index'),
array('class'=>'btn btn-primary',
'div'=>false,
'escape'=>false,
'id'=>'sb'
)
);
?>
<td><tr>
</table>
<?php echo $this->Form->end();?>

Use Rule ,(Replace your image rule with this)
'photo_id'=>array(
'mimeType'=>array(
'rule' => array('mimeType', array('image/gif', 'image/png', 'image/jpg', 'image/jpeg')),
'message'=>'Please enter a valid image!'
),

Related

CODEIGNITER: dynamically get drop down list but first to appear in list is the selected value

i have a table category that consist of (Dessert,Halal,Vegetarian). i was trying to create a CRUD. now i select the Dessert in my drop down list so i want to fetch all the value in my drop down but i want the Dessert to be seen first in dropdown. this is my code:
VIEW:
<?php $product_id = $product['recipe_id']; ?>
<?php echo form_open("dashboard/edit_product/$product_id");?>
<table>
<tr>
<td>Recipe Name: </td>
<td><?php echo form_input($r_name);?>
<div class="cleaner h10"></div>
</td>
</tr>
<tr>
<td>Recipe Category: </td>
<td><select name="r_category">
<option value=""><?php echo $r_category['value'];?></option>
</select>.
<div class="cleaner h10"></div>
</td>
</tr>
<tr>
<td>Recipe Description: </td>
<td><?php echo form_textarea($r_description); ?>
<div class="cleaner h10"></div></td>
</tr>
<tr>
<td>Recipe Cooking Time: </td>
<td><select name="cooking_time">
<option value=""><?php echo $cooking_time['value'];?></option>
</select>.
<div class="cleaner h10"></div>
</td>
</tr>
<tr>
<tr>
<td>Recipe Calories: </td>
<td><?php echo form_input($r_cal);?>
<div class="cleaner h10"></div>
</td>
</tr>
<tr>
<td>Recipe Serving Size: </td>
<td><?php echo form_input($r_serve);?>
<div class="cleaner h10"></div>
</td>
</tr>
<td>Recipe Procedure: </td>
<td><?php echo form_textarea($r_procedure); ?>
<div class="cleaner h10"></div></td>
</tr>
<td> </td>
<td><?php echo form_submit('submit', 'Submit');?>
<input type="button" name="btnBack" id="btnBack" value="Back" onclick="window.location.href='<?php echo base_url() ?>dashboard'" />
</td>
</tr>
</table>
CONTROLLER:
function edit_product($product_id) {
$product = $this->products_model->get_product($product_id);
$this->load->model('products_model');
$this->data['title'] = 'Edit Recipe';
//validate form input
$this->form_validation->set_rules('r_name', 'Recipe name', 'required|xss_clean');
$this->form_validation->set_rules('r_description', 'Recipe description', 'required|xss_clean');
$this->form_validation->set_rules('r_cal', 'Recipe Calories', 'required|xss_clean');
$this->form_validation->set_rules('r_serve', 'Recipe Serving Size', 'required|xss_clean');
$this->form_validation->set_rules('r_procedure', 'Recipe procedure', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
$data = array(
'r_name' => $this->input->post('r_name'),
'r_category' => $this->input->post('r_category'),
'r_description' => $this->input->post('r_description'),
'cooking_time' => $this->input->post('cooking_time'),
'r_cal' => $this->input->post('r_cal'),
'r_serve' => $this->input->post('r_serve'),
'r_procedure' => $this->input->post('r_procedure'),
);
if ($this->form_validation->run() === true)
{
$this->products_model->update_product($product_id, $data);
$this->session->set_flashdata('message', "<p>Recipe updated successfully.</p>");
redirect(base_url().'dashboard/edit_product/'.$product_id);
}
}
$this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data['product'] = $product;
//display the edit product form
$this->data['r_name'] = array(
'name' => 'r_name',
'id' => 'r_name',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('r_name', $product['r_name']),
);
$this->data['r_image'] = array(
'name' => 'r_image',
'id' => 'r_image',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('r_image', $product['r_image']),
);
$this->data['r_category'] = array(
'name' => 'r_category',
'id' => 'r_category',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('r_category', $product['r_category']),
);
$this->data['r_description'] = array(
'name' => 'r_description',
'id' => 'r_description',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('r_description', $product['r_description']),
);
$this->data['cooking_time'] = array(
'name' => 'cooking_time',
'id' => 'cooking_time',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('cooking_time', $product['cooking_time']),
);
$this->data['r_cal'] = array(
'name' => 'r_cal',
'id' => 'r_cal',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('r_cal', $product['r_cal']),
);
$this->data['r_serve'] = array(
'name' => 'r_serve',
'id' => 'r_serve',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('r_serve', $product['r_serve']),
);
$this->data['r_procedure'] = array(
'name' => 'r_procedure',
'id' => 'r_procedure',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('r_procedure', $product['r_procedure']),
);
//var_dump($this->data);
$this->load->view('edit_product', $this->data);
}
model:
function get_product($product_id) {
$this->db->select('*');
$this->db->where('recipe_id', $product_id);
$query = $this->db->get('recipe');
return $query->row_array();
}

Fedex form Error

This is the HTML form when i submit the form it gives the following error
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from
'../../../wsdl/ShipService_v17.wsdl' : failed to load external entity
"../../../wsdl/ShipService_v17.wsdl" in
D:\Hosting\10722104\html\fedex\php\ShipWebServiceClient\Express\Domestic\ShipWebServiceClient.php5:17
Stack trace: #0
D:\Hosting\10722104\html\fedex\php\ShipWebServiceClient\Express\Domestic\ShipWebServiceClient.php5(17):
SoapClient->SoapClient('../../../wsdl/S...', Array) #1 {main} thrown
in
D:\Hosting\10722104\html\fedex\php\ShipWebServiceClient\Express\Domestic\ShipWebServiceClient.php5
on line 17
` <form id="form1" method="post" action="php/ShipWebServiceClient/Express /Domestic/ShipWebServiceClient.php5">
<div class="from_box">
<div class="top_from_hed">Fill out this Form to Get<br />FREE <img src="images/fed-ex-butoon.png" />Shiping! </div>
<div class="all_felds">1. What are you sending?<br />
<input name="" type="checkbox" value=""onclick="showfirstbox(); " name="sending" /> Diamond <input name="" type="checkbox" value="" /> Gold <input name="" type="checkbox" value="" /> Silver <br />
<br /><br />
<input type="radio" name="printll" id="secondbox" />Print label
<table width="259" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="91" height="29">First Name:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="fname" id="textfield" />
</label>
</form> </td>
</tr>
<tr>
<td width="91" height="28">Last Name:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="lname" id="textfield" />
</label>
</td>
</tr>
<tr>
<td width="91" height="27">Street Address:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="street" id="textfield" />
</label>
</td>
</tr>
<tr>
<td width="91" height="27">Email Address:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="eeemail" id="textfield" />
</label>
</td>
</tr><tr>
<td width="91" height="28">Apt/Suite:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="textfield" id="textfield" />
</label>
</td>
</tr><tr>
<td width="91" height="27">City:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="city" id="textfield" />
</label>
</td>
</tr><tr>
<td width="91" height="27">Country:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="country" id="textfield" />
</label>
</td>
</tr><tr>
<td width="91" height="27">State:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="state_hid" id="textfield" />
</label>
</td>
</tr><tr>
<td width="91" height="28">Zip Code:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="postalcode" id="textfield" />
</label>
</td>
</tr>
<tr>
<td width="91" height="26">Phone no:</td>
<td width="10"> </td>
<td width="162">
<label>
<input type="text" name="phone" id="textfield" />
</label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><table width="157" height="19" border="0" cellpadding="0" ce llspacing="0">
<tr>
<td width="30"> </td>
<td width="74"><div class="submit_from_hed">
<a href="#"><font color="#333333">
<input type="submit"name="fdesubmit" value="submit" /></font></a>
</div></td>
<td width="53"> </td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><table width="156" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="28"> </td>
<td width="128"> </td>
</tr>
</table></td>
</tr>
</table>`
This is the code i am using for fedex form integration
`<?php
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 12.0.0
require_once('../../../library/fedex-common.php5');
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "../../../wsdl/ShipService_v17.wsdl";
define('SHIP_LABEL', time() . '.png'); // PNG label file. Change to file-extension .pdf for creating a PDF label (e.g. shiplabel.pdf)
ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache", "0");
ini_set("display_errors","On");
ini_set("track_errors","On");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$name='';
$invoice_num='INV' . time() * 3;
$option=$_REQUEST['option'];
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Express Domestic Shipping Request using PHP ***');
$request['Version'] = array(
'ServiceId' => 'ship',
'Major' => '10',
'Intermediate' => '0',
'Minor' => '0'
);
$request['RequestedShipment'] = array(
'ShipTimestamp' => date('c'),
'DropoffType' => 'REGULAR_PICKUP',
'ServiceType' => 'FEDEX_EXPRESS_SAVER',
'PackagingType' => 'YOUR_PACKAGING',
'Shipper' => addShipper(),
'Recipient' => addRecipient(),
'ShippingChargesPayment' => addShippingChargesPayment(),
'SpecialServicesRequested' => addSpecialServices(),
'LabelSpecification' => addLabelSpecification(),
'PackageCount' => 1,
'RequestedPackageLineItems' => array(
'0' => addPackageLineItem1()
)
);
try {
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client->processShipment($request); // FedEx web service invocation
if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR'){
printSuccess($client, $response);
$fp = fopen('../label/' . SHIP_LABEL, 'wb');
fwrite($fp, $response->CompletedShipmentDetail->AssociatedShipments->Label->Parts->Image); //Create COD Return PNG or PDF file
fclose($fp);
$message1="Transaction Successful<br>";
if($option==$_POST['printll'])
{
$link=SHIP_LABEL;
$message='<div id="label1" style="margin-bottom:-10px;">
<div id="number"></div>
<div id="message"> <h3 style="color:#666;">Click here to print your label</h3>
</div>
</div>';
$message.='<div id="label1">
<div id="second"> </div>
</div>';
$message.='<div id="label1">
<div id="third"></div>
</div>';
}
}else{
writeToLog($client); } // Write to log file
}
catch (SoapFault $exception) {
printFault($exception, $client);
}
function addShipper(){
$name=$_POST['fname'] . " " . $_POST['lname'];
$shipper = array(
'Contact' => array(
'PersonName' => $name,
'CompanyName' => '',
'PhoneNumber' => $_POST['phone'],
'Email' => $_POST['eeemail'],
),
'Address' => array(
'StreetLines' => array($_POST['street']),
'City' => $_POST['city'],
'StateOrProvinceCode' => $_REQUEST['state_hid'],
'PostalCode' => $_REQUEST['postalcode'],
'CountryCode' => $_REQUEST['country'])
);
return $shipper;
}
function addRecipient(){
$recipient = array(
'Contact' => array(
'Contact' => array(
'PersonName' => 'CRJ Inc',
'CompanyName' => 'CRJ Inc c/o NDB',
'PhoneNumber' => '800-574-8820'),
'Address' => array(
'StreetLines' => array('4010 Oak Circle'),
'City' => 'Boca Raton',
'StateOrProvinceCode' => 'FL',
'PostalCode' => '33431',
'CountryCode' => 'US',
'Residential' => false)
)
) ;
return $recipient ;
}
function addShippingChargesPayment(){
$shippingChargesPayment = array('PaymentType' => 'SENDER',
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => getProperty('billaccount'),
'Contact' => null,
'Address' => array(
'CountryCode' => 'US')
)
)
);
return $shippingChargesPayment;
}
function addLabelSpecification(){
$labelSpecification = array(
'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PNG', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_7X4.75'
);
return $labelSpecification;
}
function addSpecialServices1(){
$specialServices = array(
'SpecialServiceTypes' => array('COD'),
'CodDetail' => array(
'CodCollectionAmount' => array(
'Currency' => 'USD',
'Amount' => 150
),
'CollectionType' => 'ANY' // ANY, GUARANTEED_FUNDS
)
);
return $specialServices;
}
function addCustomClearanceDetail(){
$customerClearanceDetail = array(
'DutiesPayment' => array(
'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array(
'AccountNumber' => getProperty('dutyaccount'),
'CountryCode' => 'CA'
)
),
'DocumentContent' => 'NON_DOCUMENTS',
'CustomsValue' => array(
'Currency' => 'USD',
'Amount' => 20.0
),
'Commodities' => array(
'0' => array(
'NumberOfPieces' => 1,
'Description' => 'Books',
'CountryOfManufacture' => 'US',
'Weight' => array(
'Units' => 'LB',
'Value' => 1.0
),
'CustomsValue' => array(
'Currency' => 'USD',
'Amount' => 20.000000
)
)
),
'ExportDetail' => array(
'B13AFilingOption' => 'NOT_REQUIRED'
)
);
return $customerClearanceDetail;
}
function addPackageLineItem1(){
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'InsuredValue' => array(
'Amount' => 20.00,
'Currency' => 'USD'
),
'Weight' => array(
'Value' => 1.0,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 20,
'Width' => 10,
'Height' => 10,
'Units' => 'IN'
),
'CustomerReferences' => array(
'0' => array(
'CustomerReferenceType' => 'CUSTOMER_REFERENCE',
'Value' => 'GR' . time() * 7
), // valid values CUSTOMER_REFERENCE, INVOICE_NUMBER, P_O_NUMBER and SHIPMENT_INTEGRITY
'1' => array(
'CustomerReferenceType' => 'INVOICE_NUMBER',
'Value' => $invoice_num
),
'2' => array(
'CustomerReferenceType' => 'P_O_NUMBER',
'Value' => 'PO' .time() * 5
)
)
);
return $packageLineItem;
}
?>
`
Please find me some solution for this so that i would be able to create labels from the website

How to update database in codeigniter

I have this code for updating the database but wont just work. Help me to trace the error:
The error is in validation but i cant find any problem with my code. It brings this error: 'product_name required'
'username required '
'email required'
'usertype required'
and therefore it does not update my database. I have just included code for only 4 items in the controller and view
My controller
function edit_product($product_id) {
$product = $this->generalmod_model->get_product($product_id);
//validate form input
$this->form_validation->set_rules('product_name', 'product_name name', 'required|xss_clean');
$this->form_validation->set_rules('username', 'username', 'required|xss_clean');
$this->form_validation->set_rules('email', 'email', 'required|xss_clean');
$this->form_validation->set_rules('usertype', 'usertype', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
$data = array(
'product_name' => $this->input->post('product_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'usertype' => $this->input->post('usertype'),
);
if ($this->form_validation->run() === true)
{
$this->generalmod_model->update_product($product_id, $data);
echo "updated successfully";
}
}
$this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data['product'] = $product;
//display the edit product form
$this->data['product_name'] = array(
'product_name' => 'product_name',
'id' => 'product_name',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('product_name', $product['product_name']),
);
$this->data['username'] = array(
'username' => 'username',
'id' => 'username',
'type' => 'text',
'style' => 'width:300px',
'value' => $this->form_validation->set_value('username', $product['username']),
);
$this->data['email'] = array(
'email' => 'email',
'id' => 'email',
'type' => 'text',
'style' => 'width:300px',
'value' => $this->form_validation->set_value('email', $product['email']),
);
$this->data['usertype'] = array(
'usertype' => 'usertype',
'id' => 'usertype',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('usertype', $product['usertype']),
);
$this->load->view('update_profile', $this->data);
}
My model
function get_product($product_id)
{
$this->db->select('user_id, product_name, username, email, usertype');
$this->db->where('user_id', $product_id);
$query = $this->db->get('users');
return $query->row_array();
}
public function update_product($product_id, $data)
{
$this->db->where('user_id', $product_id);
$this->db->update('users', $data);
}
view :
echo form_open("generalcon/edit_product/$product_id");?>
<table width="700" border="1" cellpadding="0" cellspacing="2" align="center">
<tr>
<td width="130" align="right"> product Name: </td>
<td><?php echo form_input($product_name); ?></td>
</tr>
<tr>
<td width="130" align="right"> username: </td>
<td><?php echo form_input($username); ?></td>
</tr>
<tr>
<td align="right">Email:</td>
<td><?php echo form_input($email); ?></td>
</tr>
<tr>
<td align="right">usertype:</td>
<td><?php echo form_input($usertype); ?></td>
</tr>
<tr>
<td> </td>
<td><?php echo form_submit('submit', 'Submit');?>
<input type="button" name="btnBack" id="btnBack" value="Back" onclick="window.location.href='<?php echo base_url() ?>manage'" />
</td>
</tr>
</table>
For the validation error that you are getting, in each of the arrays in the controller where you set up the form fields, the array key needs to be 'name' instead of its title. For example you have 'username' => 'username' and 'email' => 'email'. This needs to be 'name' => 'username' and 'name' => 'email'.
Also, in the first line of the view file, the $product_id variable is not being parsed by php as you intend. You need <?php echo form_open("generalcon/edit_product/".$product_id); ?> with the $product_id outside the quotation marks and concatenated with a period.

PHP : combo box value is not getting updated in codeigniter

I have table view of some product which get data from database, there are two option edit and delete when I click on edit it shows particular data.
There is 2 categories inside combo box say Pizza and Sandwich.
By default Pizza is selected, and the value in database is also Pizza only now the problem begins, when I select sandwich instead of pizza the value in database is not getting updated.
I have used codeigniter framework for this project, so I want solution in same framework.
I have searched in google and many other way but hard luck, not getting proper solution what I want.
Any help would be appreciated. Thank in advance.
code: Controller
function products_edit($product_id)
{
$this->load->library('form_validation');
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('products_model');
$data=$this->products_model->general();
$product = $this->products_model->get_product($product_id);
$category['categories']=$this->products_model->get_category();
$this->data1['title'] = 'Edit Product';
//validate form input
$this->form_validation->set_rules('name', 'Product name', 'required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'required|xss_clean');
$this->form_validation->set_rules('price', 'Price', 'required|xss_clean');
$this->form_validation->set_rules('is_featured', 'Is Featured', 'required|xss_clean');
$this->form_validation->set_rules('prorder', 'Order', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
$data1 = array(
'product_name'=> $this->input->post('name'),
'product_desc'=> $this->input->post('description'),
'product_category'=> $this->input->post('category'),
'extras'=> $this->input->post('extras'),
'price'=> $this->input->post('price'),
'is_featured'=> $this->input->post('is_featured'),
'prorder' => $this->input->post('order'),
);
if ($this->form_validation->run() === true)
{
$this->products_model->updateproducts($product_id, $data1);
$this->session->set_flashdata('message', "<p>Product updated successfully.</p>");
redirect('products_controller/products_edit/'.$product_id);
}
}
$this->data1['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data1['product'] = $product;
//$this->data1['category']=$category;
//display the edit product form
$this->data1['name'] = array(
'name' => 'name',
'id' => 'name',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('name', $product['product_name']),
);
$this->data1['description'] = array(
'name' => 'description',
'id' => 'description',
'type' => 'text',
'cols' => 40,
'rows' => 5,
'value' => $this->form_validation->set_value('description', $product['product_desc']),
);
$category1=$this->products_model->get_category();
$category1['value']=set_value('category',$product['product_category']);
$temp=array(
'1'=>$category1['value'],
);
$category1=array_diff($category1,$temp);
$category1['value']=set_value('category',$product['product_category']);
$this->data1['category']=$category1;
$this->data1['extras'] = array(
'value' => $this->form_validation->set_value('extras', $product['extras']),
);
$this->data1['price'] = array(
'name' => 'price',
'id' => 'price',
'type' => 'text',
'style' => 'width:40px;text-align: right',
'value' => $this->form_validation->set_value('price', $product['price']),
);
$this->data1['is_featured'] = array(
'name' => 'is_featured',
'id' => 'is_featured',
'type' => 'text',
'style' => 'width:40px;text-align: right',
'value' => $this->form_validation->set_value('isfeatured', $product['is_featured']),
);
$this->data1['prorder'] = array(
'name' => 'prorder',
'id' => 'prorder',
'type' => 'text',
'style' => 'width:40px;',
'value' => $this->form_validation->set_value('prorder', $product['prorder']),
);
$this->load->view('products_edit', $this->data1);
}
Model:
function get_product($product_id) {
$this->db->select('product_id,product_name,product_desc,product_category,extras,price,is_featured,prorder');
$this->db->where('product_id', $product_id);
$this->db->distinct('product_category');
$query = $this->db->get('product');
return $query->row_array();
}
function updateproducts($product_id, $data)
{
$this->db->where('product_id', $product_id);
$this->db->update('product', $data);
}
View :
<?php $product_id = $product['product_id']; ?>
<?php echo form_open("products_controller/products_edit/$product_id");?>
<table width="500" border="1" cellpadding="0" cellspacing="2" align="center">
<tr>
<td width="130" align="right"> Product Name: </td>
<td><?php echo form_input($name); ?></td>
</tr>
<tr>
<td width="130" align="right"> Product Description: </td>
<td><?php echo form_textarea($description); ?></td>
</tr>
<tr>
<td align="right">Product Category:</td>
<td>
<?php echo form_dropdown("product_id",$category,'value')?>
</td>
</tr>
<tr>
<td align="right">Extras:</td>
<td><?php echo form_dropdown("product_id",$extras,"#","id='product_id'");?></td>
</tr>
<tr>
<td align="right">Price:</td>
<td><?php echo form_input($price); ?></td>
</tr>
<tr>
<td align="right">Is Featured:</td>
<td><?php echo form_input($is_featured); ?></td>
</tr>
<tr>
<td align="right">Order:</td>
<td><?php echo form_input($prorder); ?></td>
</tr>
<tr>
<td> </td>
<td><?php echo form_submit('submit', 'Submit');?>
</td>
</tr>
</table>
<table align="center">
<tr>
<td>
<?php echo form_close(); ?>
<?php echo form_open("products_controller/products_search");?>
<?php echo form_submit('submit', 'Back');?>
<?php echo form_close(); ?>

My GET type form is displaying a POST type form in cakephp

I am trying to create a multiple search query using GET but it show differently.
below is my view code:
echo $this->form->create('Place', array('type' => 'get', 'class' => 'form-inline', 'url' => array_merge(array('action' => 'admin_index'))));
echo $this->Form->input('province', array(
'options' => $provinces,
'label' => false,
'value' => $this->request->query['province'],
'div' => false,
));
echo " ";
$type = array(
' ' => '-Choose type of place',
'attraction' => 'Attraction',
'hotel' => 'Hotel',
'restaurant' => 'Restaurant'
);
echo $this->Form->input('place_type', array(
'options' => $type,
'label' => false,
'div' => false,
));
echo " ";
echo $this->Form->input('title', array(
'placeholder' => 'Enter title',
'label' => false,
'div' => false,
));
?>
<input type="submit" class="btn btn-primary" value="Filter">
<?php echo $this->Html->link('Reset', array('action' => 'index'));?>
<?php echo $this->form->end(); ?>
</div>
</div>
<!-- <div class="row-fluid">
<div class="pagination pagination-large"> -->
<!-- <ul>
<?php
echo $this->Paginator->numbers(array(
'separator' => false,
'tag' => 'li',
'currentClass' => 'active',
'currentTag' => 'span',
'modulus' => 5,
'first' => 1,
'last' => 1,
'ellipsis' => '<li><span>...</span></li>',
));
?>
</ul>
</div>
<div class="well well-small counter"><?php echo $this->Paginator->counter(array(
'format' => __('{:page} - {:pages} of {:count} records', true)
)); ?></div>
</div> end of top section row fluid -->
<div class="row-fluid">
<div class="span14">
<table class="table table-hover">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('title'); ?></th>
<th><?php echo $this->Paginator->sort('place_type'); ?></th>
<th><?php echo $this->Paginator->sort('city'); ?></th>
<th><?php echo $this->Paginator->sort('province'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $key => $place): ?>
<tr>
<td><?php echo h($place['Place']['id']); ?> </td>
<td>
<?php echo $this->Html->link($place['Place']['title'], '/spot/' . $place['Place']['slug'])?>
</td>
<td>
<?php echo $place['Place']['place_type']; ?>
</td>
<td>
<?php echo $place['Place']['city']; ?>
</td>
<td>
<?php echo $place['Place']['province'] . ", " . $place['Place']['country_code']; ?>
</td>
<td>
<?php echo $place['Place']['created']; ?>
</td>
<td>
<?php
echo $this->Html->link(
'Edit',
array('action' => 'edit', $place["Place"]["id"], 'admin' => false),
array("class" => "btn btn-custom")
) . " ";
?>
</td>
<td>
<?php
echo $this->Form->create("Place", array('action' => 'delete', 'onSubmit' => 'return confirm("Do you really want to delete this content?");'));
echo $this->Form->hidden("id", array("value" => $place['Place']['id']));
$options = array(
'label' => 'Delete',
'class' => 'btn btn-custom',
);
echo $this->Form->end($options);
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="row-fluid">
<div class="paging clearfix span12">
<div class="pagination pagination-large">
<ul><?php echo $this->Paginator->numbers(array(
'separator' => false,
'tag' => 'li',
'currentClass' => 'active',
'currentTag' => 'span',
'modulus' => 5,
'first' => 1,
'last' => 1,
'ellipsis' => '<li><span>...</span></li>',
)); ?></ul>
</div>
<div class="well well-small counter"><?php echo $this->Paginator->counter(array(
'format' => __('{:page} - {:pages} of {:count} records', true)
)); ?></div>
</div>
</div>
I use debug() to see what the form is printing and it is getting this details:
'<select name="data[province]" id="province">
<option value="ZSU">Zamboanga Del Sur</option>
<option value="ZSI">Zamboanga Sibugay</option>
</select>'
the name="data[province]" should not be appearing because I am using a GET type and it should show this instead name="province" Am I missing something here? Thank you in advance

Categories