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

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 "" .$month.""; } if (isset($_POST['monthForm'])){ $monthpick= $index+1; echo $monthpick; $_POST['monthNumber'];} } ?>

Select a month:   <?php echo monthlist();?>

  <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>

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]
function monthlist() {
$monthName = array(“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”);
foreach ($monthName as $index) {
echo “$index”;
}
}
[/php]

Sorry wrong forum, So what your saying is i should make the 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.

You don’t give the option a name, that’s for the select tag

<?php echo monthlist();?>

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

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

If you want to keep the month as the value, you’ll need to use a switch or a lot of if statements to determine the month’s number. If you want to use the number as the value, then you can just display the echo’d POST for that field or use an ajax script with another switch.

If you want to happen after everything is done and submitted, then use a regular php script. If you want to happen when the person selects the month, then use ajax.

Sponsor our Newsletter | Privacy Policy | Terms of Service