The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Use image as submit button, How to use a graphic as a submit button
The-Yikes
post May 27 2020, 03:49 PM
Post #1





Group: Members
Posts: 6
Joined: 27-May 20
Member No.: 27,365



Hi! I'm hoping someone here can help me out.

I'm trying to use an image as a submit button which in turn loads a php script.
Here's what I have

HTML File:
CODE

<html>

<head>
<title>No title</title>
<meta name="generator">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<form name="form1" method="post" action="post.php">
    <p> </p>
    <table border="1" width="407">
        <tr>
            <td width="200">
                <p><input type="text" name="name"></p>
            </td>
            <td width="191">
                <p><input type="text" name="pwd"></p>
                <p><input type="image" name"submit_btn" src="button1.jpg" alt"Submit"></p>
                <p></p>
                </td>        </tr>
        <tr>
            <td width="397" colspan="2"><input type="submit" name="submit_btn"></td>
        </tr>
    </table>
</form>
<p> </p>
</body>

</html>


And here's what i have for the php:
CODE

<?php

if(isset($_POST['submit_btn']))
{
  $username = $_POST['name'];
  $password = $_POST['pwd'];
  $text = $username . "," . $password . "\n";
  $fp = fopen('data.txt', 'a+');

    if(fwrite($fp, $text))  {
        echo 'saved';
    
    }
fclose ($fp);    
}
?>
<html>


It works fine with a standard Submit button.

I would really appreciate any little bit of help you can offer!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
The-Yikes
post May 28 2020, 06:33 AM
Post #2





Group: Members
Posts: 6
Joined: 27-May 20
Member No.: 27,365



Thanks Pandy! I changed the line to read the following

CODE
               <p><input type="image" name="submit_btn" src="button1.jpg"></p>


But it'still not working. It loads the next page but it's not writing to the text file.

P.s thanks for the quick reply!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 28 2020, 07:15 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



Try something like this PHP:

CODE
echo '<pre>';
print_r($_POST);
echo '</pre>';

to make sure the form data is submitted properly.


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post May 28 2020, 07:18 AM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Why do you want two buttons doing the same thing BTW?
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The-Yikes
post May 28 2020, 07:34 AM
Post #5





Group: Members
Posts: 6
Joined: 27-May 20
Member No.: 27,365



QUOTE(pandy @ May 28 2020, 07:18 AM) *

Why do you want two buttons doing the same thing BTW?

I don't need two buttons i only need one, i just kept it to use for reference
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post May 28 2020, 07:37 AM
Post #6


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Thanks, Christian. Thought so, but I wasn't sure.

Anyway, just for the sake of it, delete the ordinary submit button and see if it works with only the image submit.
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
The-Yikes   Use image as submit button   May 27 2020, 03:49 PM
pandy   There's input type="image". https:/...   May 27 2020, 04:04 PM
Christian J   In what way doesn't it work? I see both an i...   May 27 2020, 04:52 PM
pandy   Ack, I only saw the last submit button. :(   May 27 2020, 05:00 PM
The-Yikes   Christian jay you asked in which does it not work....   May 28 2020, 06:01 AM
pandy   There's an equal sign missing here. <inpu...   May 28 2020, 06:14 AM
The-Yikes   Thanks Pandy! I changed the line to read the f...   May 28 2020, 06:33 AM
pandy   Hmm. Could it be that different names have to be u...   May 28 2020, 07:15 AM
Christian J   Hmm. Could it be that different names have to be ...   May 28 2020, 07:24 AM
Christian J   Try something like this PHP: echo '<pre...   May 28 2020, 07:15 AM
pandy   Why do you want two buttons doing the same thing B...   May 28 2020, 07:18 AM
The-Yikes   Why do you want two buttons doing the same thing ...   May 28 2020, 07:34 AM
pandy   Thanks, Christian. Thought so, but I wasn't su...   May 28 2020, 07:37 AM
The-Yikes   Thanks, Christian. Thought so, but I wasn't s...   May 28 2020, 08:46 AM
Christian J   I then changed the line <input type="ima...   May 28 2020, 10:15 AM
The-Yikes   Thanks Christian J but that's a bit beyond m...   May 28 2020, 10:21 AM
Christian J   Try adding this to the page's (or site's) ...   May 28 2020, 02:27 PM
pandy   But WHY doesn't the image submit work? :angry...   May 28 2020, 04:43 PM
Christian J   From https://www.php.net/manual/en/language.vari.....   May 28 2020, 05:13 PM
pandy   ¡Ay caramba! I don't understand that. Wha...   May 28 2020, 06:33 PM
pandy   Ay, I get it. I didn't realize the OPs script ...   May 28 2020, 08:11 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 05:19 PM