I use Zend\InputFilter\InputFilter class for form validation. point field should accept only integers between 1 and 5. But it doesn't work properly it accepts string starting with integers between 1 and 5. For example 1kjhkjh, 2tgfjhgfjhf, 4jhkljg...
What is wrong in my code?
$inputFilter->add (
$inputFilter->getFactory()->createInput (
array (
'name' => 'point',
'required' => true,
'validators' => array (
array(
'name' => 'Digits'),
array (
'name' => 'Between',
'options' => array (
'min' => 1,
'max' => 5,
'messages' => array('notBetween' => 'Point must be between %min% and %max%')
)
)
)
)
)
);
Use the the second parameter of zend validator to break the validators chain and return an error, breakChainOnFailure (documentation) tells the element to stop validating if this error is triggered, so in your case if it is not a digit the user gets an error, when the user has fixed the error the second validator will get triggered too:
$inputFilter->add (
$inputFilter->getFactory()->createInput (
array (
'name' => 'point',
'required' => true,
'validators' => array (
array(
'name' => 'Digits', 'breakChainOnFailure' => true),
array (
'name' => 'Between',
'options' => array (
'min' => 1,
'max' => 5,
'messages' => array('notBetween' => 'Point must be between %min% and %max%')
)
)
)
)
)
);
Another option would be to replace Zend_Validate_Digits with Zend_Validate_Int (docmentation) depending of what error message you prefer to give to the user if he enters non valid data. Of course as suggested in the comments you could also use the Zend_Filter_Int if what you want is to handle any non valid data by fixing it yourself and do not give the user feedback about what he did wrong.
'breakChainOnFailure': true
should be
'breakChainOnFailure'=> true
Related
i am using the following code to get files from folder id. But I am not getting the files id instead empty array returning.
putenv('GOOGLE_APPLICATION_CREDENTIALS=C:\Users\new\Downloads\zonefunnel1.json');
$client = new Google_Client();
$client->addScope(Google_Service_Drive::DRIVE);
$client->useApplicationDefaultCredentials();
$service = new Google_Service_Drive($client);
$res=$service->files->listFiles();
//print_r($res);
$folderId="0B_bZZilaXPR4WkNvdFpMZmdneEU";
$optParams = array(
'pageSize' => 10,
'fields' => "nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents)",
'q' => "'".$folderId."' in parents"
);
$results = $service->files->listFiles($optParams);
print_r($results);die();
I am getting the following,
Google_Service_Drive_FileList Object ( [collection_key:protected] => files [filesType:protected] => Google_Service_Drive_DriveFile [filesDataType:protected] => array [incompleteSearch] => [kind] => [nextPageToken] => [internal_gapi_mappings:protected] => Array ( ) [modelData:protected] => Array ( ) [processed:protected] => Array ( ) [files] => Array ( ) )
Please help me I have spent one week time for this.But not able to sort it out.
Regards,
Rekha
$files_list = $service->files->listFiles(array())->getFiles($optParams);
I want to sort this array by product price in ascending order. How can I do this?
Array
(
[0] => stdClass Object
(
[product_id] => 16
[product_name] => Ferrari 4802
[product_details] => I know this car is good. Because I have driven this car 10 year.
[product_quantity] => 1
[product_price] => 2560
[shipping_cost] => 1000
[product_image] => ./admin_assets/image/uploads/product_image/ea28444f93d1fea413c95861bf306fbf.jpg
[product_details_image] => ./admin_assets/image/uploads/product_details/ea28444f93d1fea413c95861bf306fbf.jpg
[thumbnails_image] => ./admin_assets/image/uploads/thumbnails/ea28444f93d1fea413c95861bf306fbf.jpg
[slidder_image] => ./admin_assets/image/uploads/slidders/ea28444f93d1fea413c95861bf306fbf.jpg
[status] => 1
[slidder] =>
[category_id] => 4
)
[1] => stdClass Object
(
[product_id] => 15
[product_name] => Laborghini urus
[product_details] => I know this car is good. Because I have driven this car 10 year.
[product_quantity] => 2
[product_price] => 500
[shipping_cost] => 1000
[product_image] => ./admin_assets/image/uploads/product_image/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[product_details_image] => ./admin_assets/image/uploads/product_details/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[thumbnails_image] => ./admin_assets/image/uploads/thumbnails/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[slidder_image] => ./admin_assets/image/uploads/slidders/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[status] => 1
[slidder] =>
[category_id] => 4
)
[2] => stdClass Object
(
[product_id] => 14
[product_name] => Laborghini hurican023
[product_details] => I know this car is good. Because I have driven this car 10 year.
[product_quantity] => 4
[product_price] => 50
[shipping_cost] => 1000
[product_image] => ./admin_assets/image/uploads/product_image/65e660ef6e3ebcb0773d87c048c93e1b.png
[product_details_image] => ./admin_assets/image/uploads/product_details/65e660ef6e3ebcb0773d87c048c93e1b.png
[thumbnails_image] => ./admin_assets/image/uploads/thumbnails/65e660ef6e3ebcb0773d87c048c93e1b.png
[slidder_image] => ./admin_assets/image/uploads/slidders/65e660ef6e3ebcb0773d87c048c93e1b.png
[status] => 1
[slidder] =>
[category_id] => 4
)
)
Because the array is generated by a database query you can easily have the query do the sorting for you.
You don't show your model code but assuming you are using Query Builder (a.k.a. Active Record) you need the following in your model before you execute $this->db->get().
$this->db->order_by('product_price', 'ASC');
Here is some example code showing a full query. It assumes the table is named 'products', you want to select all the table's fields, and you want only a particular 'category_id'.
In the Model file:
public function product_by_category($category)
{
$query = $this->db
->where('category_id', $category)
->order_by('product_price', 'ASC')
->get('products');
//return all records or NULL if no records are found
return $query->num_rows() > 0 ? $query->result() : NULL;
}
I was wondering how I could get the usernames, etc. from messages using the API. Calling the GET messages API gives me all the info I need from the message, but I only get the userID. Because of API request limits, I can't afford to do another API request to know for each messages all the needed userinfo.
Am I missing something, or is this simply not possible?
In fact, check the "references" part of the response and you will find the whole details concerning your user.
I dont see where that is? This is my API response from yammer (for one message)
Array
(
[0] => stdClass Object
(
[id] => 544689850
[sender_id] => 1507082247
[replied_to_id] => 544673530
[created_at] => 2015/06/04 13:03:09 +0000
[network_id] => 355014
[message_type] => update
[sender_type] => user
[url] => https://www.yammer.com/api/v1/messages/544689850
[web_url] => https://www.yammer.com/b-rail.be/messages/544689850
[group_id] => 5741341
[body] => stdClass Object
(
[parsed] => Signed and Approved!
[plain] => Signed and Approved!
[rich] => Signed and Approved!
)
[thread_id] => 544673530
[client_type] => Web
[client_url] => https://www.yammer.com/
[system_message] =>
[direct_message] =>
[chat_client_sequence] =>
[language] => en
[notified_user_ids] => Array
(
)
[privacy] => private
[attachments] => Array
(
)
[liked_by] => stdClass Object
(
[count] => 0
[names] => Array
(
)
)
[content_excerpt] => Signed and Approved!
[group_created_id] => 5741341
)
I wrote shippment module with checking a lot of resources/tutorials etc. I am using magento 1.9. Source of module is:
https://github.com/aleextra/magentoshipping
I lost full day to find why it doesn't works fine. Magento see my module, when I am adding at Model/Carrier.php at line 52 code:
die($result);
it shows objec dump:
Mage_Shipping_Model_Rate_Result Object
(
[_rates:protected] => Array
(
[0] => Mage_Shipping_Model_Rate_Result_Method Object
(
[_data:protected] => Array
(
[carrier] => mikshipping
[carrier_title] => Mik Carrier
[method] => fixed
[method_title] => Fixed price 10
[price] => 10
[cost] => 10.00
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
)
[_error:protected] =>
)
What I am doing wrong?
As a quick guess I say that your carriers name in the config.xml (mshipping) does not match the code used in Carrier.php (mikshipping). I have them always being the same so Iḿ not absolutely sure if this might cause the issue, but it is easy to check.
Model :
function trans_gdc_add()
{
$trans_gdc_gc_package[0] = $this->input->post('trans_gdc_gc_package');
$trans_gdc_gc_package1 = implode(",", $trans_gdc_gc_package[0]);
$add=array(
'trans_gdc_no' => $this->input->post('trans_gdc_no'),
'trans_gdc_to' => $this->input->post('trans_gdc_to'),
'trans_gdc_vehicle_no' => $this->input->post('trans_gdc_vehicle_no'),
'trans_gdc_vehicle_type' => $this->input->post('trans_gdc_vehicle_type'),
'trans_gdc_vehicle_chas' => $this->input->post('trans_gdc_vehicle_chas'),
'trans_gdc_vehicle_make' => $this->input->post('trans_gdc_vehicle_make'),
'trans_gdc_vehicle_eng' => $this->input->post('trans_gdc_vehicle_eng'),
'trans_gdc_vehicle_permit' => $this->input->post('trans_gdc_vehicle_permit'),
'trans_gdc_vehicle_pol' => $this->input->post('trans_gdc_vehicle_pol'),
'trans_gdc_vehicle_isby' => $this->input->post('trans_gdc_vehicle_isby'),
' trans_gdc_date' => $this->input->post(' trans_gdc_date'),
'trans_gdc_from' => $this->input->post('trans_gdc_from'),
'trans_gdc_driver_add' => $this->input->post('trans_gdc_driver_add'),
'trans_gdc_lic_no' => $this->input->post('trans_gdc_lic_no'),
'trans_gdc_vehilce_owner_name' => $this->input->post('trans_gdc_vehilce_owner_name'),
'trans_gdc_vehicle_owner_add' => $this->input->post('trans_gdc_vehicle_owner_add'),
'trans_gdc_vehicle_owner_mob' => $this->input->post('trans_gdc_vehicle_owner_mob'),
'trans_gdc_broker_name' => $this->input->post('trans_gdc_broker_name'),
'trans_gdc_broker_mob' => $this->input->post('trans_gdc_broker_mob'),
'trans_gdc_gc_no' => $this->input->post('trans_gdc_gc_no'),
'trans_gdc_gc_package' => $trans_gdc_gc_package1,
'trans_gdc_gc_cont' => $this->input->post('trans_gdc_gc_cont'),
'trans_gdc_gc_weight' => $this->input->post('trans_gdc_gc_weight'),
'trans_gdc_gc_freight' => $this->input->post('trans_gdc_gc_freight'),
'trans_gdc_gc_consignor' => $this->input->post('trans_gdc_gc_consignor'),
'trans_gdc_gc_consignee' => $this->input->post('trans_gdc_gc_consignee'),
'status' => '1'
);
return $this->db->insert('trans_gc_add',$add);
}
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: mysql/mysql_driver.php
Line Number: 552
Please help me to resolve this issue .
check this
' trans_gdc_date' => $this->input->post(' trans_gdc_date'),
space might be giving the problem, repla
'trans_gdc_date' => $this->input->post(' trans_gdc_date'),
You can't directly merge strings in arrays!
your trying to merge concatinate strings with arrays or lets say arrays with string thats not possible
General Example
<?php
$stack = array("Orange", "Banane");
array_push($stack, "Apfel", "Himbeere");
print_r($stack);
?>
for your code Example
// array push tiggers a php array as stack!
$add=array()
array_push($add, 'trans_gdc_no', $this->input->post('trans_gdc_no'));
array_push($add, 'trans_gdc_to', $this->input->post('trans_gdc_to'));
print_r($add);