Page 1 of 1
Get data from Selection List
Posted: Sat Jan 07, 2012 11:44 am
by dmallia
I made this form.
Code: Select all
<form method="post" enctype="multipart/form-data">
<select name="file" style="width: 150px">
<option value="1">pbsv.cfg</option>
<option value="2">server.cfg</option>
</select>
<input type="submit" name="load" value="Load">
</form>
now using php I am going to set a variable named $selected and in that variable I want to store the value that the user selects. Does anyone knows how I can get the selected data?
Re: Get data from Selection List
Posted: Sat Jan 07, 2012 12:48 pm
by califdon
What PHP script will receive the data from this form? You haven't provided an
action= parameter, so your code will default to calling the same script again. If this is what you intend, then your script will have to have some code to determine whether it should just display the form (the first time it is called) or whether it should look for user form data and take some action based on that. You should probably read some tutorials on using POST variables, such as
http://www.html-form-guide.com/php-form ... -post.html. Basically, the script that handles the form data will find the value selected in the $_POST array, using the index "file" (the name you have assigned to the select element of your form).
Re: Get data from Selection List
Posted: Sun Jan 08, 2012 10:42 am
by dmallia
so i made this script.
Code: Select all
<?php
$fn = "test.txt";
if (isset($_POST['content']))
{
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
}
?>
and under that i have this form
Code: Select all
<form method="post" enctype="multipart/form-data">
<textarea name="content"><?php readfile($fn) ?></textarea><br />
<input type="submit" name ="save" value="Save">
</form>
now i created a drop down list
Code: Select all
<form method="post" enctype="multipart/form-data">
<select name="file" style="width: 150px">
<option>test1.txt</option>
<option>test2.txt</option>
</select>
<input type="submit" name="load" value="Load"></a>
</form>
and would like to add it to the php script above, so I can choose the file i want to edit.