Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6730075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:21:54+00:00 2026-05-26T10:21:54+00:00

Can you help me to write selected values from a form to a file

  • 0

Can you help me to write selected values from a form to a file with their id. I have html form:

<form name="frm1" method="post" action="form_to_write.php">
    <h4>q1</h4>
    <input type="radio" name="answer[1]" value="someValue1" />someValue1<br />
    <input type="radio" name="answer[1]" value="someValue2" />someValue2<br />
    <input type="radio" name="answer[1]" value="someValue3" />someValue3
    <h4>q2</h4>
    <input type="radio" name="answer[3]" value="someValue4" />someValue4<br />
    <input type="radio" name="answer[3]" value="someValue5" />someValue5<br />
    <input type="radio" name="answer[3]" value="someValue6" />someValue6
    <h4>q3</h4>
    <input type="radio" name="answer[2]" value="someValue9" />someValue9<br />
    <input type="radio" name="answer[2]" value="someValue7" />someValue7<br />
    <input type="radio" name="answer[2]" value="someValue8" />someValue8
    <input type="submit" value="submit" name="submit"/>
</form>

And my file form_to_write.php is:

$array = array_map("rtrim", $_POST['answer']);
$str = implode("\r\n", $array);
$date="date_not_work"; //date('m-d-y_H:i:s')
$fp = fopen($date."_out.txt", "w+");
$write=fwrite($fp, $str);
fclose($fp);

if ($write) echo 'Write is done!';
else echo 'Error!';

I need result in file like this:

1|value of 1
3|value of 3
2|value of 2

Now it write only values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:21:54+00:00Added an answer on May 26, 2026 at 10:21 am
    $str = '';
    foreach ($_POST['answer'] as $num => $answer) {
      $str .= "$num|$answer\r\n"; //i see no point in doing rtrim here
    }
    

    instead of

    $array = array_map("rtrim", $_POST['answer']);
    $str = implode("\r\n", $array);
    

    as for the date, it’s probably because of : symbols.

    make it "y-m-d_H-i-s" format.
    note the y-m-d order. this is way more reliable as it makes your files sortable by date

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope somebody can help me. I've been trying to write a custom html
Is there a c# library that can help to write and indent Javascript code.
can anyone help me write a linq query, its a bit confusing... Basically i
java experts can you please help me write detached queries as a part of
Can anyone help me with the trying to write SQL (MS SqlServer) - I
I have implemented a file selector with a combobox. I want to write the
I have a text read from a XML file stored in UTF8 encoding. C#
I have an HTML form which contains a drop down, a tinyMCE textarea, and
I am trying to create a UDF that takes the values from 4 selected
i am having trouble. i write HTML and jQuery and set same name attribute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.