MarioApprentice Posted May 12, 2013 Share Posted May 12, 2013 Hello everybody! I'm writing an application that, among other things, allows users to send messages to admin of the page. Then, admin access it trough their CMS. After they successfully send the message, a window saying that the message was sent successfully has to appear. After clicking on OK, the message fades out with JQuery. This is the code of the message <input type='hidden' class='hidden-elem' value='<?php if(isset($_SESSION['prikaz'])) { echo 'prijava'; unset($_SESSION['prikaz']); } ?>'> <div class='prijava'> <div class='welcome'> <?php if(isset($_SESSION['poslana'])) { ?> <p class='uspjeh'>Vaša poruka je uspješno poslana</p> <p><span>Sa poštovanjem,</span><span>Tim Cvjećarnice Oliva.</span></p> <img src='images/ikone/success.png' class='ukras'> <?php unset($_SESSION['poslana']); } elseif(isset($_SESSION['dobrodoslica'])) { ?> <h1>Dobrodošlao/la na stranicu <span>Cvjećarnice Oliva</span></h1> <p>Na ovoj stranici možete naći najbolji asortiman cvijeća i ukrasnih aranžmana u Osijeku. Ako vas zanima nešto više o pojedinom cvijetu koji vam se sviđa, za vas smo pripremili i članke, koji na zanimljiv način opisuju i govore o cvijeću. Nadamo se da ste zadovoljni. Također, možete nas osobno posjetiti na našoj adresi, Vjenceslava Hodaka 16, Osijek. Veselimo se budućem susretu! <span>Sa poštovanjem,</span><span>Tim Cvjećarnice Oliva.</span> </p> <img src='images/dekoracija.png' class='ukras'> <?php unset($_SESSION['dobrodoslica']); } elseif(isset($_SESSION['fail'])) { ?> <p class='fail'>Došlo je do pogreške. Ispričavamo se na neugodnosti i molimo da, nakona nekog vremena ponovno pokušate. Hvala vam na strpljenju.</p> <p><span>Sa poštovanjem,</span><span>Tim Cvjećarnice Oliva.</span></p> <img src='images/ikone/close.png' class='ukras'> <?php unset($_SESSION['fail']); } ?> <button>Ok</button> </div> <?php ?> </div> The language is croatian and the content is irrelevant. The main thing is, if $_SESSION['prikaz'] is set, then the value of the hidden field is populated with the string 'prijava'. The $_SESSION['prikaz'] gets populated in antoher script and he isn't the problem beacuse, he is set every time and in every situation. That input field is important for the JQuery code that follows... $('.prijava').hide(); var tip = $('.hidden-elem').attr('value'); if(tip == 'prijava') { $('.prijava').show(); $('.prijava .welcome button').click(function() { $('.prijava').fadeOut(500); }); } JQuery then takes the value of the value attribute of .hidden-elem and checks if its equal to 'prijava'. If it is, then it shows the <div class='prijava'>. The problem is this. When the user is logged in, the messages shows with no problem. But when the user is not logged in, the message does not show, but it gets proccessed with inline style='display:none'. The value of the .hidden-elem is populated with the string 'prijava' but $('hidden-elem').attr('value') doesn't return the value of that hidden input element, thus if(tip == 'prijava') doesn't evaluate to true. I don't understand how can one behaviour be valid for, when the user is logged in and when he isn't if the script is operating with identical data in both cases? I know this is a long post and I thank anyone who tries to solve it. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 I think you are destroyed your session somewhere in your script or you're setting a global $_SESSION to unset() or to NULL, when the user is not logged in or you don't set a session_start() on the template with the code above. Quote Link to comment Share on other sites More sharing options...
MarioApprentice Posted May 12, 2013 Author Share Posted May 12, 2013 it's not the session. the sessions are fine. all of them. jquery is not getting the value 'prijava' from the hidden input field when the user is not logged in. when the user is logged in, its all fine. but the sessions all work and are all set. the main question is, the code shown above is executing in the SAME form when the user is logged in and when he's logged out but its producing different results. i tried using the val() function but doesn't work. i've tried displacing the <script> tags to the end of the <body> element but nothing works. 'view source' shows that the right element is there, and that the hidden input element has the value of 'prijava' but JQuery is not picking it out. I'm sorry if this is a jquery question. i didn't know that when i was posting the question. if this post is to be erased, its cool. i'll look for the answer elsewhere. thank for your answer. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 Alright then, can you var_dump($_SESSION) array when the user is logged in and logged out, please. Quote Link to comment Share on other sites More sharing options...
MarioApprentice Posted May 12, 2013 Author Share Posted May 12, 2013 whell i can, but none of the session values are relevant to this example. the $_SESSION['prikaz'] only use is to put the string 'prijava' into the hidden input field. That field is a bridge of communication between jquery and php. 'prijava' is then used to show() the <div class='prijava'> with some message. but if you want it, here it is... This is logged in... array(2) { ["tablica"]=> string( "naslovna" ["korisnik"]=> object(Member)#1 (1) { ["fields":protected]=> array(4) { ["ime"]=> string(5) "Mario" ["prezime"]=> string(7) "legenda" ["pass"]=> string(0) "" ["mail"]=> string(24) "maslec.krlec10@gmail.com" } } } here are two values, 'korisnik', which holds the main data of the user like his name, surname, mail and so on and 'tablica' which does some other work that has nothing to do with this problem. This is the session when the user is not logged in... array(1) { ["tablica"]=> string( "naslovna" } The only difference is Member object when the user is logged in but that has nothing to do with this problem. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 You must re-design the script, your all SESSION is not set to this part of the script when the user is logged out. Quote Link to comment Share on other sites More sharing options...
MarioApprentice Posted May 12, 2013 Author Share Posted May 12, 2013 the only SESSION that is relevant for this problem is the $_SESSION['prikaz']. <input type='hidden' class='hidden-elem' value='<?php if(isset($_SESSION['prikaz'])) { echo 'prijava'; unset($_SESSION['prikaz']); } ?>'> and that session is set in both ways, logged in or logged out. i've checked it in both logged in and logged out. it's set and it works. i think that php has nothing to do with this but jquery, i don't know. but it's not php. thanks for you help. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 (edited) Two more things I wanna do for me. 1. You were put down var_dump in a wrong place, I want to put it on top of the page (after session_start()) assuming you have already started a session_start(), right? 2. If you're on firefox and use firebug could you give us the result of var tip = $('.hidden-elem').attr('value'); console.log(tip or alert (tip) when the user is logged in - logged out. Edited May 12, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
MarioApprentice Posted May 12, 2013 Author Share Posted May 12, 2013 (edited) ok. before login. array(1) { ["tablica"]=> string( "naslovna" } after liogin array(4) { ["tablica"]=> string( "naslovna" ["korisnik"]=> object(Member)#1 (1) { ["fields":protected]=> array(4) { ["ime"]=> string(5) "Mario" ["prezime"]=> string(7) "legenda" ["pass"]=> string(0) "" ["mail"]=> string(24) "maslec.krlec10@gmail.com" } } ["prikaz"]=> string(0) "" ["dobrodoslica"]=> string(0) "" } SESSION['prikaz'] gets set when i want to show the <div class='prijava'>. The actual message of that element depends wether i'm sending a message, logging in ($_SESSION['dobrodoslica'] sets the welcome text) or, there is an error in the application. but SESSION['prikaz'] is only for setting the value of <input> to 'prijava'. When the user is logged in, console.log(tip) has the string 'prijava' but when logged out doesn't. That is the main problem as i said above. if(tip == 'prijava') doesn't execute. Same conditions, different results. I inspected the html with firebug and all the neccessery elements are there. Hidden <input> field has the value of 'prijava'. Everything is the same being logged in or logged out. As i said in the first post, the application should display that the message has been sent successfully via the mechanism above. When the user is logged in, it shows the message. When not, it doesn't show the message. The message is saved on the database in both ways. Edited May 12, 2013 by MarioApprentice Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 Yes, I understand the issue, so it sounds you have a logical error(s) in the script. You need post everything relevant to that script. Quote Link to comment Share on other sites More sharing options...
MarioApprentice Posted May 12, 2013 Author Share Posted May 12, 2013 that is it. every relevant code is in the posts above. I've got nothing left. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 How do you define which SESSION where belons to? Where is the file that users sends their emails? Also, can you put it down error_reporting(-1) on top of that file. Quote Link to comment Share on other sites More sharing options...
MarioApprentice Posted May 12, 2013 Author Share Posted May 12, 2013 the file is a script that processes data like forms... it reacts only to submit <input> fields. The SESSIONS relevant for this are set on login and when the user sends messages. Like this: Login ->$_SESSION['prikaz']; ->$_SESSION['welcome']; ->$_SESSION['userDataObject']; sendMessage ->$_SESSION['prikaz'] ->$_SESSION['message_type'] -> error message -> success message error message and sucess message are just words like, 'you have sent your message sucessfully... there was an error'. What message is outputed is up to $_SESSION['welcome'] or $_SESSION['message_type']. They are not relevant and can't mess with anything logically. They just determine message output. But $_SESSION['prikaz'] echo'es the string 'prijava' into the value of the hidden input field. That script is not the problem. Its working just fine, since it only has to set the neccessesery SESSIONs and it does that. I don't think there is a way to solve this trough posts on forum. Thanks for your help and your time, but I'll try to solve this by my self. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.