dongmanni6916 2013-07-24 06:44
浏览 24
已采纳

PHP:操纵用户输入浏览器的数据

I would like for a user to be able to input data in a text field on my website. WITH this data I would like for them to be able manipulate it.

For example:

Let's say someone needs all the letters in a paragraph capitalized and on my website I have a PHP script that does just that. How do I create a means for them to use my script?

Like so:

  • paste paragraph into left text field
  • press 'action button' or in this example 'capitalize letters' button
  • text in left text field gets ran through the script and becomes all capitalized
  • text now appears in right text field

A better way to ask this I guess is how do I connect the users input with the script and display the output once it's been ran?

  • 写回答

1条回答 默认 最新

  • douye7033 2013-07-24 07:26
    关注

    You have to put your fields in a form in the HTML file, for example like this:

    <form method="post" action="script_that_does_the_action.php">
        Left paragraph: <input type="text" id="leftP" name="leftP"><br>
        Right paragraph: <input type="text" id="rightP" name="rightP">
    </form>
    

    and then in your script that does all of the action, you can fetch the user input like this:

    $userInput = $_POST['leftP'];
    //do the capitalization now here
    //store the result somehow. Maybe using sessions like this: $_SESSION["result"];
    //then you have to redirect the page back to where the text fields are for example using header("location: ");
    

    and now that you are back in the index page (if I may call it like that), paste the resulting value to the right field:

    <input type="text" id="rightP" name="rightP" value="<?php echo $_SESSION["result"]; ?>">
    

    Be sure that both of your files (the action script and index file) are in .php format, and that you start the session with session_start();

    That's only one example...the most basic one. If you want to make it in the proper way, I'd also suggest using javascript :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测