11 Replies - 5818 Views - Last Post: 18 March 2013 - 05:07 PM Rate Topic: -----

#1 poldz123  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 26-October 12

Adding action to button inside form

Posted 18 March 2013 - 03:39 PM

How can I add a action on a different button so I can go to the test.php file instead of going to checklogin.php .
it keeps going to the checklogin.php not to register.php.

Sorry I know this is a noob question.
BTW I want my register button and lgin button to be insde the table
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>

<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"><INPUT type="submit" value="register" action="test.php"></td>
</tr>
</table>
</td>
</form>

</tr>
</table>

This post has been edited by poldz123: 18 March 2013 - 03:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Adding action to button inside form

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3252
  • View blog
  • Posts: 10,902
  • Joined: 12-December 12

Re: Adding action to button inside form

Posted 18 March 2013 - 03:52 PM

<input type="submit" value="register" action="test.php">

action is an attribute of the form, not of an input: you can't just make stuff up!!

It is up to the PHP script to produce different content, or re-direct to another page. Give both submit buttons the same name and check the value of this in the PHP script to decide what to do next.

BTW The bgcolor and align attributes for a table were deprecated in HTML 4.01!? and no longer exist in HTML5. (I don't know where people dig these things up from :whistling:. )
Was This Post Helpful? 0
  • +
  • -

#3 poldz123  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 26-October 12

Re: Adding action to button inside form

Posted 18 March 2013 - 03:54 PM

Yea I made that up lol I though It would redirect me to the register.php.

But im Still struggling on how should I do it?? Can I put a form inside the form. formception

and add an action at the form inside the form to redirect me to the register button??

Can you give me a good example please and thank you.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3252
  • View blog
  • Posts: 10,902
  • Joined: 12-December 12

Re: Adding action to button inside form

Posted 18 March 2013 - 03:55 PM

The width attribute for a table is no longer supported in HTML5 either - use CSS.
Was This Post Helpful? 0
  • +
  • -

#5 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: Adding action to button inside form

Posted 18 March 2013 - 03:59 PM

You want the information of the form to be applicable to two different pages?

You could make two separate submit buttons, both with unique names, and make a page that handles the form's data as such:


if(isset($_POST['checkLoginSubmit'])) {
    //Do Something
}else{
    if(isset($_POST['registerSubmit'])) {
        //Do Something else
    }
}



This post has been edited by xxxjj18: 18 March 2013 - 04:07 PM

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3252
  • View blog
  • Posts: 10,902
  • Joined: 12-December 12

Re: Adding action to button inside form

Posted 18 March 2013 - 04:05 PM

View Postpoldz123, on 18 March 2013 - 03:54 PM, said:

Yea I made that up lol I though It would redirect me to the register.php.

But im Still struggling on how should I do it?? Can I put a form inside the form. formception

and add an action at the form inside the form to redirect me to the register button??

Can you give me a good example please and thank you.

We cannot nest forms.

$submitted = false;
if (isset($_POST['Submit']) && !empty($_POST['Submit'])) {
    $submitted = $_POST['Submit'];
}
if ($submitted !== false) {
    if ($submitted == 'Login') {
        // do something
    } else if ($submitted == 'register') {
        // do something else
    } else {
        // something dodgy going on
    }
}


View Postxxxjj18, on 18 March 2013 - 03:59 PM, said:

You want the information of the form to be applicable to two different pages?

You could make two separate submit buttons, both with unique ID's, and make a page that handles the form's data as such:


if(isset($_POST['checkLoginSubmit'])) {
    //Do Something
}else{
    if(isset($_POST['registerSubmit'])) {
        //Do Something else
    }
}



The post-data is based on names, not IDs. You can, as I suggested, give the two buttons the same name but different values, or two different names if you prefer.

This post has been edited by andrewsw: 18 March 2013 - 04:07 PM

Was This Post Helpful? 0
  • +
  • -

#7 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: Adding action to button inside form

Posted 18 March 2013 - 04:08 PM

andrewsw Ah, I accidentally said ID instead of name xD. Thanks for catching me on that lol
Was This Post Helpful? 0
  • +
  • -

#8 poldz123  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 26-October 12

Re: Adding action to button inside form

Posted 18 March 2013 - 04:11 PM

Where Do I put the codes that you just added???
at the checklogin.php??? or inside the form??
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3252
  • View blog
  • Posts: 10,902
  • Joined: 12-December 12

Re: Adding action to button inside form

Posted 18 March 2013 - 04:17 PM

View Postxxxjj18, on 18 March 2013 - 04:08 PM, said:

andrewsw Ah, I accidentally said ID instead of name xD. Thanks for catching me on that lol

No worries. Actually, I think my code is wrong: both buttons will be submitted, as an array. So, yes, I would probably give them different names.

View Postpoldz123, on 18 March 2013 - 04:11 PM, said:

Where Do I put the codes that you just added???
at the checklogin.php??? or inside the form??

As just mentioned, my code is slightly wrong anyway. Give the two submit buttons different names and use xxxjj18 's example.

If you don't know where to put the code then I suggest that you need to study more of the fundamentals of PHP.

Doh! But you'll need to write some client-side (Javascript) code to change the values of the submit buttons before the form is submitted, or remove one of them entirely from the form.

Sorry, must be tired :whistling:
Was This Post Helpful? 0
  • +
  • -

#10 poldz123  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 26-October 12

Re: Adding action to button inside form

Posted 18 March 2013 - 04:26 PM

thanks you guys I made it work.. I used the isset that xxxjj18'] added..
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3252
  • View blog
  • Posts: 10,902
  • Joined: 12-December 12

Re: Adding action to button inside form

Posted 18 March 2013 - 04:40 PM

View Postpoldz123, on 18 March 2013 - 04:26 PM, said:

thanks you guys I made it work.. I used the isset that xxxjj18'] added..

Well done.

Yes, I believe that only the submit button that is clicked will have its value posted to the PHP script, so that my original script would work.
Was This Post Helpful? 0
  • +
  • -

#12 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: Adding action to button inside form

Posted 18 March 2013 - 05:07 PM

Glad we could help :)

This post has been edited by xxxjj18: 18 March 2013 - 05:07 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1