SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Zealot Para's Avatar
    Join Date
    Mar 2005
    Location
    London UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Internet Explorer 'Error On Page' with my form submit function?

    Hi im having issues with a form submit function, its working perfect in Firefox, but IE is giving a 'Error On Page' in left hand corner and the form doesnt work.

    As i am a complete javascript novice its giving me a major headache.

    Here is the code, i trimmed it down a little as there was so many input fields

    Thankyou in advance for any input.

    PHP Code:
    <script language="javascript" type="text/javascript">
        function submitbutton(pressbutton) {
            var form = document.adminForm;
            if (pressbutton == 'cancel') {
                submitform( 'viewlink' );
                return;
            }

            // do field validation
            if (form.link_name.value == ""){
                alert( "<?php echo $this->_MT_LANG->PLEASE_FILL_IN_LINK_NAME ?>" );
            } else {
                form.task.value=pressbutton;
                form.submit();
            }
        }
    </script>



    <table width="96%" cellpadding="4" cellspacing="0" border="0" align="center">
        <form action="<?php echo sefRelToAbs("index.php"?>" method="post" enctype="multipart/form-data" name="adminForm" id="adminForm">
        
        <?php echo ( (isset($this->warn_duplicate) && $this->warn_duplicate == 1) ? '<tr><td colspan="2">' $this->_MT_LANG->THERE_IS_ALREADY_A_PENDING_APPROVAL_FOR_MODIFICATION '</td></tr>' '' )?>


        <tr>
            <td valign="top" align="right">Category:</td>
            <td><?php echo $this->catlist ?> <i>Please make sure you select the correct category</i><br /><br /></td>
        </tr>

        

        <tr>
            <td colspan="2">
                <input type="hidden" name="option" value="<?php echo $this->option ?>" />
                <input type="hidden" name="task" value="savelisting" />
                <input type="hidden" name="Itemid" value="<?php echo $this->Itemid ?>" />            
                <?php if ( $this->link->link_id == ) { ?>
                <input type="hidden" name="cat_id" value="<?php echo $this->cat_id ?>" />
                <?php } else { ?>
                <input type="hidden" name="link_id" value="<?php echo $this->link->link_id ?>" />
                <input type="hidden" name="cat_id" value="<?php echo $this->cat_id ?>" />
                <?php ?>
    <br /><br /><center>
                <input type="button" value="<?php echo $this->_MT_LANG->SUBMIT_LISTING ?>" onClick="javascript:submitbutton('savelisting')" class="button" /> <input type="button" value="<?php echo $this->_MT_LANG->CANCEL ?>" onClick="history.back();" class="button" /></center>
                </form>
            </td>
        </tr>
    </table>

  2. #2
    SitePoint Zealot Para's Avatar
    Join Date
    Mar 2005
    Location
    London UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a note, seems the Cancil button works ok, but submit still error.

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Next time please post the code after the PHP code has been processed.

    What is 'savelisting'?

    I am concerned that your code is not following JavaScript Best Practices. I recommend you read up on them.

    Don't forget to make sure that the (X)HTML and CSS code you write is valid.
    http://validator.w3.org/
    http://jigsaw.w3.org/css-validator/
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Zealot Para's Avatar
    Join Date
    Mar 2005
    Location
    London UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that, here is the function, i think im going to just try and submit without the javascript if possable as its kinda beyond me. This is a joomla componant im using, not a script i have written myself.


    Thanks for your help

    PHP Code:
    function savelisting$option ) {
        global 
    $mt_user_addlisting$mt_needapproval_addlisting$mt_needapproval_modifylisting$database$_MT_LANG$Itemid$my;
        global 
    $mt_notifyuser_newlisting$mt_notifyadmin_newlisting$mt_notifyuser_modifylisting$mt_notifyadmin_modifylisting$mt_allow_html$mt_user_addlisting;

        global 
    $mosConfig_mailfrom$mosConfig_fromname$mt_admin_email$mosConfig_absolute_path$mosConfig_live_site$mt_listing_image_dir$mt_resize_method$mt_resize_quality$mt_resize_listing_size;

        
    # Get cat_id / remove_image / link_image
        
    $cat_id intvalmosGetParam$_REQUEST'cat_id') );
        
    $remove_image mosGetParam$_REQUEST'remove_image');
        
    $link_image mosGetParam$_FILES'link_image'null );
        
    $new_cat_id intvalmosGetParam$_POST'new_cat_id') );

        
    # Check if any malicious user is trying to submit link
        
    if ( ($mt_user_addlisting == && $my->id 1) || $mt_user_addlisting == -) {
            
            echo 
    _NOT_EXIST;

        } else {
        
    # Allowed

            // Convert all checkbox value to comma delimited
            
    for($i=1$i<=30$i++) {
                if ( @
    is_array($_POST["cust_".$i]) ) {
                    
    $_POST["cust_".$i] = implode(",",$_POST["cust_".$i]);
                }
            }

            
    $row = new mtLinks$database );
            if (!@
    $row->bind$_POST )) {
                echo 
    "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
                exit();
            }
            
            if ( 
    $new_cat_id <> $row->cat_id AND $new_cat_id ) {
                
    $row->cat_id $new_cat_id;
            }

            
    $isNew = ($row->link_id 1) ? 0;

            
    # website's validation
            
    if ( $row->website == "http://" ) {
                
    $row->website '';
            } elseif( !empty(
    $row->website) && substr($row->website,0,7) != 'http://' ) {
                
    $row->website 'http://'.$row->website;
            }

            
    # Assignment for new record
            
    if ($isNew) {

                
    $row->link_created date"Y-m-d H:i:s" );    
                
    $row->ordering 999;

                if ( 
    $my->id 0) {
                    
    $row->user_id $my->id;
                } else {
                    
    $database->setQuery"SELECT id FROM #__users WHERE usertype = 'Super Administrator' LIMIT 1" );
                    
    $row->user_id $database->loadResult();
                }

                if (!
    $mt_allow_html) {
                    
    $row->link_desc strip_tags($row->link_desc);
                }

                
    // Approval for adding listing
                
    if ( $mt_needapproval_addlisting ) {
                    
    $row->link_approved '0';
                } else {
                    
    $row->link_approved 1;
                    
    $row->link_published 1;
                    
    mosCache::cleanCache'com_mtree' );
                }

            
    # Modification to existing record
            
    } else {
                
                
    //print_r( $_POST );

                # Validate that this user is the rightful owner
                
    $database->setQuery"SELECT user_id FROM #__mt_links WHERE link_id = '".$row->link_id."'" );
                
    $user_id $database->loadResult();

                if (  
    $user_id <> $my->id ) {
                    echo 
    _NOT_EXIST;;
                } else {

                    
    # Get the name of the old photo and last modified date
                    
    $sql="SELECT link_id, link_image, link_modified, link_created FROM #__mt_links WHERE link_id='".$row->link_id."'";
                    
    $database->setQuery($sql);
                    
    $database->loadObject($old);

                    
    $old_image $old->link_image;

                    
    # Remove previous old image
                    /*
                    if ( $remove_image || ($old_image <> '' && $link_image['tmp_name'] <> '') ) {
                        $row->link_image = '-1';

                        if(!unlink($mosConfig_absolute_path.$mt_listing_image_dir.$old_image)) {
                            echo "<script> alert('".$_MT_LANG->ERROR_DELETING_OLD_IMAGE."'); </script>\n";
                        }
                    }
                    */
                    # Retrive last modified date
                    
    $old_modified $old->link_modified;
                    
    $link_created $old->link_created;

                    
    $row->link_modified date"Y-m-d H:i:s" );    
                    
    $row->link_published 1;
                    
    $row->user_id $my->id;
                    
                    
    // Get other info from original listing
                    
    $database->setQuery"SELECT link_hits, link_votes, link_rating, link_featured, link_created, link_visited, link_image, ordering, publish_down, publish_up FROM #__mt_links WHERE link_id = '$row->link_id'" );
                    
    $database->loadObject$original );

                    foreach( 
    $original AS $k => $v ) {
                        
                        
    // Set link_image to "-1" to indicate image removal
                        
    if ( $k == "link_image" && ( $remove_image || ($old_image <> '' && $link_image['tmp_name'] <> '') ) ) {
                            if ( 
    $mt_needapproval_modifylisting ) {
                                
    $row->link_image '-1';
                            } else {
                                if(!
    unlink($mosConfig_absolute_path.$mt_listing_image_dir.$old_image)) {
                                    echo 
    "<script> alert('".$_MT_LANG->ERROR_DELETING_OLD_IMAGE."'); </script>\n";
                                } else {
                                    
    $row->link_image '';
                                }
                            }
                        } else {
                            
    $row->$k $v;
                        }
                    }

                    
    // Remove any listing that is waiting for approval for this listing
                    
    $database->setQuery"DELETE FROM #__mt_links WHERE link_approved = '".(-1*$row->link_id)."'" );
                    
    $database->query();
                    
                    
    // Approval for modify listing
                    
    if ( $mt_needapproval_modifylisting ) {
                        
    $row->link_approved = (-$row->link_id);
                        
    $row->link_id null;
                    } else {
                        
    $row->link_approved 1;
                        
    mosCache::cleanCache'com_mtree' );
                    }

                }

            } 
    // End of $isNew

            # Create Thumbnail
            
    if ( $link_image['name'] <> '' ) {

                
    $mtImage = new mtImage$link_image$mosConfig_absolute_path.$mt_listing_image_dir );
                
    $mtImage->setMethod$mt_resize_method );
                
    $mtImage->setQuality$mt_resize_quality );
                
    $mtImage->setSize$mt_resize_listing_size );

                if ( 
    $row->link_id ) {
                    
    $mtImage->setName$row->link_id."_".$link_image['name'] );
                }

                if ( 
    $mtImage->check() ) {
                    if ( 
    $mtImage->resize() ) {
                        if ( 
    $row->link_id ) {
                            
    $row->link_image $row->link_id."_".$link_image['name'];
                        } elseif( 
    $isNew ) {
                            
    // Do nothing yet. The record is not saved, therefore no link_id available.
                        
    } else {
                            
    $row->link_image $old->link_id."_".$link_image['name'];
                        }
                    }
                } else {
                    echo 
    "<script> alert('".$mtImage->getErrorMsg()."'); window.history.go(-1); </script>\n";
                    exit();
                }

            }

            
    # Strip HTML tags if admin does not allow it
            
    if (!$mt_allow_html) {
                
    $row->link_desc strip_tags($row->link_desc);
            }
            

            
    # OK. Store new listing into database
            
    if (!$row->store()) {
                echo 
    "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
                exit();
            } else {
                
                
    # If this is a newly submitted link and has image, rename the photo to listingID_photoName.jpg
                
    if ( $isNew && $link_image['error'] == ) {

                    
    // Get last inserted listing ID
                    
    $mysql_last_insert_cl_id $database->insertid();

                    
    $database->setQuery"SELECT link_id FROM #__mt_cl WHERE cl_id = ".$mysql_last_insert_cl_id );
                    
    $mysql_last_insert_id $database->loadResult();

                    if ( 
    $mysql_last_insert_id ) {

                        if ( 
    rename$mosConfig_absolute_path.$mt_listing_image_dir.$link_image['name'], $mosConfig_absolute_path.$mt_listing_image_dir.$mysql_last_insert_id."_".$link_image['name'] ) ) {

                            
    $database->setQuery"UPDATE #__mt_links SET link_image = '".$mysql_last_insert_id."_".$link_image['name']."' WHERE link_id = '".$mysql_last_insert_id."' LIMIT 1" );
                            
    $database->query();

                        }
                    }

                
    # This is modification to an existing listing
                
    } elseif( !$isNew && $link_image['error'] == && $row->link_id ) {

                    
    $database->setQuery"SELECT LAST_INSERT_ID()" );
                    
    $mysql_last_insert_id $database->loadResult();

                    if ( 
    $mysql_last_insert_id ) {

                        if ( 
    rename$mosConfig_absolute_path.$mt_listing_image_dir.$link_image['name'], $mosConfig_absolute_path.$mt_listing_image_dir.($row->link_approved * -1)."_".$link_image['name'] ) ) {
                            
                            
    $database->setQuery"UPDATE #__mt_links SET link_image = '".($row->link_approved * -1)."_".$link_image['name']."' WHERE link_id = '".$mysql_last_insert_id."' LIMIT 1" );
                            
    $database->query();

                        }
                    }

                }
            }

            
    # Send e-mail notification to user/admin upon adding a new listing

            // Get owner's email
            
    $database->setQuery"SELECT email, name FROM #__users WHERE id = '".$my->id."' LIMIT 1" );
            
    $database->loadObject$author );

            if ( 
    $isNew ) {

                
    # To User
                
    if ( $mt_notifyuser_newlisting == && $my->id ) {
                    
                    if ( 
    $row->link_approved == ) {
                        
    $subject sprintf($_MT_LANG->NEW_LISTING_EMAIL_SUBJECT_WAITING_APPROVAL$row->link_name);
                        
    $msg $_MT_LANG->NEW_LISTING_EMAIL_MSG_WAITING_APPROVAL;
                    } else {
                        
    $subject sprintf($_MT_LANG->NEW_LISTING_EMAIL_SUBJECT_APPROVED$row->link_name);
                        
    $msg sprintf($_MT_LANG->NEW_LISTING_EMAIL_MSG_APPROVED$row->link_namesefRelToAbs($mosConfig_live_site."/index.php?option=com_mtree&task=viewlink&link_id=$row->link_id&Itemid=$Itemid"),$mosConfig_fromname);
                    }

                    
    mosMail$mosConfig_mailfrom$mosConfig_fromname$author->email$subjectwordwrap($msg) );
                }

                
    # To Admin
                
    if ( $mt_notifyadmin_newlisting == ) {
                    
                    if ( 
    $row->link_approved == ) {
                        
    $subject sprintf($_MT_LANG->NEW_LISTING_EMAIL_SUBJECT_WAITING_APPROVAL$row->link_name);
                        
    $msg sprintf($_MT_LANG->ADMIN_NEW_LISTING_MSG_WAITING_APPROVAL$row->link_name$row->link_name$row->link_id$author->name$my->username$author->email);
                    } else {
                        
    $subject sprintf($_MT_LANG->NEW_LISTING_EMAIL_SUBJECT_APPROVED$row->link_name);
                        
    $msg sprintf($_MT_LANG->ADMIN_NEW_LISTING_MSG_APPROVED$row->link_namesefRelToAbs($mosConfig_live_site."/index.php?option=com_mtree&task=viewlink&link_id=$row->link_id&Itemid=$Itemid"), $row->link_name$row->link_id$author->name$my->username$author->email);
                    }

                    
    //mosMail( $mosConfig_mailfrom, $mosConfig_fromname, $mt_admin_email, $subject, wordwrap($msg) );
                    
    mosMailToAdmin$subject$msg );

                }

            }

            
    # Send e-mail notification to user/admin upon modifying an existing listing
            
    else {


                
    # To User
                
    if ( $mt_notifyuser_modifylisting == && $my->id ) {
                    
                    if ( 
    $row->link_approved ) {
                        
    $subject sprintf($_MT_LANG->MODIFY_LISTING_EMAIL_SUBJECT_WAITING_APPROVAL$row->link_name);
                        
    $msg sprintf($_MT_LANG->MODIFY_LISTING_EMAIL_MSG_WAITING_APPROVAL$row->link_namesefRelToAbs($mosConfig_live_site."/index.php?option=com_mtree&task=viewlink&link_id=$old->link_id&Itemid=$Itemid") );
                    } else {
                        
    $subject sprintf($_MT_LANG->MODIFY_LISTING_EMAIL_SUBJECT_APPROVED$row->link_name);
                        
    $msg sprintf($_MT_LANG->MODIFY_LISTING_EMAIL_MSG_APPROVED$row->link_namesefRelToAbs($mosConfig_live_site."/index.php?option=com_mtree&task=viewlink&link_id=$old->link_id&Itemid=$Itemid"),$mosConfig_fromname);
                    }

                    
    mosMail$mosConfig_mailfrom$mosConfig_fromname$author->email$subjectwordwrap($msg) );
                }

                
    # To Admin
                
    if ( $mt_notifyadmin_modifylisting == ) {
                    
                    if ( 
    $row->link_approved ) {
                        
    $subject sprintf($_MT_LANG->MODIFY_LISTING_EMAIL_SUBJECT_WAITING_APPROVAL$row->link_name);
                        
    $msg sprintf($_MT_LANG->ADMIN_MODIFY_LISTING_MSG_WAITING_APPROVAL$row->link_namesefRelToAbs($mosConfig_live_site."/index.php?option=com_mtree&task=viewlink&link_id=$old->link_id&Itemid=$Itemid"), $row->link_name$row->link_id$author->name$my->username$author->email);
                    } else {
                        
    $subject sprintf($_MT_LANG->MODIFY_LISTING_EMAIL_SUBJECT_APPROVED$row->link_name);
                        
    $msg sprintf($_MT_LANG->ADMIN_MODIFY_LISTING_MSG_APPROVED$row->link_namesefRelToAbs($mosConfig_live_site."/index.php?option=com_mtree&task=viewlink&link_id=$old->link_id&Itemid=$Itemid"), $row->link_name$row->link_id$author->name$my->username$author->email);
                    }

                    
    mosMailToAdmin$subject$msg );
                }

            }

            
    mosRedirect"index.php?option=$option&task=listcats&cat_id=$cat_id&Itemid=$Itemid", ( ($isNew) ? ( ($mt_needapproval_addlisting) ? $_MT_LANG->LISTING_WILL_BE_REVIEWED $_MT_LANG->LISTING_HAVE_BEEN_ADDED) : ( ($mt_needapproval_modifylisting) ? $_MT_LANG->LISTING_MODIFICATION_WILL_BE_REVIEWED $_MT_LANG->LISTING_HAVE_BEEN_UPDATED ) ) );

        }


  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Huh? But that's a PHP function.

    I was asking about this: (I figured out it was a red herring though.)
    Code:
    onClick="javascript:submitbutton('savelisting')"
    Where is the form control named "link_name"?

    What is the submitform() function defined as?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  6. #6
    SitePoint Zealot Para's Avatar
    Join Date
    Mar 2005
    Location
    London UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz View Post
    Huh? But that's a PHP function.
    Sorry, i didnt realise what you were saying.


    Quote Originally Posted by Kravvitz View Post
    Where is the form control named "link_name"?
    link_name is one of the fields in my form, as i mentioned i didnt post all the fields.


    Quote Originally Posted by Kravvitz View Post
    What is the submitform() function defined as?
    I havent got a clue, javascript is my weak point, all i know is that it works in firefox ok, but IE its a no go.

    Sorry to be a pain in the butt!

    Thanks for your help

  7. #7
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if the submitform() function is missing, then that might be what's causing the problem in IE.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •