Page 1 of 1

HTML input as image button

Posted: Sat Jul 04, 2009 6:30 am
by billy_111
Hey,

I am new to this forum and wanted to ask a question.

I am trying to create an image button and use it as a submit button:-

Code: Select all

<input name="submit" type="image" src="images/submit.jpg" alt="Submit"/>
I have the following php code that shoudl work with this but does not work it simply refreshes the page:-

Code: Select all

    //This code runs if the form has been submitted
            if (isset($_POST['submit'])) 
            { 
                //This makes sure they did not leave any fields blank
                if (!$_POST['txt_fname'] | !$_POST['txt_sname'] | !$_POST['txt_address'] ) 
                {
                    die('You did not complete all of the required fields');
                }   
            }
Has anybody got any ides why this is happpening..?

Thanks

Regards
Billy

Re: HTML input as image button

Posted: Sat Jul 04, 2009 10:30 am
by ben.artiss
Hi Billy,

Your code only has single pipes for the 'or' operator (i.e. | instead of ||). I'm surprised it hasn't given you an error but try:

Code: Select all

if (isset($_POST['submit'])) {
    // use trim($input) to remove spaces etc
    if (!trim($_POST['txt_fname']) || !trim($_POST['txt_sname']) || !trim($_POST['txt_address'])) {
        die('You did not complete all of the required fields');
    }   
}
Hope that helps.

Re: HTML input as image button

Posted: Sun Jul 05, 2009 1:53 am
by paqman
Also, don't forget that microsoft abandoned sending a submit image's name in IE7. You have to check for $_POST["submit_x"] or $_POST["submit_y"], since IE no longer sends $_POST["submit"]. If anyone has anything to add, please do because I never found a better solution that that, or taking out the images all together...

Re: HTML input as image button

Posted: Mon Jul 06, 2009 8:53 am
by billy_111
Hey,

Thanks for your reply, but after taking that in mind it does not seem to work either..

Sorry for all the code but i think its better if i send what i have so you can have a look at it...

Code: Select all

 
        <div class="welcome">
        <p>registration</p>     
        </div>
                
        <?php 
            // Connects to Database 
            $dbc = mysql_connect ('db.sonassi.com','c2_listen','listen256') OR die('Could not connect to MySQL : ' . mysql_error() );
            mysql_select_db ('c2_listen') OR die('Could not select the database : ' . mysql_error() );
        
            //This code runs if the form has been submitted
            if (isset($_POST['submitted'])) 
            { 
                //This makes sure they did not leave any fields blank
                if (!trim($_POST['txt_fname']) || !trim($_POST['txt_sname']) || !trim($_POST['txt_address']) 
                || !trim($_POST['txt_city']) || !trim($_POST['txt_county']) || !trim($_POST['txt_pcode'])
                || !trim($_POST['txt_email']) || !trim($_POST['txt_username']))
                {
                    echo '<p style=margin-left:5px;font-size:12px><img src=images/warning_48.png> You did not complete all of the required fields.</p>';
                }
                else
                {
                if (!get_magic_quotes_gpc()) {
                $_POST['txt_username'] = addslashes($_POST['txt_username']);
                }
                $usercheck = $_POST['txt_username'];
                $check = mysql_query("SELECT username FROM members WHERE username = '$usercheck'") or die(mysql_error());
                $check2 = mysql_num_rows($check);
                
                if ($check2 != 0) {
                echo '<p style=margin-left:5px;>Sorry, the username <b>'.$_POST['txt_username'].'</b> is already in use. </p>';
                }
                    
                $insert = "INSERT INTO members (title, fname, sname, address, city_town, county, postcode, constituency, email, username) VALUES 
                (
                'MRRRR',
                '".$_POST['txt_fname']."', 
                '".$_POST['txt_sname']."',
                '".$_POST['txt_address']."',
                '".$_POST['txt_city']."',
                '".$_POST['txt_county']."',
                '".$_POST['txt_pcode']."',
                'TEST',
                '".$_POST['txt_email']."',
                '".$_POST['txt_username']."'
                )";
                $add_member = mysql_query($insert);
                }
            }               
        ?>
 
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="registers">
        <div style="background-image:url('images/register.jpg'); background-repeat: no-repeat; margin-left:5px;height:250px">
        <table style="font-size:12px;  margin-left:10px;">      
        <tr><td style="width:630px">Bills are the very essence of government.<br/>
        Bills, if passed, become the laws by which we are all governed. Drafting and voting on Bills about <br/>  
        tax rates, speed limits, immigration, minimum wage, abortion, social housing policy etc., is the core <br/>
        function of each elected government and your MP votes on your behalf on all these matters. This <br/>
        web site is designed to try to give you, the voter, a chance to influence these Bills, <br/>
        via your MP, in a way which has not previously been possible.
        </td></tr>
        </table>
 
        <table style="font-size:12px; margin-left:10px; margin-top:5px">        
        <tr><td style="width:230px">Title</td><td>
            <select name="title">
<option value="">-select-</option>
<option value="/tags/">Mr</option>
<option value="/">Mrs</option>
<option value="">Ms</option>
<option value="">Miss</option>
</select>
*</td></tr>
        <tr><td style="width:230px"></td><td>
            if other, please enter: <br/><input type="text" name="txt_title2" style="width:165px"/></td></tr>
        <tr><td><input id="hidden" type="hidden"/> </td></tr>
        <tr><td style="width:230px">First name</td><td>
            <input type="text" name="txt_fname" style="width:165px"/>*</td></tr>
        <tr><td style="width:230px">Last name</td><td>
            <input type="text" name="txt_sname" style="width:165px"/>*</td></tr>
            </table>
        </div>
        <br/>
        <table style="font-size:12px; margin-left:14px;">
                <tr><td style="width:230px">Address</td><td>
            <input type="text" name="txt_address" style="width:165px"/>*</td></tr>
            <tr><td style="width:230px"></td><td>
                <input type="text" name="txt_address2" style="width:165px"/></td></tr>
        <tr><td style="width:230px">City/Town</td><td>
            <input type="text" name="txt_city" style="width:165px"/>*</td></tr>
        <tr><td style="width:230px">County</td><td>
            <input type="text" name="txt_county" style="width:165px"/>*</td></tr>
        <tr><td style="width:230px">Post code</td><td>
            <input type="text" name="txt_pcode" style="width:165px"/>*</td></tr>
            </table>
            
            <table style="font-size:12px; margin-left:14px;">
        <tr><td style="width:230px">Constituency</td><td>
                        <select name="sel_const" style="width:226px">
<option value="">Bury North</option>
<option value="">Cheadle</option>
<option value="">Prestwich</option>
<option value="">Salford</option>
<option value="">Tatton</option>
</select>
*</td></tr>
        <tr><td style="width:230px">Email address</td><td>
            <input type="text" name="txt_email0" style="width:165px"/>* This will be used as part of your login</td></tr>
        <tr><td style="width:230px">Username</td><td>
            <input type="text" name="txt_username0" style="width:165px"/>* This will be used as part of your login</td></tr>
        <tr><td></td><td align="right">
            <input name="submitted" type="image" src="images/submit.jpg" value="Submit" alt="Submit"/></td></tr>
        </table>    
        </form>
        </div>
 
 
I would appreciate it if anybody can help..

Thanks
Regards
Billy