Search the Community
Showing results for tags 'inside'.
-
I have included language file and function file in my index.php include 'includes/functions.php'; include 'languages/english.php'; english.php contains <?php $lang['success']['a'] = 'Settings have been updated.'; $lang['error']['b'] = 'Database error. Please try again later!'; ................................. ?> functions.php <?php function testFunction($id, $settings, $db){ $query = 'UPDATE table_name SET a = a + :a WHERE id = :id'; $update = $db->prepare($query); $update->bindParam(':a', $settings['a'], PDO::PARAM_INT); $update->bindParam(':id', $id, PDO::PARAM_INT); $success = $update->execute(); if($success){ print $lang['success']['a']; }else{ print $lang['error']['b']; } } ................................................. ?> Now if i print testFunction(); i got Undefined variable: lang in ............. If i include 'languages/english.php'; in testFunction() then everything works. Any other way to make $lang working without including language file in testFunction(). (Sorry for my bad english) print testfunction(2, $settings, $db);
-
Hello, I'm here with a question that maybe silly for most of you but I just can't handle it. As I know, there's no way in built in PHP inside JS because diferent kind of languages ( Server Side and Client Side ). But I have a problem that I need help to handle. I have a multilanguage system in my site ( PHP ) and form validations ( JS ). I have the error messages showed by JS instantly, but I can only print text, not a PHP variable info. For example: $(function() { // validate signup form on keyup and submit $("#loginform").validate({ rules: { user: "required", password: "required", }, messages: { user: "Please enter your username or email.", password: "Please enter your password", } }); }); And my multilanguage system uses the following system: $lang['login_error'] = 'Incorrect details provided.'; There is any way to make something like this: $(function() { // validate signup form on keyup and submit $("#loginform").validate({ rules: { user: "required", password: "required", }, messages: { user: <?php echo $lang[login_error']; ?>, password: "Please enter your password", } }); }); I know this doesn't work, but it's to make an easy example in what I need, because depending the language the user as choosen, the error should be there in that language, not only in one language. Could you please help me to handle this ? Thanks in advance.
- 5 replies
-
- php
- javascript
-
(and 3 more)
Tagged with: