Jump to content

[SOLVED] How to write data into a form using php ?


kizofilax

Recommended Posts

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

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

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.