weeder Posted August 12, 2008 Share Posted August 12, 2008 I am new to php and getting the hang of the basic stuff but this i have failed Have 3 radio buttons and looking to call a function print "<h3>Banks</h3><br /> <form action='bank.php' method='post'> <input type='radio' name='money' id='1' value='1' /> Money<br /> <input type='radio' name='crystal' id='2' /> Crystal<br /> <input type='radio' name='ruby' id='3' value='3' /> Ruby<br /> <input type='submit' value='bank' /></form>"; Need to call button 1 function money() button2 function crystal() button3 function ruby() All the functions are in the same file and all work ok I just can't get the radio buttons to call functions any help will be greatly apreceated Quote Link to comment https://forums.phpfreaks.com/topic/119332-radio-button-function-call/ Share on other sites More sharing options...
akitchin Posted August 12, 2008 Share Posted August 12, 2008 you'd be better off naming them the same, and giving them the respective value they represent. this will allow you to use the radio as it was meant to (restricting the selection to one option): <?php if (isset($_POST['submit']) { {$_POST['fn']}(); } print "<h3>Banks</h3> <form action='bank.php' method='post'> <input type='radio' name='fn' id='fn' value='money' /> Money <input type='radio' name='fn' id='fn' value='crystal' /> Crystal <input type='radio' name='fn' id='fn' value='ruby' /> Ruby <input type='submit' value='bank' /></form>"; ?> please use code tags in the future. Quote Link to comment https://forums.phpfreaks.com/topic/119332-radio-button-function-call/#findComment-614707 Share on other sites More sharing options...
KevinM1 Posted August 12, 2008 Share Posted August 12, 2008 First, give your submit input a name, so you can reference it directly within your PHP code. Then, in bank.php, do something along the lines of: <?php if(isset($_POST['submit'])) //this assumes you named your submit input 'submit' { if(isset($_POST['money'])) { //execute money code } else if(isset($_POST['crystal'])) { //execute crystal code } else if(isset($_POST['ruby'])) { //execute ruby code } else { //any error reporting you need to do?? } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/119332-radio-button-function-call/#findComment-614712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.