php submit button display text file

hi i have the following code below. I have 2 drop down menus and a submit button. Depending on what is chosen from the drop down a certain text file will be displayed. Can someone help me out please

[size=8pt][php]







                                    <td>
                                            <form name="enviornment" onClick="this.form.submit()" default="ny" method="POST">
                                                    <select name="dropdown">
                                                            <option value="ny">10.10.10.10</option>
                                                            <option value="to">12.12.12.12</option>
                                                            <option value="ln">21.21.21.21</option>
                                                            <option value="hk">32.34.45.65</option>
                                                    </select>
                                                    <noscript><input type="submit" value="Submit"></noscript>
                                            </form>
                                    </td>
                                    <td>
                                    <script type="text/javascript">
                                            function loadQueryResults() {
                                            $('#mydiv').load('messages.txt');
                                            return false;
                                            }
                                    </script>
                                    </td>
                                    <td>
                                            <button type="submit" form="QueryForm" onclick="return loadQueryResults();">Submit Query</button>
                                            <DIV id="mydiv">...</DIV>
                                    </td>
                            </tr>
                    </table>
                <?php
            </script>
    </body>
[/php][/size]



New York
Toronto
London
Hong Kong



Deja Vu ! Thought we were doing this in the other post… Anyways…

So, first why two drop-downs? Use one. Change the options from:

10.10.10.10

to:

New York

When your processing section reads the drop-down select with " $city = $_POST[“dropdown”]; ",
it will grab the value, not the name. Therefore, in this example, it will pull the 10.10.10.10 as it’s value.

Then, in your code, you can use that number to pull the correct text file. Of course, this is IF you have
the various text files named differently for each city. Does that help some?

hi again Ernie,
sorry for mixing up 2 posts. So what i have at this point is the following below. So i have 2 dropdowns which depending on what you select and submit, a text file will display. So i need to check the 2 choice variables then tie them into displaying a file depending on what you have chosen.
so if you choose New York and 12.12.12.12 i would a file text file from the server retrieved which is called
NewYork-12.12.12.12.log

[size=8pt]
[php]

New York Toronto London Hong Kong 10.10.10.10 12.12.12.12 21.21.21.21 32.34.45.65 Submit Query
...
<?php [/php][/size]

So, as I said before, just use ONE dropdown.

Change the drop down’s options to be more like this:

New York

Then, read it using $city = $_POST[“dropdown”]; (Although I would change it’s name to city_dropdown or something that makes more sense…)

At that point, you already have the text file name inside the variable. Just use that to pass onto the
file load routine… should work nicely…

A couple other thoughts on this…

The user does not see the value of the drop downs. If they VIEW-SOURCE of the page, they will.
So, this is not really secure as anyone can get the city names and IP’s you have inside the values.
BUT, if these are public sites, no problem. If they are private, then just use a coding scheme and
process the files using PHP which the users can not see.

Hope that makes sense.

i understand. im trying to add a isset function to get what values were passed in as below, but my page is blank when i add that php section. What am i doing wrong there? thanks,

[size=8pt][php]

