Jump to content

2 submit buttons on 1 page


Briek

Recommended Posts

hello,

 

I have this code :

 

<INPUT TYPE="Submit" VALUE="Change Password" name="ChangePasswd" TABINDEX=4>

<INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3>

 

Problem :

When the enter is pressed, the first submit is executed. -> "Change Password".

I want that when enter is pressed that the "Login" button is triggered.

 

Is there a possibility to set the enter to "Login" without changing the the place of the buttons???

(if I put "Login" button before "Change Password"; Enter does the "Login", but this is no option)

 

Thx in advance

Link to comment
https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/
Share on other sites

Not that I can think of.  By default, I believe browsers search for the first button.  You can try:

 

 

<INPUT TYPE="button" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="this.form.submit()">

<INPUT TYPE="submit" VALUE="Login" name="action" TABINDEX=3>

 

Not sure how that'll work

Well, this really isn't a PHP question and belongs in either HTML or Javadcript forum. But to answer your question, here's one solution:

 

Without seeing the layout of the page I would say that you need to use javascript. Just create a hidden field for the submit type and then use javascript on the submit buttons to populate the field instead of sending the value as the submit value:

 

<input type="hidden" name="submitValue" id="submitValue">

<INPUT TYPE="Submit" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="document.getElementById('submitValue').value=this.value;">

<INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3 onclick="document.getElementById('submitValue').value=this.value;">

 

 

With onclick="this.form.submit()" : the "Login" is done when enter is pressed.

But the "Change Password" doesn't work anymore.

 

Here more of my code:

 

<HTML><HEAD></HEAD>

<body bgcolor="#FFFFEE" link="#FF8C00" vlink="#FF8C00" alink="#FF8C00" OnLoad="document.index.USER.focus();">

<FORM name="index" method="POST">

  <INPUT TYPE="text" NAME="USER" TABINDEX=1>

  <INPUT TYPE="password" NAME="PASSWORD" TABINDEX=2>

  <INPUT TYPE="Button" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="this.form.submit()">

  <INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3>

</FORM>

 

<?php

 

$action =  $_POST['action'];

$ChangePasswd = $_POST['ChangePasswd'];

 

if ($action == "Login" or $ChangePasswd == "Change Password")

{

 

}

?></BODY></HTML></html>

 

Problem :

with onclick="this.form.submit()" -> the $_POST['ChangePasswd'] isn't triggered

 

Can somebody solve this???

 

 

thanks in advance

<HTML><HEAD></HEAD>
<body bgcolor="#FFFFEE" link="#FF8C00" vlink="#FF8C00" alink="#FF8C00" OnLoad="document.index.USER.focus();">
<FORM name="index" method="POST">
   <INPUT TYPE="text" NAME="USER" TABINDEX=1>
   <INPUT TYPE="password" NAME="PASSWORD" TABINDEX=2>
   <INPUT TYPE="button" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="this.form.submit()">
   <INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3>
</FORM>

<?php

if (isset($_POST)) {
  //User submitted the page
  if (isset($_POST['action'])) {
    echo "User clicked Login";
  } else {
    echo "User clicked Change password";
  }

}
?></BODY></HTML></html>

if (isset($_POST)) {

  //User submitted the page

  if (isset($_POST['action'])) {

    echo "User clicked Login";

  } else {

    echo "User clicked Change password";

  }

}

 

 

The "if (isset($_POST))" is always true so the "else {echo "User clicked Change password";}" is always triggered.

 

Somebody can fix this????

 

Thx

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.