form data being sent to file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Tue Jun 18, 2013 11:22 am

form data being sent to file

Postby maximom » Tue Jun 18, 2013 11:27 am

I have created form using php and want the information from the form to be sent to a file on my website.

Can anyone please tell me the coding to do this.


php-forum Active User
php-forum Active User
Posts: 382
Joined: Thu Mar 15, 2012 3:59 pm

Re: form data being sent to file

Postby landi » Wed Jun 19, 2013 2:56 pm


The array $_REQUEST will contain all your form field names and values. You can output it with print_r() or you could process each field with some code like this:

Code: Select all

    $sOut= ''; // Result string
    foreach ($_REQUEST as $sKey => $sValue) {
        // Add each form field to $sOut
        $sOut .= $sKey .'=' . $sValue . "\n";   
    //print str_replace("\n", '<br>', $sOut);
    // Output the result string to a file
    file_put_contents('/tmp/file.txt', $sOut);

Hope that helps

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests