I am using codeigniter form validation rules.Instead of showing me correct error message it is showing "Field was not set". I want to show error related to field name.
This is my code.
$this->form_validation->set_rules('project_name', 'Project Name', 'trim|required');
how to show that "Firstbane is required" or something default of codeigniter.
Thanks in advance!
I had the same problem.
I solved it as follow:
I have "xampp" installed, with the option "short_open_tag=false" in the "php.ini" file. I have the package of spanish language installed, too. This one have "validation_lang.php" file in the path "system/laguage/spanish" (I'm Spaniard) and it start with "<?" short tag. Well, I changed the "<?" by "<?php". Later, my program worked.
I hope it can help you.
Excuse me my bad English!
You can set a custom error message with set_message and use the label from the set_rules function. You can find the documentation here.
Here is an example:
// Set the validation rule
$this->form_validation->set_rules('project_name', 'Project Name', 'trim|required');
// Set the custom message with %s where the label should go
$this->form_validation->set_message('required', '%s is required. Please enter a value.');
// For an invalid project_name, you will get the error:
// Project Name is required. Please enter a value.
In my case user3110655, I got the same issue when using another language than english with system language files downloaded over the web.
All files were good, except form_validation one.
Keys wasn't written like the english file and tag wasn't with %s as expected.
If using a language file, double check that your file is correctly written like the english one provided by code igniter.
Related
I want to test that warning messages are displayed correctly when form fields are returned as invalid. The best way to do this would be to access the array in validation.php to get the name of the language line that I want to use.
How can I do this?
The documentation for Laravel is very great. You can access language files in resources/lang/{locale}/ easily with the provided trans() function (Laravel 5):
$expected = 'The :attribute may only contain letters.';
$actual = trans('validation.alpha');
$this->assertEquals($expected,$actual);
Please provide your attempts in the question next time. Also have a look at the SO tour (you will be rewarded with a bronze badge afterwards!)
I'm trying to create a second invoice template and add another print invoice link so I can print a standard invoice but also print a 'internal' invoice copy with an 'Official Use' table in which can be filled out by staff on the print out.
I've found the template invoice.tpl and print_invoice.tpl in /basic/mail/orders/
created two new files called invoice.dirty.tpl and print_invoice_dirty.tpl and pasted the content of the original files in the new ones, changed the path and added the table I wanted.
I've managed to locate the code for the 'Print Invoice' link and duplicated that changing the href by adding _dirty to the original 'orders.print_invoice?' but when I try the link it opens the popup ok but I get a 404 error, i've checked the permissions and changed them to full but still it won't play ball...
it seemed quite simple and I expected it to work but obviously i'm missing something, any guidance would be appreciated.
Check controllers that bring data to this files, maybe there is the main problem.
What cs-cart version are you using?
You need to create also the mode > invoice_dirty and this can be added with the help of file order.post.php but before i can give you some instructions i need to know you cs-cart version
When I turn on cache in Magento, I get the following exception:
Serialization of 'Mage_Core_Model_Layout_Element' is not allowed
Exception occurs in app/code/core/Mage/Page/Block/Template/Links.php, on line:
return parent::getCacheKeyInfo() + array(
'links' => base64_encode(serialize($links)),
'name' => $this->getNameInLayout()
)
I am using Magento Enterprise 1.10 and PHP 5.3.
Can anyone tell me what the problem is?
You shouldn't have an empty after_text or before_text tags in your layout file. If you don't need it, just delete the tag at all.
If it will not help, dump the $links variable before the 150th line in the app/code/core/Mage/Page/Block/Template/Links.php file, and you will see an array with arrays inside it. All of keys and values should be strings or integers, not objects. The key of array value which is an object will tell you which tag to delete from the layout file.
Awesome #vsushkov.
I used:
try{
serialize($links);
} catch(Exception $e){
Mage::log($links);
die;
}
to find out exact layout where we had those empty tags and after removing those empty tags, it fixed the issue and then removed above code :-)
Saw this issue on a clients site. None of the solutions above worked for me. After much googling of the error, it seems to be related to JM or JoomlArt themes/extensions.
The code is extremely poorly written. For example some of the things you will find in these themes include:
Declaring php classes inside templates,
Setting global variables inside templates,
Setting data into superglobals from templates,
Providing a translation file, yet not wrapping most text strings in template in the translate function
I found 1 response from their support staff essentially suggesting to turn off error reporting to fix the issue.
I found my problem in app/design/frontend/default/jm_adamite/template/catalog/navigation/tops.phtml
There was a line setting $this into $_SESSION. I commented it out and the error went away. Nothing else appeared broken. A grep for that variable being used anywhere else had 0 results. If you have one of these JM extensions installed or use one of their themes, I would suspect that first
Good luck
This problem happened to me when trying to serialize categories after calling the getCategoryUrl function after digging i found out that that set _urlModel object which cannot be serialized as it contains Mage_Core_Model_Layout_Element so before serializing the object check if it has that _urlModel property
I'm using Kohana validation library and I want to set up my own user friendly error messages. The problem is that I generate the form dynamically, so field names are not know during development.
Can a set up error messages for the different validation rules (required, digit, ...) regardless the field name? How?
Note: I'm using Kohana v2.3.4
I know about this problem.
What I ended up doing, is something like this (though this does not know what type of error occurred, it worked for me in my situation).
Assume $errors are the errors returned from the validation library.
My view
<input type="text" id="input-something" name="something" />
<?php if (isset($errors['something']): ?>
<label for="input-something" class="error">Something didn't go right!</label>
<?php endif; ?>
Usually I would echo the $errors['something'] as the text node of the label element, but because they are defined dynamically, I just printed a general purpose error.
It's not a great solution, but you may be able to get away with it.
If someone comes across this using Kohana 3.2, the solution is, that you just add validation.php to messages folder and add your default values, for example:
return array(
'not_empty' => "Yo dawg, this field can't be empty!",
'[other rule]' => "[other message]",
);
You can look in to Kohana's source, and just copy the validation.php with default messages to your apps message folder and then just translate all of them.
I have successfully created new rules for the prototype validation, now I need to translate the error messages (Location: String in Javascript). However, I can only translate all the messages, my new custom ones don't appear to be translatable. How do I change this?
Maybe you need an jstranslator.xml file inside etc folder:
<?xml version="1.0" encoding="UTF-8"?>
<jstranslator>
<some-message-name translate="message" module="mymodule">
<message>This is the text in my own js validation</message>
</some-message-name>
</jstranslator>
With the following structure and meanings:
<jstranslator> - [one] XML root node.
<some-message-name> - [zero or more] root node child elements with a unique XML element name across all jstranslator.xml files (otherwise last in loading order based on module listing wins).
Attributes:
translate="message" - (optional) a hint that the child element(s) that is being translated is named "message", however this is hardencoded for the js translation XML files (Magento CE 1.9, search for "*/message") and this attribute does not need to be used.
module="mymodule" - (optional) name of the module, if left out the value is "core". It will be used to instantiate the data-helper later on (from that module) which then is reponsible to load the translations (e.g. from the CSV files).
<message> - [zero or one per parent] message to translate. the text value of this elements node-value is taken to be added to the javascript Translator object data.
All jstranslator.xml files of activated modules are processed.
Then put your translation line into the Something_Mymodule.csv file:
"This is the text in my own js validation", "(translated in a different language or speech)"
Then in your js scripts you can use your own translations via the Translator:
Translator.translate('This is the text in my own js validation');
Further References
Correct usage of jstranslator.xml
To translate custom javascript error messages you need also to add them to the following file:
\app\code\core\Mage\Core\Helper\Js.php
find a function _getTranslateData()
and you'll see a bunch of messages already in there.
just add your message somewhere in the array like this:
'This is my validation message' => $this->__('This is my validation message')
Don't forget a comma (,).
And then put translation in some translate file.
In the file where you use this message (I use it in opcheckout.js file) you need to wrap text in Translator.translate('This is my validation message').
I haven't figured out yet if it's important which translate file that is. You can try Mage_Core.csv .
I needed it in Mage_Checkout.csv and it works in there.
Anyway, for those who are interested in more, I noticed that these javascript messages are printed in header of every html page and some worrie that it messes with the SEO. Anyway this is printed in file
\app\design\frontend\bmled\default\template\page\html\head.phtml with the code.
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
Check for more here:
I hope this helps, I just hope this works everywhere, so far I tested it on Onepage Checkout only.
You can edit app/local/ur_language/Mage_Core.csv file, adding original string in the first Column the translated one in the second. All the javascript translations are stored in this file.
What's helped me (Magento EE 1.6) -
I added new translation object:
<script>
var _data = {
'This is a required field.':
"<?php echo $this->__('This is a required field.'); ?>",
'Please make sure your passwords match.':
"<?php echo $this->__('Please make sure your passwords match');?>",
'validate telephone error':
"<?php echo $this->__('validate telephone error');?>"
};
var Translator = new Translate(_data);
</script>
if it is defined VarienForm uses it in js validation
We had exactly the same problem with one of our magento projects. We found that the function in app/design/frontend/default/default/template/page/htmlhead.phtml had been commented out:
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
After putting this in, it still did not work, because translations had not been inserted into translate file. Check out those two things and it should start working.
To expand on this, you must add the translation strings to Mage/Core/Helper/Js.php.