SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Code Does Not Work But Should?

    Hi,

    I have the following code however it does not work on my site but I have seen it on other sites.

    It is supposed to be a submit button. Can anyone advise if the DOCTYPE is correct?


    Code:
    <div class="aboutuscontent">
    <div class="followbuttonbox">   
    <form>
    <input name="followbutton" type="image" src="07221802_d18fc66228740e19b32cd5c95c8b4502.png" />
    </div>
    </form>
    </div>

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Mar 2013
    Location
    Oneonta, NY
    Posts
    307
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Justlukeyou,

    I notice that you have some classes (i.e. aboutuscontent and followbuttonbox). Do you have a css style sheet linked to your HTML document that contains those classes? Also, are you sure that the image for your button is on your server? I would check those things first. If you can provide a link to the page where the code is installed I might be able to help you further.

    Best,

    Shawn

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Many thanks,

    I am trying to use an image as a submit button, the top line works but the bottom line doesn't.

    Can anyone advise how to use an image as a submit button?


    Code:
    <input name="followbutton" type="submit" />
    <input name="followbutton" type="image" src="/images/follow.png" />

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You are using the correct way to define an image as the submit button.

    Just exactly what is happening that indicates that it is not working.

    Is the image displaying? If not then the path to the image is wrong.

    If you click on the image then the form will be submitted - if it isn't then one of the validation tests that you are doing must be wrong.

    It is usually best to not name submit buttons/images at all as the information passed is not useful - particularly when using images where both followbutton.x and followbutton.y will be zero if the form is submitted from the keyboard and will only contain values indicating a position within the image if the form is submitted by clicking on the image.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    The image displays but when I click it nothing happens.

    Is there a way of using images as a submit button?

  6. #6
    SitePoint Addict bronze trophy
    Join Date
    Mar 2013
    Location
    Oneonta, NY
    Posts
    307
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Justlukeyou,

    A better way to do this would be as follows:

    This goes in your HTML

    <div id=followbutton>
    <input type="submit" id="image-button">Text</input>
    </div>

    This Goes in a CSS File

    #followbutton input{
    background: #fff url(' /images/follow.png')no-repeat;
    }


    Best,

    Shawn

  7. #7
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I tried this but I couldn't get it to work. It displays the word "sumit" and the image on top of one another.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Thanks,

    The image displays but when I click it nothing happens.

    Is there a way of using images as a submit button?

    Yes - exactly as you are doing - at least for the part of the code that you are showing us.

    If it isn't working then the problem is in a part of the code you haven't shown us.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    This is all the code. I just cant see why it works with standard submit button but not an image. Its driving me nuts.


    Code:
    <form method="post" enctype="multipart/form-data">
    
    <?php
     
    $profileid = (int)$_GET['ID'];
    $followerid = intval($_SESSION['userID']);
    
    
    
    $query = mysql_query("SELECT * FROM follow WHERE user_id = '". $profileid ."' AND follow_user_id= '". $followerid ."'"); 
    $duplicatefollow = null;
    if (mysql_num_rows($query) > 0) 
    { 
    $error['duplicatefollow'] = 'You Already Follow This Profile.</a>.'; 
    }   
    
    else
    {
      
    if(isset($_POST['followbutton'])) {
    
    
    $query = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES ('{$profileid}', '{$followerid}')";
    $result = mysql_query($query);
    
    
    	if (!$result){
    	$errors[] = "Query: {$query}<br>Error: " . mysql_error();
    	}
           if(($profileid) == ($followerid)) {
    $errors['sameprofile'] = "You cannot follow your own profile.";
    }
    }  
    }     
      
    
    
      
      $loginprofile = intval($_SESSION['userID']); 
      
      $query_rsSearch = "SELECT * FROM follow WHERE `follow_user_id` = '$loginprofile'";
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
      
    ?>
    
       
    
    <div class="followbuttonbox">   
    <input name="followbutton" type="submit" />
    <input name="followbutton" type="image" src="/images/follow.png" />
    </div>
    </form>


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
  •