0

I'm working on a project for my school for modifying basic wireless parameters in a linux router with commands just using HTML GUI. I worked mostly with php. So far i've been going fine but now i'm stuck and i cannot find any clear solution for my little problem.

I have the following drop down:

<form method="post" action="changefrequency.php">
<select name="freq">
<option value="auto">Auto</option>
<option value="2412">Channel 1</option>
<option value="2417">Channel 2</option>
<option value="2422">Channel 3</option>
<option value="2427">Channel 4</option>
<option value="2432">Channel 5 </option>
<option value="2437">Channel 6</option>
<option value="2442">Channel 7</option>
<option value="2447">Channel 8</option>
<option value="2452">Channel 9</option>
<option value="2457">Channel 10</option>
<option value="2462">Channel 11</option>
<option value="2467">Channel 12</option>
</select>
  <input type="submit" value="Set Frequency"/>
</form>
</div>

I post the value let's say option 2432 (channel5) to a router via php scripting with the command inside it using FTP upload and it works fine. I have made a script which automatically download in a txt file the frequency. So let's say user selected from the HTML and submited in the drop down channel 5 with value 2432 i will get locally saved a txt that has 2432 or frequency=2432 inside it.

Now my question is how can we check what value will it be inside the txt file and put it as default value for my dropdown? So any time the user changes the frequency the default value will be change in the dropdown menu.

thanks!

La Erti B
  • 5
  • 7

3 Answers3

0

Read the file with file_get_contents

Then use PHP to send HTML with the correct default option pre-selected

Anthony Astige
  • 1,919
  • 1
  • 13
  • 18
  • i know file_get_contents, i can show it in another text frame for example: the frequncey is: 2432, the idea is how to make the DEFAULT VALUE of the drop down – La Erti B Jun 26 '16 at 19:35
  • Thanks for trying to help but the dafault value it must be read from the txt file. Default Value must be dynamically changed so as many times the user opens let's say index.html the .txt file must be read and the default value to be changed or checked. Any idea how to do this? – La Erti B Jun 26 '16 at 19:42
0

Use file_get_contents into $val, and then use

<option value="2412" <?php if($val == '2412'): ?>selected<?php endif; ?>>Channel 1</option>

Of course, this is tedious to do for every single frequency so I suggest you store all these in an array like

$frequencies = ['2412' => 'Channel 1', '2417' => 'Channel 2'];

etc and then iterate to print out the options like

foreach($frequencies as $k => $v):
    if($k == $val)
        $selected = 'selected';
    else
        $selected = '';
    echo '<option value="' . $k . '" ' . $selected .' >' . $v . '</option>';
endforeach;
phreakv6
  • 2,135
  • 1
  • 9
  • 11
0

$freqNumber = file_get_contents("mytextfile.txt"); (see answer from Anthony Astige) I suppose in the following lines, that $freqNumber just contains the number, if not, you have to adjust it with php.

Then you have to check where to add the "selected", which tells html which one is the default value which is selected. You can do this in the following way:

<option value="2412" <?php if($freqNumber == 2412){echo " selected";} ?>>Channel 1</option>

You can do this for every option.