Jump to content

[SOLVED] Having Trouble With Multiple GLOBAL $_POST Vars


Recommended Posts

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!

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.