10.10.10.10 12.12.12.12 21.21.21.21 32.34.45.65 <?php if(isset($_POST['region']) ) { echo "bla"; ?> [/php][/size]

Well, your drop-down is named “dropdown”. It is inside the tag.

So, you are checking to see if “region” is set, not “dropdown”…

Either change the select to “region” for it’s name which is the best way.
Or, change the isset to check the “dropdown” field…

Good luck…

got it thanks. but how come when i add

[php]<?php
if(isset($_POST[‘region’]) ) {
echo “bla”;
?>[/php]

my page disappears when i refresh it. Is that not the proper insertion of the php inside the html ?

Well, this is because you did not close the IF clause…

It should be either this way:
if ( isset($_POST[“region”] ) echo “bla”;

or
if ( isset($_POST[“region”] ) {
echo “bla”;
//Plus any other code…
}

Either one command or multiples inside of braces…

this is odd. whenever i add the:

[php] if ( isset($_POST[“region”] ) {
echo “bla”;
//Plus any other code…
}[/php]

my page disappears. Could it be in the wrong spot?

Again… LOL Syntax ! ! !

if ( isset($_POST[“region”])) { echo “bla”; }

A missing para “)” after isset clause…

This time it was my typing error. Sorry for that…

ahhh yes. that part is good now. ok my dilema is this now. the reason i need 2 drop downs.
one drop down will be region which contains new york, london etc…
and the 2nd drop down, enviornment which will contain ip address.

so when you select new york then will be 4 sub choices for new york and when you select london there will
be 4 choices for servers for london etc… so in the end if you select new york and server ip 192.168.1.10 and click submit, the file newyork-192.168.1.10.log from the server will be retrieved and displayed on the web page. whew…ok. dont get tired of me yet please. :slight_smile: im almost there.
:slight_smile:

Ha! Never get tired of helping…

So, as most newbies do, you are over thinking the problem. Just add in the extra servers into one
dropdown. So, let’s say you have four IP’s for NY. Just list them separately kinda like this:
New York Server 1
New York Server 2
New York Server 3
New York Server 4
or
New York (10.10.10.10)
New York (10.10.10.11)
New York (10.10.10.12)
New York (10.10.10.13)

Again, the user will see the New York options, but, the value would be the IP you need to pull
data from. Then, inside of the code to grab the data, use the “value” of the drop-down.

That should work better than two drop downs. Then only reason it would not is if you have a
very large number of cities and servers that you need to list. In that case, you would need a
type of dynamic dropdown that would requery the database for the second dropdown. This can
be done also but is more tricky. So, hopefully that will work for you. By the way, how many
servers are you talking about monitoring? And, are they public servers or private. If private, you
should hide the IP addresses. That’s another topic…

ok so i got this below so far which looks good. I need to tie the submit button in with what the user chooses from the drop down menu. The submit button as you can see below is independent of the form :frowning:

[php][size=8pt]

<?php if(isset($_POST['region'])) { echo "Then go get region/ip file" } ?>
New York (10.10.10.10) London (10.10.10.11) New York (10.10.10.12) New York (10.10.10.13) Hong Kong (23.23.23.23) Submit Query
...
[/size][/php]

Well, this is where I got mixed up with the two different posts.
So, you are creating a dropdown with servers in it. When someone changes the setting on it,
you want the page to load the data into the DIV tag. This is done in the JQuery, not PHP.
This means that the code:

<?php if(isset($_POST['region'])) { echo "Then go get region/ip file" } ?>

is not needed. Instead, just use the JQuery code to display the new data.
So, to do this, you need to change the form for the dropdown to NOT submit. Change:

to:

Note: I renamed the form so it is not the same as the as JQuery will have issues with it. Also note: there is no action so it posts to itself and on onclick as you want to do that in the dropdown.

Change the tag, remove the form=“QueryForm” as I do not think you need that part.

Lastly, what happens is that when you press the SUBMIT button it runs the JQuery code instead of
submitting the form. Now inside there is where you must alter what is done with the server that is
selected by the user.

So, you switched from loading the data log from the fetchLog.php file to just a text file. I assume this
was just for testing purposes. What we would have to do is pass the selected file to the PHP file
and alter that file to grab the passed server address. Then, it should all work together.

Are you with me up to this point?

ok excellent, so this is what i have now below. Lastly i need to take what the user selects and add that to
the command.txt string in the jquery. so command.txt would be ‘choice selected.command.txt’

[size=8pt][php]

New York (10.10.10.10) London (10.10.10.11) New York (10.10.10.12) New York (10.10.10.13) Hong Kong (23.23.23.23) Submit Query
...
[/php][/size]

So, just change:

to:

This change will load the SELECTED value from REGION dropdown and add “commands.txt” to the end.
Then, it loads that…

hi Ernie
i tried changing the script section as shown below. I created a txt file called 10.10.10.10commands.txt
and tried to select the New York 10.10.10.10 option from the drop down hoping that it would retrieve
this text file, but its not showing. I tried renaming the file a few different ways but it didnt help. Can you
see what i screwed up? thanks.

[size=8pt][php]

NewYork(10.10.10.10) London(10.10.10.11) NewYork(10.10.10.12) NewYork(10.10.10.13) HongKong(23.23.23.23) Submit Query
[/php][/size]

LOL, we need to teach you how to debug…

So, whenever a step is not working, you need to back up one step and display the data just before
going into the step that fails. So, in this case, we need to see if my just created JQuery routine
works as it should. So, we know that the drop-down works. We know how it handles the values.
We know that the button works as it loaded the file without the added IP part.

Now, to debug this, we need to create an “ALERT” in the JQuery code. In this manner, we can see if it
is loading the correct name for the file. So, add an alert line in the code like below. Note that if you
need to debug PHP, you would just use a “DIE(something);” line, but, in JS or JQuery, you use “alert();”…
Just have to figure out what I did wrong in pulling the data out of the form…

EDIT: So, I found that sometimes the “child” option doesn’t work. So, they say to try “VAL” instead.
(I changed it to that to see if it works…)

So, change the JQuery like this and tell me what it shows…
[php]

[/php]
Note: as you see it should pop-up an alert that shows the value inside of the dropdown.

*** PLEASE notice my EDIT. Several sites say to use the .val instead of .children…***

ok so i changed it and i do get a pop up which says ‘undefined’. so the value from the dropdown in this case is undefined? i suspect maybe its not finding my txt file perhaps? My web debugger tells me

The requested URL /~admin/commgger/php/[object was not found on this server.

not sure if that helps..
Sponsor our Newsletter | Privacy Policy | Terms of Service