Find the answer to your Linux question:
Results 1 to 6 of 6
I want to make a web page that has a text box with a send button. How should the highlightened html line be edited to execute the script s1 when ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    5

    Help with HTML!

    I want to make a web page that has a text box with a send button.

    How should the highlightened html line be edited to execute the script s1 when the send/submit is pressed?

    HTML

    <textarea name="comments" cols="50" rows="6">
    Enter text here...
    </textarea><br>
    <input type="submit" value="send" >
    <form action="/usr/lib/cgi-bin/s1.sh" method="post">
    </form>

    To execute s2 what changes should be made to the following code/tag.
    s2 will print the first line to the screen.

    <action="/usr/lib/cgi-bin/s2.sh" method="post">


    Here is what happens when I enter text and press the submit/send button
    ****://img109.imageshack.us/img109/7418/screenshotui.png

    Feel free to suggest any idea!

  2. #2
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    action="s2.php" method="post"

    File: s2.php:
    <?php
    if (isset($_POST["SUBMITNAME"]) && $_POST["SUBMITNAME"] == "VALUE"){
    $parameter=" -xyz";
    exec("/usr/lib/cgi-bin/s1.sh$parameter");
    }
    ?>

    It's still possible that this is the same file as the html action page is.

    e.g.: I can't read anything on your screenshot ... it's just too small.

    /usr/lib/cgi-bin/s1.sh in an Action won't work because the explorer needs to be able to see that file ... and i assume that this file is on the server.
    So you need to start the script (via apache) on the Server ...
    The information itself can be passed as parameter or as stdin.

  3. #3
    Just Joined!
    Join Date
    Nov 2009
    Posts
    5
    Thanks for the reply.

    I am new to HTML and Ubuntu.
    I want the text entered by user to be processed by script s1
    which will be in /usr/lib/cgi-bin
    I have already configured apache 2.

    Script s1 will write to a file f1 whatever will be entered by user in textbox.

    Script s1:

    "Content-Type: text/html"

    read a
    $a >t f
    //write the contents of $a to the file tf


    Script s2 will be executed which will display the first line of text from the file f1.

    Script s2:

    head -n 1 tf

    Quote Originally Posted by zombykillah View Post
    action="s2.php" method="post"

    File: s2.php:
    Shouldn't it be s2.sh?

    <?php
    if (isset($_POST["SUBMITNAME"]) && $_POST["SUBMITNAME"] == "VALUE"){
    $parameter=" -xyz";
    exec("/usr/lib/cgi-bin/s1.sh$parameter");
    }
    ?>
    I think you have to omit '?' and I have done it without it.

    Here is a simpler tag. Your code in blue.
    <html>
    <head><title>Title</title></head>
    <body>
    <form action="/usr/lib/cgi-bin/form_reader" method="post">

    <php if (isset($_POST["SUBMITNAME"]) && $_POST["SUBMITNAME"] == "VALUE"){
    $parameter=" -xyz";
    exec("/usr/lib/cgi-bin/s1.sh$parameter");}>


    Enter data:<input type="text" name="data"><br>
    <input type="submit">
    </form>
    </body>
    </html>

    Still doesnt work.Opens the script in text form i.e doesnt process it.

    It's still possible that this is the same file as the html action page is.
    e.g.: I can't read anything on your screenshot ... it's just too small.
    Yes it opens the file s1 when after entering text I press submit.It should process and write to file tf

    It's still possible that this is the same file as the html action page is.
    e.g.: I can't read anything on your screenshot ... it's just too small.
    Edited .It opens script s1.
    ****://img109.imageshack.us/img109/7418/screenshotui.png
    In the end I am trying to write to the file tf but it doesnt write.

    /usr/lib/cgi-bin/s1.sh in an Action won't work because the explorer needs to be able to see that file ... and i assume that this file is on the server.
    So you need to start the script (via apache) on the Server ...
    I use mozilla in ubuntu and it opens the file as you can see in the screenshot above it however doesnt process.

    The information itself can be passed as parameter or as stdin.
    There should be a simpler way.

  4. #4
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    What you see in the firefox is just your script as file.
    With
    <form action="/usr/lib/cgi-bin/form_reader" method="post">
    You tell the browser, when any submit is done open the file defined with action.
    Meaning the browser will open that file.
    If you sit on a different computer where the file doesn't exist he will tell you file not found.
    Next problem is that the browser won't start any scripts on the server.
    But it is possible for the server to start scripts when there is data received from any browser.

    Here an example for you:
    file "index.php":
    PHP Code:
    <?php
    if (isset($_POST["SUBMITNAME"]) && $_POST["SUBMITNAME"] == "VALUE"){
    exec("echo \"".$_POST['data']."\" | /usr/lib/cgi-bin/s1.sh");
    ?>
    <html>
    <head><title>Title</title></head>
    <body>
    <form action="index.php" method="post">
    Enter data:<input type="text" name="data" value="<?php echo $_POST['data'];?>"><br>
    <input type="submit" name="SUBMITNAME" value="VALUE">
    </form>
    </body>
    </html>

  5. #5
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    Yes I know ... my example isn't secure ...
    You may wanna check for " before the execute.
    Of course you could also write
    PHP Code:
    exec("echo \"".$_POST['data']."\" > tf 
    I've found a page how to execute scripts direct:
    ____://httpd.apache.org/docs/2.0/howto/cgi.html
    However I've no Idea how to get the POST values in such an script ... sure is easy ...

  6. #6
    Just Joined!
    Join Date
    Nov 2009
    Posts
    5

    nothing

    Still couldn't find a way to run a script in html.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...