Client Side Coding > HTML & CSS

Trouble with form and how to submit data using $_POST please help

(1/2) > >>

squilla23:
So here is my problem i am trying to have the form post a selected months index number +1 so i can return the month number to the input form?? Im pretty much a noob so as easy as possible explanation would be cool


<?php
      $monthName = array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
      "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
      
      function monthlist($monthName){
         global $monthName;
            foreach ($monthName as $index => $month)
               {
                  
                  echo "<option value='monthForm' >" .$month."</option>";
                  }
                        if (isset($_POST['monthForm'])){
                        $monthpick= $index+1;
                        echo $monthpick;
                         $_POST['monthNumber'];}
         }
      
         ?>

<html>
  <head>
  </head>
 
  <body>
    <form id="monthForm" name="monthForm" method="post" action="monthListStart.php">
      <p>Select a month:&nbsp;&nbsp;
       <select>
            <?php echo monthlist();?></option>
       </select>
      </p>
    
      
      <p>
        <input type="submit" value="What is the number for the month you selected?" name="submit" />
      </p>
      <p>You selected:&nbsp;<input type="text" id="monthNumber" name="monthNumber" /> </p>
      
      
    </form>
  </body>
</html>

richei:
1st - wrong part of the forum, needs to be in the php area
2nd - why do you need an array and a function for the months?  If its going to be a constant, then go ahead and hardcode it.

You don't have a multidemensional array and you're endng the foreach loop to soon, the only thing being recorded is the first month.

--- PHP Code: ---
function monthlist() {
    $monthName = array("Jan", "Feb", "Mar", "Apr", "May", "Jun",   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
     foreach ($monthName as $index)  {
         echo "<option value='$index'>$index</option>";
     }


--- End code ---

squilla23:
Sorry wrong forum, So what your saying is i should make the <option> and  hard code to the html rather than using the function. The part im really confused on is how do i post the selected month to the input id monthNumber?

Oh and thanks for the help i aprreciate it Im really having more trouble with php then any other of the languages for some reason.

richei:
You don't give the option a name, that's for the select tag

<select name='monthForm'>
            <?php echo monthlist();?></option>
</select>

Not sure what you're talking about with the input id, is that the month number or something?

squilla23:
what i mean is i need the selected month to show in the input area and display what the months number is I have tried all kinds of things but as i said before Its a little confusing at this point im sure it is something simple I am missing

Navigation

[0] Message Index

[#] Next page

Go to full version