LovinItAll Posted December 25, 2007 Share Posted December 25, 2007 Hi, I'm pretty new to PHP, so I hope this isn't a remedial question. I've written a script that contains several POST form elements. I'm attempting to evaluate the user selected form based on elements stored in GLOBAL $_POST. Here's a modified sample of the script with all of the salient elements (I tried to make it as readable as possible): <?php someFunction(); function someFunction() { $output = "<table align='center'><form action='' method='post'> <td><select name='chngAll' size=1>"; $output .= "<option value= selected=selected>Selection1</option>"; $output .= "<option value=1>Selection2</option>"; $output .= "<option value=2>Selection3</option>"; $output .= "<option value=3>Selection4</option>"; $output .= "</select> <INPUT type='submit' value='Change All' name='chngAll'> </td>"; $output .= "<tr><td height='35'><hr align='center'></td></tr></table>"; echo $output; $output = "<tr><table align='center'> <form action='' method='post'> <td><select name='chngThis' size=1>"; $output .= "<option value= selected=selected>Selection1</option>"; $output .= "<option value=1>Selection2</option>"; $output .= "<option value=2>Selection3</option>"; $output .= "<option value=3>Selection4</option>"; $output .= "</select> <INPUT type='submit' value='Change This' name='chngThis'> </td></tr>"; $output .= "<tr><table align='center'> <form action='' method='post'> <td><select name='chngThat' size=1>"; $output .= "<option value= selected=selected>Selection1</option>"; $output .= "<option value=1>Selection2</option>"; $output .= "<option value=2>Selection3</option>"; $output .= "<option value=3>Selection4</option>"; $output .= "</select> <INPUT type='submit' value='Change That' name='chngThat'> </td></tr>"; $output .= "<tr><td height=15></td></tr> <tr><td colspan='6'> <div align=center><form action='' method='post'> <input type='submit' value='ButtonA' name='buttonA' /></td></tr>"; $output .= "<tr><td height=15></td></tr> <tr><td colspan='6'> <div align=center><form action='' method='post'> <input type='submit' value='ButtonB' name='buttonB' /></td></tr>"; $output .= "</tbody></table></form>"; echo $output; } ?> If I select 'Change All', 'Change This', or 'Change That', the following elements appears in the global $_POST array: chngAll chngThis chngThat buttonA and buttonB do not appear. If I select Button A, the following elements appears in the global $_POST array: chngAll chngThis chngThat buttonA If I select Button B, the following elements appears in the global $_POST array: chngAll chngThis chngThat buttonB What I really want is for the element I select, and ONLY the element I select, to appear in $_POST, to wit: If I select Change All, I want the value in $_POST to be changeAll without the other values If I select Button B, I want the value in $_POST to be buttonB without the other values, etc. I can't figure out why there are multiple vars showing up in $_POST, and more confusing is why buttonX only appears if I select one of those buttons. I hope all this makes sense. Thanks in advance for any help you can provide. Happy Holidays to you and yours! Quote Link to comment https://forums.phpfreaks.com/topic/83134-solved-having-trouble-with-multiple-global-_post-vars/ Share on other sites More sharing options...
Barand Posted December 25, 2007 Share Posted December 25, 2007 Close the previous form with a /form tag before opening the next form. Quote Link to comment https://forums.phpfreaks.com/topic/83134-solved-having-trouble-with-multiple-global-_post-vars/#findComment-422869 Share on other sites More sharing options...
LovinItAll Posted December 25, 2007 Author Share Posted December 25, 2007 Thank you very much! Weird how buttonX's didn't need that, i.e. they didn't show up in $_POST unless they were selected. I can't tell you what an excellent Xmas gift you just gave me -- almost as good as the Snoopy (or Gumby) ties I'm sure to get from my girls! Thanks again, and have a Happy Holiday. Quote Link to comment https://forums.phpfreaks.com/topic/83134-solved-having-trouble-with-multiple-global-_post-vars/#findComment-422871 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.