Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 44
  1. #16
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    lol i feel like a doofus, i work on this all the time and have used js in the header before or called it there i mean, and yet that never occured to me to put this in the head section.. omg too funny,, its like forgetting how to walk lol.... maybe i have been pushing myself too hard...

    Yes that should work to put the call to the js in the head section and do it that way. thanks so much for you time.. I am red in the face... .

    Thanks for being patient. I guess i had my head in a box and was totally blinded lol

  2. #17
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    Now that my eyes are open ill build a js file to do the error control results and that should work perfect. thanks again. Ill hit you up if i have a question or ill post the code i come up with.

  3. #18
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by durangod View Post
    the closest is document.write that thats still js.
    That's long dead JavaScript - you should never use document.write in JavaScript any more.

    Simply code what you want to have appear as the alert using ordinaryu HTML and have it hidden. Then use JavaScript to change it from hidden to visible.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  4. Users who have thanked felgall for this post:

    durangod (07-08-2013)

  5. #19
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,678
    Thanks
    80
    Thanked 4,646 Times in 4,608 Posts
    Quote Originally Posted by durangod View Post
    Also dont you have to have a document to do

    Code:
    document.referrer;
    what i mean is that if someone accesses my php file directly and no form post then there technically is no document, correct?
    Incorrect.

    There is *ALWAYS* a document. The <html>...</html> tags create the document.

    There is no referrer in that case. But there's always a document.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  6. Users who have thanked Old Pedant for this post:

    durangod (07-08-2013)

  7. #20
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    so here is the end part of my php process for the mp3 upload.. what i did was i took out all the var settings text wize in the php and just used a number and then used the switch to set the value.. then send to js..

    here is the end of the php process.

    Code:
    // there are a a bunch more case's above this, this just gives you and idea of the configuration of it. 
    
      default:
                  $outmessg = "Upload was NOT completed! There may be a system issue or a file issue! Please contact support";
                  $outaction = '9';
          break;
    		
      }//close switch   
    
    ?>
    
    
    <script type="text/javascript">
    
    var sendaction = "<?php echo $outaction ?>";
    var sendmsg = "<?php echo $outmessg ?>";
    
    getresults(sendaction, sendmsg);
    
    </script>
    and then that function is in the js file here

    Code:
    /* this file processes the output to the user from the results of the upload process in the php file */
    
    
    function getresults(action, msg)
    {
    //action is #
    //msg is msg
    var refr = document.referrer;
    var gog = "http://www.google.com";
    var resact = action.value;
    var resmsg = msg.value;
    
    if(resact == 8)
    {
    // completed positive
    alert('Confirmation: ' + resmsg);
    window.location.href = refr;
    }elseif(resact == 0)
      {
       //direct access to php attempted no form post
       alert('Error: ' + resmsg);
       window.location.href = gog;
      }else{
           //everything else is some issue
           alert('Error: ' + resmsg);
           window.location.href = refr;
           }//close else
    
    }//close function getresults

    and then i use the header option in admin of oxwall to add the js file

    Code:
    <script type="text/javascript" src="/mymp3player/mp3results.js"></script>
    So the page loads
    it loads mp3results.js so we can use it
    then i do the upload
    it runs thru the php
    then hits the switch
    the goes to the function
    and it should pop the message

    if no form post it shoot off the message then takes them to google

    does that seem correct process.
    Last edited by durangod; 07-08-2013 at 12:52 AM. Reason: fixed mistake in my js

  8. #21
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,678
    Thanks
    80
    Thanked 4,646 Times in 4,608 Posts
    I think I want to see it live.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  9. #22
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    ok let me put the old php file back so you can check it out and ill shoot you the login info in pm..

  10. #23
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    pm sent

    sorry forgot to say its M on the menu and then upload an mp3

  11. #24
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,678
    Thanks
    80
    Thanked 4,646 Times in 4,608 Posts
    But that's not a popup. It's just an alert().

    Which you should never use for production coding, in any case.

    You need to reorganize this, completely.

    Somebody suggested you could use a query string. That's not a bad idea:
    Code:
    if ( resact == 0) {
       //direct access to php attempted no form post
       window.location.href = gog;
    }
    
    window.location.href = refr + "?msg=" 
        + encodeURIComponent(  ( ( resact == 8 ) ? "Confirmation: " : "Error: " ) + resmsg );
    And then, on the page that refr sends the person back to, you look at the querystring and post the message as an HTML popon, *NOT* using alert().

    If there are too many possible pages that document.referrer could be sending the person back to, then maybe the best solution is an INTERMEDIATE page:
    [code]
    Code:
    if ( resact == 0) {
       //direct access to php attempted no form post
       window.location.href = gog;
    }
    
    window.location.href = "messagePage.php?ref=" + encodeURIComponent(refr)
        + "&msg=" 
        + encodeURIComponent(  ( ( resact == 8 ) ? "Confirmation: " : "Error: " ) + resmsg );
    And then messagePage.php shows the message and, after a pause or upon some user action, then continues on to the original http.referrer.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  12. Users who have thanked Old Pedant for this post:

    durangod (07-08-2013)

  13. #25
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    thanks for that.. im assuming when you say HTML popon you mean just open a smaller window as in window.open rather than an alert(), thats easy enough to do..

    omg now i have to go back to all my old scripts and remove all those alerts hee hee.. my bad... Really the only reason i started using alerts in the first place is one if my first scripts i worked on in early php4 used them all over the place and i just never stopped lol.

    thanks for you help nice job

  14. #26
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,678
    Thanks
    80
    Thanked 4,646 Times in 4,608 Posts
    Quote Originally Posted by durangod View Post
    im assuming when you say HTML popon you mean just open a smaller window as in window.open rather than an alert(), thats easy enough to do..
    No. Not at all.

    Try to AVOID using window.open! Some aggressive popup blockers can and will block those.

    Instead, you use what I call a "popon", which is just a <div> that is positioned on top of all other content. Some call it a "modal dialog" but I avoid that term because MSIE (only) has it's own modal dialog control, and you don't want to use that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  15. #27
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    Ok thanks...

    Is it ok instead of the query string to use an auto submit form, i feel the post is more secure than the string and the
    code for the form is easier for me to understand and worth with JS wise..
    I know you secured the string with encode but do you still prefer that or is the auto submit form just as good


    Code:
    <!-- auto submit form to post results of upload--> 
    
                                 <html>
                                   <head>
                                    </head>
                                     <body>
                                       <form name="upresfrm" method="POST" action="processmsg.php"> 
                                        <input type="hidden" name="outmes" value="<?php echo $outmessg; ?>" />
                                        <input type="hidden" name="outact" value="<?php echo $outaction; ?>" />
                                       </form>
    
                                       <script type="text/javascript">
                                       <!--
                                       function resnotify()
                                       {
                                         document.upresfrm.submit();
                                         }
                                       // -->
                                       </script>
    
                                       <script type="text/javascript">
                                       <!--
                                       resnotify();
                                       //  -->
                                       </script> 
                                    </body>
                                </html>
    
    
    
    <!-- done -->

    Also and now i have an empty div sitting on the page.
    now in the processmsg.php grap the past and formulate the final output and then send the message and referrer value to the js function below which
    this js file has been added to the header so the function should not be available to call. It fills in the div and also sends executes the referrer.




    // i hope i did this function correct, i know i can do this with ajax easily enough i was just trying to save some keystrokes.

    // f stands for final so this is the final msg that will be in the div as well as the final location sent.
    function showinfo(fmsg,fref)
    {
    document.getElementById('showmsg').innerHTML.fmsg.value;
    window.location.href = fref;
    }//close function showinfo
    Last edited by durangod; 07-08-2013 at 10:08 PM.

  16. #28
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,678
    Thanks
    80
    Thanked 4,646 Times in 4,608 Posts
    <shrug>Or cookies. Or session values in PHP code. Mechanism isn't important. Important part is to avoid the blank screen, as you said.

    Quite frankly, I don't even know why you are doing any of this in HTML/JavaScript instead of all in PHP code. That would make it all more secure, etc.

    I mean, the page that receives the uploaded file is a PHP page, of course. So why not just do it all in PHP, starting from there?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  17. #29
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    I agree with you totally, the main reason is that the page you see is added thru the admin page add, it is not an actual page as in page.php/html that i can edit (and i dont want to do that anyway because when an update comes out i will lose my edits) it is simply a parsed rendition of what i add in the content section of the page add. Think of it as a textarea that you can add html and a call to a js file in the header which produces the page display.

    Most people do a plugin but that entails hooks, libraries and for me is way too time consuming for such a simple task.

    So i used the add page, tossed in an iframe for the mp3 display and then included my form on the bottom.


    so it seems my option is to pass that value from php to js in order to fill that empty div..

    I have an ajax that i built a while back, well you all helped with it, its totally redone and works, and i could just put the listener in and
    grab the value from the responseText but as i said i was hoping this would be a slam dunk deal lol...
    Last edited by durangod; 07-08-2013 at 10:59 PM.

  18. #30
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    I did manage to get the upload process (other than the html) into one php file. It is all working accept for the display. The redirect is working perfectly on testing, but no message is span (i changed it to a span with id)


    Code:
    in the html i have <span id="showmsg"> </span>


    here is the last part of my process.


    // up to this point i have correct data and all is well
    //if i just hit upload with no file chosen i get


    Error: No File Selected - you must select a file to upload

    /music
    that is the correct message $showmesg
    that is the correct redirect page name $gowhere

    but it is not displaying the message on the page inside the span after redirect.

    Code:
    if ($showmesg != '' && $gowhere != '')
    {
    
    ?>
    
    <script type="text/javascript">
    
    function showmessage()
    {
    var smsg = "<?php echo $showmesg; ?>";
    document.getElementById('showmsg').innerHTML = smsg;
    }//close function showmessage
    
    function redir()
    {
    var sref = "<?php echo $gowhere ?>";
    window.location.href = sref;
    }//close function redir
    
    
    redir();
    showmessage();
    
    // -->
    </script>
    
    <?php
     }//close if showmesg and gowhere
    exit;
    ?>
    Last edited by durangod; 07-09-2013 at 01:48 AM.


 
Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •