Reply
Making submit buttons unique
Old 11-28-2007, 06:26 PM Making submit buttons unique
Average Talker

Posts: 20
Name: Levi
Trades: 0
I need to make 2 submit buttons one that if clicked sends data to a mysql server the other if clicked takes data from the mysql server.

This is what my submit buttons are currently.
Code:
<input type="submit" name="submit" id="submit" value="Create an Account" />
<input type="submit" name="submit" id="submit" value="Tell Me My Password" />
I am using an if statement in perl to try and get it to do one of the other action for it like this.

Code:
if ($submit == "Create an Account")
{
Send everything to the database
}
Code:
if ($submit == "Tell Me My Password")
{
Send password back
}
Right now it will run through both of them sending the data to the mysql database as well as sending it back and printing it, and I don't know how to make it so that it will only run through the one clicked on. Can anyone help me?
Levi_ is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-28-2007, 07:12 PM Re: Making submit buttons unique
chrishirst's Avatar
Super Moderator

Posts: 26,536
Location: Blackpool. UK
Trades: 0
You can't have two elements with the same ID.

Just give the buttons different names

"create" & "send_pwd" or submit1 & submit2
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | Crowded Nightclub? | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-28-2007, 07:19 PM Re: Making submit buttons unique
Nathand's Avatar
Extreme Talker

Posts: 228
Location: USA
Trades: 0
What do you tell the form to do once submitted? E.G. <form action = something>.

First change the name of one of the submit buttons so you have two different names. Something like this:
Code:
<input type="submit" name="submit1" id="submit" value="Create an Account" />
<input type="submit" name="submit2" id="submit" value="Tell Me My Password" />
Then do something like this inside the file that gets executed:
PHP:
Code:
if(isset($_POST["submit1"]))
{
create account code
}
else if(isset($_POST["submit2"]))
{
retrieve password
}
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
Old 11-28-2007, 08:15 PM Re: Making submit buttons unique
Average Talker

Posts: 20
Name: Levi
Trades: 0
I changed them so that the first input is submit and the second one is submit2.

Code:
                            <form name="info" id="info" action="cgi-bin/booksonline.cgi" method="post">
                            Account Number: <input type="text" name="username" id="username" size="5" maxlength="5" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            Password: <input type="password" name="password" id="password" size="10" maxlength="10" />
                            <br /><br />
                            <input type="submit" name="submit" id="submit" value="Create and Account" onclick="" />
                            <input type="submit" name="submit2" id="submit2" value="Tell Me My Password" onclick=""  />
                            </form>
Thats my form code, it is linked to a perl file that says this
Code:
if ($submit == "Create an Account")
{
Send everything to the database
}

elsif ($submit2 == "Tell Me My Password")
{
retrieve the password
}
It still comes up as completing the first if, but it does not get to the second one anymore. That means it is returning the first if true every time I assume?
Levi_ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Making submit buttons unique
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.09281 seconds with 13 queries