从窗体获取用户输入,使用php写入文本文件 [英] Get user input from form, write to text file using php

查看:154
本文介绍了从窗体获取用户输入,使用php写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为订户收购的一部分,我期望从一个html表单中获取用户输入的数据,并使用php将其写入一个制表符分隔的文本文件。所写入的数据需要用制表符分隔,并附加下面的其他数据。



在点击表单上的订阅后,我希望它删除表单并在div中显示一条类似感谢订阅的小消息。

这将在wordpress博客上,并包含在弹出窗口中。

以下是具体的细节。

变量/输入是

  $ Fname = $ _POST [Fname]; 
$ email = $ _POST [emailPopin];
$ leader = $ _POST [radiobuttonTeamLeader];
$ industry = $ _POST [industry];
$ country = $ _POST [country];
$ zip = $ _POST [zip];

$ leader是一个两选项单选按钮,其值为'yes'和'no'。 / p>

$ country是40个左右国家的下跌。



所有其他值都是文本输入。



除了动作外,我已经完成了所有基本表单代码,我真的需要知道如何做的是:



如何使用php写入制表符分隔的文本文件,并在提交感谢信息后交换表单?



再次感谢您的帮助。

//您要写入的文件的名称
$ myFile =data.txt;

//打开要附加的文件(文件必须已经存在)
$ fh = fopen($ myFile,'a');

//为您的发布数据创建CSV列表
$ comma_delmited_list = implode(,,$ _POST)。 \\\
;

//写入文件
fwrite($ fh,$ comma_delmited_list);

//完成
fclose($ fh);

替换

中的<\\ p>,


As part of a subscriber acquisition I am looking to grab user entered data from a html form and write it to a tab delimited text file using php.The data written needs to be separated by tabs and appended below other data.

After clicking subscribe on the form I would like it to remove the form and display a small message like "thanks for subscribing" in the div.

This will be on a wordpress blog and contained within a popup.

Below are the specific details. Any help is much appreciated.

The Variables/inputs are

$Fname = $_POST["Fname"];
$email = $_POST["emailPopin"];
$leader = $_POST["radiobuttonTeamLeader"];
$industry = $_POST["industry"];
$country = $_POST["country"];
$zip = $_POST["zip"];

$leader is a two option radio button with 'yes' and 'no' as the values.

$country is a drop down with 40 or so countries.

All other values are text inputs.

I have all the basic form code done and ready except action, all I really need to know how to do is:

How to write to a tab delimited text file using php and swap out the form after submitting with a thank you message?

Thanks again for all the help.

解决方案

// the name of the file you're writing to
$myFile = "data.txt";

// opens the file for appending (file must already exist)
$fh = fopen($myFile, 'a');

// Makes a CSV list of your post data
$comma_delmited_list = implode(",", $_POST) . "\n";

// Write to the file
fwrite($fh, $comma_delmited_list);

// You're done
fclose($fh);

replace the , in the impode with \t for tabs

这篇关于从窗体获取用户输入,使用php写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