...

View Full Version : textfield as part of a command



btigas
09-13-2009, 07:37 PM
Greetings

I'm newbie to php. I am trying to add a textbox value as a part of a command each time i press a "Submit" button.
Can someone help me?
Thanx in advance.

Jazz914
09-13-2009, 08:54 PM
Could you explain a little more I don't get what you mean?

btigas
09-13-2009, 11:09 PM
Well, i created a php page to controll my lpt port. it works but there are so many values (255), so i cannot have 255 buttons, each for a value.

Here is my page


<?php
{
if (isset($_POST['up']))
shell_exec("sudo /var/www/html/up.sh");
}
if (isset($_POST['right']))
{
shell_exec("sudo /usr/local/bin/parashell 0x378 0");
}
if (isset($_POST['down']))
{
shell_exec("sudo /var/www/html/down.sh");
}
if (isset($_POST['left']))
{
shell_exec("sudo /usr/local/bin/parashell 0x378 254");
}
?>
<HTML>
<HEAD><TITLE>LPT Control</TITLE>
<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #0033CC;
}
body {
background-color: #CCCCCC;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></HEAD>
<BODY>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">

<p class="style1">LPT Control
<input type='submit' name='up' value="Up">
<input type='submit' name='down' value='Down'>
</p>
<p>
<INPUT type='submit' name='right' value='All Zero'>
</p>
<p>
<INPUT type='submit' name='left' value='All One'>
</p>
<p><INPUT type='submit' name='left2' value='Value Input'>
<input name="textfield" type="text" value="">
</p>
</form>
</body></html>


i want to create a text field to write the desired value ( 0 - 255 )
and by pressing a "Submit" button the value in the text box takes place in the shell_exec("sudo /usr/local/bin/parashell 0x378 XXX"); command and execute ( XXX = value 0 - 255)
Sorry for my bad english.... :D

Zangeel
09-14-2009, 12:08 AM
OK well lets say the textarea name is name = " textarea "

The code would be something like



<?php
if ( isset ( $_POST['textarea'] ) )
{
if (in_array($_POST['textarea'], range(0,255)))
{
shell_exec("sudo /usr/local/bin/parashell 0x378 " . (int) $_POST['textarea']);
}
}
?>


This checks if the textarea post data was sent, checks if the number is w number between 0-255, then executes the command.

btigas
09-14-2009, 12:14 AM
Zangeel
Thank you very much for your answer
I will try this first thing in the morning ( its 1:15 am over here)

btigas
09-14-2009, 10:31 AM
Unfortunately this error appears

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /var/www/html/test7.php on line 20

<?php
{
if (isset($_POST['up']))
shell_exec("sudo /var/www/html/up.sh");
}
if (isset($_POST['right']))
{
shell_exec("sudo /usr/local/bin/parashell 0x378 0");
}
if (isset($_POST['down']))
{
shell_exec("sudo /var/www/html/down.sh");
}
if (isset($_POST['left']))
{
shell_exec("sudo /usr/local/bin/parashell 0x378 254");
}
if ( isset ( $_POST['textarea'] ) )
{
if (in_array($_POST['textarea'], range(0,255)))
{
shell_exec("sudo /usr/local/bin/parashell 0x378 " . (int) $_POST['textarea']);
}
}
?>
<HTML>
<HEAD><TITLE>LPT control</TITLE>
<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #0033CC;
}
body {
background-color: #CCCCCC;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></HEAD>
<BODY>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">

<p class="style1">LPT Control
<input type='submit' name='up' value="UP">
<input type='submit' name='down' value='DOWN'>
</p>
<p>
<INPUT type='submit' name='right' value='All 0'>
</p>
<p>
<INPUT type='submit' name='left' value='All 1'>
</p>
<p><INPUT type='submit' name='valueadd' value='Value Insert'>
<input name="textarea" type="text" >
<p>
<p>
</form>
</body></html>


Help Needed!!!

btigas
09-14-2009, 11:07 AM
Zangeel
Thank you very much
Your Answer was correct



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum