EDIT: Here’s the "better" one.
First Page
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
</head>
<body>
<form id="routeME" name="routeME" action="routeME.php" method="post">
<input id="key" name="key" type="hidden">
<input id="funcA" name="funcA" type="button" value="A">
<input id="funcB" name="funcB" type="button" value="B">
<input id="funcC" name="funcC" type="button" value="C">
</form>
<script type="text/javascript">
$('form#routeME :button').click(function() {
$('#key').val($(this).attr('id'));
$('form#routeME').submit();
});
</script>
</body>
</html>
Landing Page
<?php
$value = $_POST['key'];
if (isset($value)) call_user_func($value);
function funcA(){
echo 'function A NEW!';
}
function funcB(){
echo 'function B NEW!';
}
function funcC(){
echo 'function C NEW!';
}
?>
Below is the first posting…
If you have an HTML form and you POST it to a .php page, how can you pick up what the link or class was that was clicked on? I’m trying to run a .php function on the landing page depending on what link was clicked on in a JQuery function on the POSTing page. Here’s what I’m doing right now.
First Page
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#funcA").click(function(){
$('form#routeME').attr({action: "routeME.php"});
$('#key').val('A');
$('form#routeME').submit();
});
$("#funcB").click(function(){
$('form#routeME').attr({action: "routeME.php"});
$('#key').val('B');
$('form#routeME').submit();
});
$("#funcC").click(function(){
$('form#routeME').attr({action: "routeME.php"});
$('#key').val('C');
$('form#routeME').submit();
});
});
</script>
</head>
<body>
<form id="routeME" name="routeME" action="routeME.php" method="post">
<input id="key" name="key" type="hidden">
<input id="funcA" name="funcA" type="button" value="A">
<input id="funcB" name="funcB" type="button" value="B">
<input id="funcC" name="funcC" type="button" value="C">
</form>
</body>
</html>
PHP Landing page
<?php
$value = $_POST['key'];
//echo $value;
if (($value=='A')) {
A();
} else if (($value=='B')) {
B();
}else if (($value=='C')) {
C();
}
function A(){
echo 'function A!';
}
function B(){
echo 'function B!';
}
function C(){
echo 'function C!';
}
?>
It’s doing what I want in a round about way but is there a better way to get what I want??
Thanks!
I believe you’re looking for the
call_user_funcfunctioncall_user_funcCalls the function with the name passed by$value, so if you submitted ‘A’, your script would run theA()function.EDIT: If you happen to know what “range” of functions to call, you could do a check I’ve commonly used.