Worqy Posted May 6, 2011 Share Posted May 6, 2011 Hi! I have started a big project with some of my friends. Its some kind of CMS system. Now, for quick commands we wanted something like cmd on windows. Is it possible to build a script that would be something like cmd/a console. Of course it would be a webpage and not a separate window. I could do this myself with a input field and a form using the POST method. But I wouldn't wan't to refresh the page every time I run a command. So something that works like the input field, form with the POST method, but without needing to refresh every time. Ask if I didn't make it clear enough! Regards Kevin Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/ Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 I did something like this and I didn't want to reload my buttons or text so I used and iframe window as the command window. incubi Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1211538 Share on other sites More sharing options...
Worqy Posted May 6, 2011 Author Share Posted May 6, 2011 I did something like this and I didn't want to reload my buttons or text so I used and iframe window as the command window. incubi ok. I have a iFrame now, and another page with the content. I have made the textarea (log) and but now when I wan't a textline and a button (or to press Enter would be even more nice), how do i do to send the data? Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1211557 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 Are you asking that when you press Enter in the textarea the iframe updates or when you press Enter in the textarea the form submits? Pressing Enter in a textarea should insert a line break and that's what the users will expect it to do. incubi Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1211567 Share on other sites More sharing options...
Worqy Posted May 6, 2011 Author Share Posted May 6, 2011 Are you asking that when you press Enter in the textarea the iframe updates or when you press Enter in the textarea the form submits? Pressing Enter in a textarea should insert a line break and that's what the users will expect it to do. incubi I would wan't the Enter press to work the same way as a form posts. Ex: Non-iFrame: two fields, Username and Password, one button "Login" I enter the Username and Password, and press "Login". The page sends the data to another page where I check if its right and then redirects... iFrame: same two fields and button. This time it doesn't reload any page, it just edits the frame if the login was successful or not. so what I'm trying to say is, I will have one textarea that is a "log" for all content. Then a text field where I can write a command like "Connect to database", wand when I press Enter for example it could run a function called Connect... and then add the text "Connecting" to the "log".. Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1211645 Share on other sites More sharing options...
xyph Posted May 6, 2011 Share Posted May 6, 2011 Javascript (AJAX) would be the ideal way to do this. An i-frame would be an easier way. Simply direct the form to POST into the iframe, and set up the frames page to echo/query based on form values Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1211668 Share on other sites More sharing options...
Worqy Posted May 7, 2011 Author Share Posted May 7, 2011 Hi Here is a update of my project: Everything works well, I can run commands from the iFrame. But I need atm to use a button for it. How can I make "Enter" work as a submit button? EDIT: How can I make it so that text isn't saved to the textfield every time I submit it. Ex: I run the command "Create", "Delete", "Time". Now when I enter something, it suggests all of these because I have entered them before. Is there somekind of auto save that I can turn of for just this inputfield? Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1212025 Share on other sites More sharing options...
Worqy Posted May 7, 2011 Author Share Posted May 7, 2011 And now I found another thing I can't understand.. <?php $log = $_POST['txtLog']; $command = $_POST['txtCommand']; $action = "Nothing"; $words = explode(" ",$command); if(sizeof($words) == 2) { if($words[0] == "create") { if($words[1] == "new") { $action = "LOLOLO"; } } } // Add text to log $log = $log . "\n" . $command . " - " . $action; ?> <html> <head> </head> <body> <form method="post" action="test3.php"> <textarea cols="100" rows="20" name="txtLog" readonly="yes" style="background: black; color: white; font-family: COURIER;"><?php echo $log; ?> </textarea> <input type="text" name="txtCommand" style="background: black; color: white; font-family: COURIER;"> <button type="submit">Run</button> </form> </body> </html> when I input "create new" the output should be "LOLOLO" and it is. But when I input "ihiuui new" or "create asdasd" the output is still "LOLOLO". How can this be possible? Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1212040 Share on other sites More sharing options...
spiderwell Posted May 8, 2011 Share Posted May 8, 2011 i just copied your script directly and tried it on my MAMP server and it works as expected, only echoing lolol when you enter create new. here is cut n paste of the log: - Nothing blah new - Nothing - Nothing - Nothing create new - LOLOLO make new - Nothing create moo - Nothing freferf new - Nothing so god knows why you are getting errors!! Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1212098 Share on other sites More sharing options...
ldb358 Posted May 8, 2011 Share Posted May 8, 2011 okay the reason that it is saving the data and dropping down when you start typing the command is because this is a feature of your browser and because you are literally submitting the form. the best way to handle this would be with AJAX and with a framework like Jquery would be really easy to make as opposed to an iframe. if you really want to use your current solution add the autocomplete="off" attribute to your form tag. Edit: also remember to clear your form data Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1212119 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 autocomplete="off" is not w3c compliant though. Ajax is your best way. Avoid submitting the from altogether, and use javascript to do a pseudo-submit. This SHOULD avoid autocomplete issues. Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1212121 Share on other sites More sharing options...
Worqy Posted May 9, 2011 Author Share Posted May 9, 2011 EDIT fixed Quote Link to comment https://forums.phpfreaks.com/topic/235711-cmd-made-in-php/#findComment-1212777 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.