SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    In Cyber Space!
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can someone help with this JS and Form?

    Hi,

    In the following code, It's a modified version of PHPRecommend from Snipe.net, I'm trying to get rollover submit and reset buttons. Everything seems to work fine except when either button is clicked. Nothing is submitted when the submit button is clicked and the form isn't reset when the reset button is clicked. However the rollovers and everything else is working fine. Can some point out why neither of them are working? I'll post my code and the orginal code!

    Modified Code:
    PHP Code:
    <?php
    // Change the variable below to "no" if you do not wish to write 
    // the data to a text log
    $logging="yes";

    // Enter the website administrators email address here 
    $adminaddress "webmaster@domain.com"

    // Enter the company name or site name here 
    $sitename "domain.com"

    // Enter the address of your website here 
    $siteaddress ="http://www.domain.com"

    // Path to your header information if using a template layout.
    // If NOT, comment out this line!
    // include "/your/path/info/layout/header.php";
    ?>



    <?php
    IF ($action=="") {

    $referer getenv("HTTP_REFERER");  
    print 
    "<p><B>$referer</B><BR><BR></p>"
    ?> 

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>HotBodsUSA</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    //-->
    </script>
    <style type="text/css">
    <!--
    p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10 px; color: #000000; text-decoration: none;}
    input { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10 px; color: #438CCA; text-decoration: none; background-color: #DEDEDE; border-color: #438CCA #438CCA #438CCA; border-style: dashed; border-top-width: 1 px; border-right-width: 1 px; border-bottom-width:  1 px; border-left-width: 1 px}
    textarea { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10 px; color: #438CCA; text-decoration: none; background-color: #DEDEDE; border-color: #438CCA #438CCA #438CCA; border-style: dashed; border-top-width: 1 px; border-right-width: 1 px; border-bottom-width:  1 px; border-left-width: 1 px}
    --> 
    </style>
    </head>

    <body onLoad="MM_preloadImages('images/interface/but_submit_02.jpg','images/interface/but_reset_02.jpg')" background="images/interface/fill.jpg" topmargin="0" bottommargin="0">

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>
    <form method="post" action="<? echo "$PHP_SELF"?>" name="taf">
    <table width="100%" border="0" cellspacing="0" cellpadding="8">
      <tr>
        <td colspan="2"><p>Cute message here!</p></td>
      </tr>
      <tr>
        <td width="175"><p>Your Name:</p></td>
        <td><input name="yname" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Your Email Address:</p></td>
        <td><input name="yemail" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #1 Name:</p></td>
        <td><input name="fname[1]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #1 Email Address:</p></td>
        <td><input name="femail[1]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #2 Name:</p></td>
        <td><input name="fname[2]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #2 Email Address:</p></td>
        <td><input name="femail[2]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #3 Name:</p></td>
        <td><input name="fname[3]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #3 Email Address:</p></td>
        <td><input name="femail[3]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #4 Name:</p></td>
        <td><input name="fname[4]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td width="175"><p>Friend #4 Email Address:</p></td>
        <td><input name="femail[4]" type="text" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></td>
      </tr>
      <tr>
        <td colspan="2"><p>Additional Comments:</p></td>
      </tr>
      <tr>
        <td colspan="2"><textarea name="comments" cols="58" rows="5" wrap="virtual" onblur="style.backgroundColor='#DEDEDE'" onfocus="style.backgroundColor='#FFFFFF'"></textarea>
        <input type="hidden" name="url" value="<? echo "$referer"?>">
        <br><br>

    <a href="#" OnClick="javascript:document.taf.submit()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('submit','','images/interface/but_submit_02.jpg',1)"><img src="images/interface/but_submit.jpg" alt="Search" name="submit" width="53" height="14" border="0" align="middle"></a>
    <a href="#" OnClick="javascript:document.taf.reset()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('reset','','images/interface/but_reset_02.jpg',1)"><img src="images/interface/but_reset.jpg" alt="Search" name="reset" width="53" height="14" border="0" align="middle"></a>

        </td>
      </tr>
    </table>
    </form>
        </td>
      </tr>
    </table>


    <?php

    } ELSEIF ($action="Send") { 

        if ((
    $yname=="") || ($fname=="")  || ($femail=="")|| ($yemail==""))  {
    print 
    "Please use your back button and complete all of the required form fields, then resubmit.<br><br><br><br><br><br><br><br><br><br><br>";
    } else {
            print 
    "Your recmmendation to the following people has been sent:<br><br> ";
                
    // cycle through the emal addresses and names
            
    $items="5";
            
    $tally="";
            for (
    $numitems=0$numitems $items$numitems++) {
                  if ((
    $fname[$numitems]!="") && ($femail[$numitems]!=""))  {
                    
    mail("$femail[$numitems]","$yname went to $sitename and recommended you check this out","$fname[$numitems] \n\n $yname stopped by $sitename and thought you would find the following URL of interest:\n \nURL: $url \n\n Additional Comments: \n------------------------------------ \n$comments \n------------------------------------\n\nThank you! \n$sitename \n$adminaddress \n$siteaddress","FROM:$yemail"); 

                    
                    IF (
    $logging=="yes") {
                    
    $filename="url-log.txt"

                    
    // Nothing needs ot be changed here

                    
    $fl=fopen($filename,"a+"); 
                    
    // sets the pipe delimiters
                    
    fwrite($fl,"'$url'|'$femail[$numitems]'|'$yemail'|'$comments'\n"); 
                    
    fclose($fl); 
                    }
                  
    $tally.="$fname[$numitems], ";
                  }
             }

    ?> 
    <P>Your recommendation has been sent to <?php echo "$tally"?> </p>

        <p><B><A HREF="<? echo "$url"?>">GO BACK</A></B> </p>
        <BR> 
        <BR> 
    <?php 
    }

    }

    // Path to your footer information if using a template layout.
    // If NOT, comment out this line!
    // include("/your/path/info/layout/footer.php");
    ?>

    Orginal Code:
    PHP Code:
    <?  
    /************* PHPRecommend v 1.3 ***************/ 
    /************************************************/ 
    /*  written by A. Gianotto - 3/28/2000          */ 
    /*  To find out if this is the latest version   */ 
    /*  of this script, email [email]snipe@snipe.net[/email], or   */ 
    /*  visit [url]http://www.snipe.net[/url]                  */ 
    /************************************************/ 
    /************************************************/ 
    /*  PHPRecommend may be used freely for private */ 
    /*  or commercial use.  All I ask is that you   */ 
    /*  don't include it in any collections without */ 
    /*  my permission.                              */ 
    /************************************************/ 
    /************************************************/ 
    /*  DESCRIPTION:                                */ 
    /* PHP "Recommend this page to a friend" script */ 
    /*                                              */ 
    /************************************************/ 
    /************************************************/
    /* NEW IN VERSION 1.3 - Multiple Email Address Support*/
    /* ADDED 6/12/01                                */
    /*   
    /************************************************/ 
    /************************************************/
    /* URL LOGGING: 
    /* If you wish to use this feature, the only    */
    /* additional step you must take is to upload   */
    /* a blank text file into the same directory as */
    /* this script lives.  For our purposes, we     */
    /* have named it "url-log.txt".  You may name   */
    /* it whatever you like, but if you change the  */
    /* name, be sure to change it in the variable   */
    /* below, where it's marked                     */
    /*                                              */
    /* Also BE SURE TO CHMOD THE TEXT FILE TO 666   */
    /* so that the sever can open the file and      */
    /* write to it.                                 */
    /* ENJOY!                                       */
    /************************************************/ 
    /************************************************/ 
    /*  INSTALLATION:                               */ 
    /*  There is no readme or install file with     */ 
    /*  script, because it's so easy to install,    */ 
    /*  you just have to follow the comments in the */ 
    /*  first part of the code                      */ 
    /************************************************/ 
    /************************************************/ 

    // Change the variable below to "no" if you do not wish to write 
    // the data to a text log
    $logging="yes";

    // Enter the website administrators email address here 
    $adminaddress "you@yoursite.com"

    // Enter the company name or site name here 
    $sitename "yoursite.com"

    // Enter the address of your website here 
    $siteaddress ="http://www.yoursite.com"


    // Unless you are changing the verbage of the printed message, 
    // there are no further configurations that need to be done  
    // past this point, except editing the path to your footer includes 

    // If you do not use header and footer files, you can just replace 
    // the include calls with your HTML, but be sure to close the PHP tags 
    // before and after the HTML, so you don't get parse errors.

    ?>
    <html>
    <head>
    <title>yoursite.com - Tell A Friend</title>


    <?php
    // OR if you're using include files for layout....
    include "/your/path/info/layout/header.php";
    ?>

    <?php
    IF ($action=="") {
    ?> 

    <? 
    $referer 
    getenv("HTTP_REFERER");  
    print 
    "<p><B>$referer</B><BR><BR></p>"

    ?> 
    <p>To send the URL of this page and a brief message to friends who might like it, just fill out the  
    form below. 
    <BR> 
    <BR><B>NOTE:</B>  We only request your name and email address so that the person you  
    are recommending the page to knows that you wanted them to see it, and that it is not junk  
    mail.  All fields marked with an asterisk (*) are required.  You must enter at least one friend's name and email.</p>
    <BR><FORM METHOD=POST ACTION="<? echo "$PHP_SELF"?>"> 

    <TABLE BORDER="0" CELLSPACING="3" CELLPADDING="3"> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Your Name*:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="yname"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Your Email*:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="yemail"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #1 Name*:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="fname[1]"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #1 Email*:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="femail[1]"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #2 Name:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="fname[2]"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #2 Email:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="femail[2]"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #3 Name:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="fname[3]"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #3 Email:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="femail[3]"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #4 Name:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="fname[4]"></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="- 
    1">Friend #4 Email:</FONT></TD> 
        <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
    SIZE="3"><INPUT TYPE="text" NAME="femail[4]"></FONT></TD> 
    </TR> 

    <TR> 
        <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
    Serif" SIZE="-1">Additional Comments:</FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
    Serif" SIZE="3"><textarea NAME="comments" rows="3"></TEXTAREA></FONT></TD> 
    </TR> 
    <TR> 
        <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
    Serif" SIZE="3"><INPUT TYPE="hidden" NAME="url" VALUE="<? echo "$referer"?>"><INPUT  
    TYPE="submit" NAME="action" VALUE="Send"></FONT></TD> 
    </TR> 
    </TABLE> 

    </FORM> 
        <BR> 
        <BR> 
        <BR> 
        <BR> 
        <BR> 


    <? 

    } ELSEIF ($action="Send") { 

        if ((
    $yname=="") || ($fname=="")  || ($femail=="")|| ($yemail==""))  {
    print 
    "Please use your back button and complete all of the required form fields, then resubmit.<br><br><br><br><br><br><br><br><br><br><br>";
    } else {
            print 
    "Your recmmendation to the following people has been sent:<br><br> ";
                
    // cycle through the emal addresses and names
            
    $items="5";
            
    $tally="";
            for (
    $numitems=0$numitems $items$numitems++) {
                  if ((
    $fname[$numitems]!="") && ($femail[$numitems]!=""))  {
                    
    mail("$femail[$numitems]","$yname went to $sitename and recommended you check this out","$fname[$numitems] \n\n $yname stopped by $sitename and thought you would find the following URL of interest:\n \nURL: $url \n\n Additional Comments: \n------------------------------------ \n$comments \n------------------------------------\n\nThank you! \n$sitename \n$adminaddress \n$siteaddress","FROM:$yemail"); 


                
    // NEW IN VERSION 1.2 - LOGGING TO A TEXT FILE - 7/31/00
                // this writes the url, comments, and email address
                // to a text database so you can easily track which 
                // pages are being recommended most often

                // Be sure to upload the blank text file that the 
                // data will write to.  In this case, we named it url-log.txt
                // If you name your blank file url-log.txt, no changes are needed here.
                // If you decide to use a different filename, you must change the 
                // variable below.
                    
                    
    IF ($logging=="yes") {
                    
    $filename="url-log.txt"

                    
    // Nothing needs ot be changed here

                    
    $fl=fopen($filename,"a+"); 
                    
    // sets the pipe delimiters
                    
    fwrite($fl,"'$url'|'$femail[$numitems]'|'$yemail'|'$comments'\n"); 
                    
    fclose($fl); 
                    }
                  
    $tally.="$fname[$numitems], ";
                  }
             }

    ?> 
    <P>Your recommendation has been sent to <?php echo "$tally"?> </p>

        <p><B><A HREF="<? echo "$url"?>">GO BACK</A></B> </p>
        <BR> 
        <BR> 
    <? 
    }

    }

        
    // change this pathname to point to your footer file
        
    include("/your/path/info/layout/footer.php"); 



    // end of script 

    // ********************************************* 
    // Making it work on your page: 
    // Just put a link to phprecommend.php (or whatever you name 
    // the above file), and the script  
    // does the rest! 

    ?>
    Thanks for the help!

  2. #2
    Bangarang! Karloff's Avatar
    Join Date
    Mar 2003
    Location
    Manchester, United Kingdom
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just move the submit and reset <a /> statement outside of your form block, thus, right after the </form> and it should work fine (p.s. you dont need to declare javascript: in an onclick property).

    Alternatively you could replace the <a /> submit and reset buttons with something like <input onclick="document.taf.submit()" type="image" src="images/interface/but_submit.jpg" width="53" height="14" /> and have them within the form block.

    Haven't tried either out, but I am pretty sure both should work.

    Good luck and happy coding,
    Karl


    I'm desperately trying to figure out why Kamikaze pilots wore helmets. - George Carlin

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    In Cyber Space!
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out! The orginal script wanted action=send with the send button. I figured out if I did a hidden field <INPUT TYPE="hidden" NAME="action" VALUE="send"> with what I had it would work. and it worked

    Thanks for the help!

  4. #4
    Bangarang! Karloff's Avatar
    Join Date
    Mar 2003
    Location
    Manchester, United Kingdom
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh well, as long as it works fine. I didn't look at the PHP as my eyes are set to automatically skip it
    Karl


    I'm desperately trying to figure out why Kamikaze pilots wore helmets. - George Carlin


Bookmarks

Posting Permissions

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