last day (15 days later) » 

5:47 AM
0
A: How to display custom error message in php?

Gul Jamal ZimThat's because __() returns the translated text, while _e() displays/echos it. And as you are inside sprintf() function, you need the returned translated text, not display it to the screen. _e() codex reference, __() codex reference Thanks.

 
Thank you for your reply. So what would be the solution? Using $file['error'] = sprintf( __( 'ERROR: File size limit is %d KB.' ), $file_size_limit ); doesn't return an error message....
 
Just keep using the __() function. What's wrong with it?
 
It would be fine, only the error message isn't returned - I cannot see it... ?
 
It's showing the error for me. By any chance, are you logged in as an admin user?
 
do I need to specify some kind of specific <div> on my page to be able to return the error message? (sorry I'm quite a newbie to php)
no I am testing as non-admin
 
5:47 AM
It's working as it should be for me. imgur.com/isOjUds. I am testing this from the media uploader page in the backend. Where are you testing it from?
 
I have a frontend uploader for users, maybe that is the reason. Is there a way to just echo the error message instead (if it will solve the issue)
 
Can you paste the frontcode you are using here?
 
sure, here it is:
<?php
global $post, $hide_fields, $homey_local;
$layout_order = homey_option('listing_form_sections');
$layout_order = $layout_order['enabled'];
$i = 0;
$style = 'visibility: hidden; height: 0;';
if ($layout_order) {
foreach ($layout_order as $key=>$value) {
$i++;
if($i == 2 && $key == 'media') {
$style = 'visibility: visible;';
}
}
}
?>
<div class="form-step form-step-gal1" style="<?php echo esc_attr($style); ?>">
<!--step information-->
<div class="block">
<div class="block-title">
<div class="block-left">
(thanks so much for helping out - really appreciate it!!)
 
Which php file is this code section in?
 
it is a separate template
the code for the file size limit I put in my functions file
so basically, the above code is for a page template for frontend users
should I be adding the size limit code into this template instead?
 
5:55 AM
No. The size llimit code should be added to the functions.php file as it's a filter.

I haven't worked on this type of problem before. So, I am searching for a solution online. I will let you know if I find anything.
 
thank you so much!!!
I wouldn't even know what to search for.
 
Sure. No problem at all.
 
:)
 
yes, correct
 
6:16 AM
I need a bit more information.

I have checked their documentation(http://help.gethomey.io/) and found nothing similar to the code you are using. So, in which file have you added the code section you pasted?
 
that is their code, i.e. in the theme itself - I haven't customised it.
I'm just trying to limit the file size limit of uploads for frontend users
To give you some background info: this theme has a frontend dashboard for users and they add properties through it. In their frontend user dashboard, they are also able to add images, which is where the above code appears for that page
 
I understand.

To show the error in front end, the theme code must decide that if it wants to show the error or not. Just for example, WordPress itself catches the error and shows it as a notice on the backend.
So, if homey developers didn't add the error showing code for the fronted pages
you can't show that directly from the filter
 
right
so there is no way around it, as you can see
?
 
I am seeing that there's a div for showing errors on the code section you sent. <div id="homey_errors"></div>
 
I was just about to mention this :)
 
6:28 AM
But to find how to use that, I will have to go through their theme code.
 
aa right
so it will be somewhere in their theme code
 
As they didn't write anything about that in their documentation
 
yes
 
What you can do is search for their whole theme for this function - homey_option()
 
this might be way off but is it at all possible to create an "output" with the error message from functions directly? or do these elements always have to be specified in the theme template files?
 
6:30 AM
I am guessing you can find the error related function there
 
yes
would I need to add another error to that function?
 
I am really not sure how they wrote their code to show the errors.
Only after checking the code I can tell you what to do.
I am sorry. :(
 
not a problem, I really appreciate you trying to help!!
 
Try yourself finding the upload code in their theme first.
 
although I'm still confused about how the error "Error #-200: HTTP Error." was showing when I modified the code
@GulJamalZim ok, sure
 
6:34 AM
So that means they have a code to handle these errors
 
right
 
You just have to find the function where they are showing that error
 
one more question - would you know where that string would be located? "Error #-200: HTTP Error."
is this a default wordpress string?
 
This might be coming directly from the WordPress
so, searching for that might not help you
 
ok
thanks again for your help and guidance, I will research it a little more and see if I can come up with anything :)
have a great day!! :D
 
6:36 AM
It's ok. :)
Hope you can find a solution.
 
thank you :))
 

last day (15 days later) »