...

View Full Version : passing button name and value via submit()?



mlse
12-08-2006, 12:29 PM
Hi all,

I have written a little bit of PHP which turns this:



<form method="[whatever]" action="[wherever]" name="[form name]">
<input name="mytextbox" type="text" />
<confirm name="callback" value="do this" message="Do you really want to do this?" />
<confirm name="callback" value="do that" message="Do you really want to do that?" />
</form>


Into this:



<form method="[whatever]" action="[wherever]" name="[form name]">
<input name="mytextbox" type="text" />
<input type="button" onclick=confirmSubmit("callback", "do this", "[form name]", "Do you really want to do this?" />
<input type="button" onclick=confirmSubmit("callback", "do that", "[form name]", "Do you really want to do that?" />
</form>


which uses the following javascript:



<script language="javascript">
<!--
function confirmSubmit(bkey, bvalue, fname, confmsg)
{
var response;

/*** Need something here to pass bkey and bvalue as a key/value
*** pair when the form is submitted.
***/

if (formname != "") //The PHP automatically inserts the form name into the function call, or "" if it is not specified.
{
response = confirm(confmessage);

if (response == true)
document.forms[formname].submit();
}
else alert("Programming Error - The form needs a name!");
}
// -->
</script>


This makes it nice and quick for me to stick submit-like buttons into forms that require user confirmation for the form to be submitted.

*BUT* how can I pass the name and value of what I've called a "confirm" element with the other form data (see the comment in the javascript)?

What I'd like to see in the callback data ($_REQUEST) from the given example would be:



"mytextbox" => [user inputted value],
"callback" => [either "do this" or "do that" depending on the source of the confirmation event]


Any ideas?

Thanks,
Mike.

mlse
12-08-2006, 12:41 PM
Hey, I fixed my own post! Lol!

Will post solution after my lunch incase anyone else is remotely interested!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum