如何从PHP中检索HTML文本框的内容以响应按钮单击?

如何从PHP中检索HTML文本框的内容以响应按钮单击?

问题描述:

What is the best way to put a text box on the following HTML page and then, without reloading the page, get its content in PHP when the user clicks the button?

<?php require_once "phpuploader/include_phpuploader.php" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Simple File Upload - use SaveDirectory property</title>
    <link href="demo.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="demo">
        <h2>Attach some files</h2>
        <p>Attach some files using the button below.</p>
        <ul>
            <li>Allowed file types is set to: jpg, gif, png, zip 
                       - multiple files (Max 10M)</li>
        </ul>

        <?php
            $uploader=new PhpUploader();

            $uploader->MultipleFilesUpload=true;
            $uploader->InsertText="Upload Now";

            $uploader->MaxSizeKB=10240;
            $uploader->AllowedFileExtensions="jpeg,jpg,gif,png,zip";

            $uploader->SaveDirectory="savefiles";

            $uploader->Render();
        ?>          
    </div>
</body>
</html>

I know I can use form and Post but I want to stay on the same page.

Technically if you make the form post to itself, you will stay on the same page. That aside, your only solution is AJAX.

It's been a while since I used PHP, but I'm guessing your going to need AJAX if you want to avoid a full on postback.

The following link might help you out:

http://www.w3schools.com/PHP/php_ajax_database.asp

Well the simplest answer is just to submit to the same page:

<form action=""></form>

If you do this and add your form processing code at the top of the PHP file, you can submit, process the POST variable, but stay on the same page too.