kizofilax Posted April 18, 2009 Share Posted April 18, 2009 Hello im trying to update the values of a form using php my current code is this <html> <head> <?php function provincias($mes) { $mes = $_POST["month"]; $provinces = array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dic"); echo $provinces[$mes]; } provincias($mes) ?> </head> <body> <form id="monthForm" name="monthForm" method="post" action="monthAbbrev.php"> <p>Enter the number for the month of the year here (0 is January): <input type="text" id="month" name="month" /></p> <p> <input type="submit" value="What is the abbreviation?" name="submit" /> </p> <p>Answer: <input type="text" id="abbrev" name="abbrev" /></p> </form> </body> </html> So basically the user enters a number and that is mapped into the array and it gets the month which needs to be written in the answer textbox I know how to the the values using POST but is there a way to return the value and write it in the text box? Thanks Link to comment https://forums.phpfreaks.com/topic/154691-solved-how-to-write-data-into-a-form-using-php/ Share on other sites More sharing options...
beebosoft Posted April 18, 2009 Share Posted April 18, 2009 i would use "<?php echo($mes) ?>" in the textbox as the value. That is if i understand what you are trying to do. Link to comment https://forums.phpfreaks.com/topic/154691-solved-how-to-write-data-into-a-form-using-php/#findComment-813432 Share on other sites More sharing options...
kizofilax Posted April 18, 2009 Author Share Posted April 18, 2009 i would use "<?php echo($mes) ?>" in the textbox as the value. That is if i understand what you are trying to do. Ok now the text box has <p>Answer: <input type="text" id="abbrev" name="abbrev" value="<?php echo($mes) ?>" /></p> When the user enters a number, that number gets mapped into the array, say its the number "0" thats jan in the array. This jan is wha i need to appear in the textbox answer My php script does it really well, after the function i can do echo $provinces[$mes]; and i get "jan" but i cannot get it to show in the textbox. Already tried to use value="<?php echo($mes) ?>" but it doesnt work =( Any other suggestions? Thanks Link to comment https://forums.phpfreaks.com/topic/154691-solved-how-to-write-data-into-a-form-using-php/#findComment-813437 Share on other sites More sharing options...
kizofilax Posted April 18, 2009 Author Share Posted April 18, 2009 Ok i just solved this <html> <head> <?php function provincias($mes) { $mes = $_POST["month"]; $provinces = array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dic"); $_POST["abbrev"]="$provinces[$mes]"; } provincias($mes) ?> </head> <body> <form id="monthForm" name="monthForm" method="post" action="monthAbbrev.php"> <p>Enter the number for the month of the year here (0 is January): <input type="text" id="month" name="month" /></p> <p> <input type="submit" value="What is the abbreviation?" name="submit" /> </p> <p>Answer: <input type="text" id="abbrev" name="abbrev" value="<?php echo($_POST["abbrev"]) ?>" /></p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/154691-solved-how-to-write-data-into-a-form-using-php/#findComment-813446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.