Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
How to tell which submit button was clicked
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/14/09 00:51 
I have 2 submit buttons on a single form both with different values.

Code
htmlPageSelect('header');
$dat[5999999]['title'] = '<input type="submit" name="myfirstbutton" value="Go!" /><input type="submit" name="mysecondbutton" value="Go!" />';       
htmlPageSelect('row',$dat);   
htmlPageSelect('footer');


according to this thread (and some others)
http://www.webdeveloper.com/forum/showthread.php?t=189494

which button was pressed should turn up in the $_REQUEST variable. but its not there.

Code
print "<pre>";
print_r($_REQUEST);
print "</pre>";


is there any way to know _which_ submit button was pressed?

Thanks


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
smith.kyle
CodeSmith


Joined: 27 Apr 2006
Posts: 22009
Location: Southern California

Posted: 05/14/09 14:55 
It should be $_post['myfirstbutton'] and $_post['mysecondbutton']. If you give them different values, then you can check if the variable is set as well as the value of it.


_________________
kyle[at]jamroom.net

Yes...that's a soda machine...

I get bored when no one's posting...
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/14/09 16:57 
yeah, that is what i was expecting, but it doesn't appear.


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/14/09 19:46 
here is a test script:
name: which_submit.php
place the file in the home jamroom directory
/which_script.php

Code
<?php
// set up our included files
require_once('include/jamroom-include.inc.php');

// get our variables
$_post = getPostVars();
##################################
# WHICH SUBMIT BUTTON WAS CLICKED
##################################
    if(isset($_post['submit_test'])){
    print "<pre>";
    //display all variables
    //$i = get_defined_vars();
    //print_r($i);
   
    //display only the $_post variables
    print_r($_post);
    print "<pre>";
    }   
   
   // Set up our page
   jmHtmlBegin("Which Submit button was clicked?");
   jmBodyBegin();       

    jmBeginForm('which_submit.php');   
    jrHtmlFormHiddenField('submit_test','test');

    htmlPageSelect('header');
    $dat[5999999]['title'] = '<input type="submit" name="myfirstbutton" value="myfirstbutton" /><input type="submit" name="mysecondbutton" value="mysecondbutton" />';       
    htmlPageSelect('row',$dat);   
    htmlPageSelect('footer');
   
    jmSubmit('submit','','150px');
    jmEndForm();
   
   
    jmBodyEnd();
    jmHtmlEnd();   
?>


produces the output of:
Array
(
[jr_html_form_token] => 933c55ec
[submit_test] => test
)
regardless of which submit was pressed.

even if i uncomment the:

Code
    //$i = get_defined_vars();
    //print_r($i);


which outputs ALL the set variables neither of the submit button's names or values are anywhere to be found.

could something in jamroom internals be stripping it?

--edit--
the flat php form does work.

Code
print '<form enctype="multipart/form-data" action="which_submit.php" method="post" name="form"/>';
print '<input type="submit" name="myfirstbutton" value="Go!" />';
print '<input type="submit" name="mysecondbutton" value="Go!" />';
print '</form>';

if ($_REQUEST['myfirstbutton']) print "I SEE THE FIRST BUTTON";
if($_REQUEST['mysecondbutton']) print "I SEE THE SECOND BUTTON";


--edit edit--
found the problem: its this in the <form creation line.

Code
onsubmit="lockFormSubmit(this)"



_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
smith.kyle
CodeSmith


Joined: 27 Apr 2006
Posts: 22009
Location: Southern California

Posted: 05/14/09 20:42 
You could do it with javascript actually:

<input type="hidden" id="hidden_container" name="hidden_container" value="">
<input type="submit" name="myfirstbutton" value="Go!" onclick="document.getElementById('hidden_container').value='myfirstbutton';">
<input type="submit" name="mysecondbutton" value="Go!" onclick="document.getElementById('hidden_container').value='mysecondbutton';">

not pretty, but it'll work.


_________________
kyle[at]jamroom.net

Yes...that's a soda machine...

I get bored when no one's posting...
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/14/09 21:07 
Cheers Kyle, That way would probably work too. (im not very good with javascript.)

so im working on a way around it by removing the javascript check in the form headers.

Code
$token = jrHtmlFormTokenCreate()
jmShowLine('sometext here<form name="form" method="post" target="_self" action="which_submit.php" enctype="multipart/form-data">
<input type="hidden" name="jr_html_form_token" value="' . $token . ">');


The 'lockFormSubmit' is checking for any form elements of types 'submit' 'reset' 'button' and disabling them. (to "lock" a form so it cannot be submitted twice)

if this way doesnt work then ill try yours. thanks


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.