...

View Full Version : How to write to a file on submit button click?



ramki067
03-03-2008, 10:41 AM
Hi all,
I'm having 4 textboxes. The values of which needs to be written to a file when i click the submit button. How do i do that? Please help.

the code is below:


<font size=3 > Detailed Results </font>
<Input type="textbox" name="Det_Results" size="60"/>
<br><br>
<font size=3 > Test Summary </font>&nbsp;&nbsp;&nbsp;&nbsp;
<Input type="textbox" name="Test_sum" size="60"/>
<br><br>
<font size=3 > Ref FFT Location </font>
<Input type="textbox" name="Ref_fft" size="60"/>
<br><br>
<font size=3 > Build Path </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<Input type="textbox" name="bui_path" size="60"/>
<br><br><br>
<INPUT type="submit" value="Run Automation" onclick="" />


Thanks,
Ramki.

mlseim
03-03-2008, 04:30 PM
First you need to have a <form> line that specifies the PHP script to run
when the form is submitted:

<form action="myprocessingscript.php" method="post">
.
.
.
<input type="submit" name="submit" value="Save Data">
</form>


Then you have some decisions to make ...

In the PHP script called "myprocessingscript.php", it will open a text
file and append your data ... but append it on one line with a comma
separating the values, or what? Tell us what your file should look like?

I mention comma separation because it could be a .csv file that you
import into Excel?

Not enough information to answer your question.

Fumigator
03-03-2008, 04:30 PM
Look into (google, php manual, etc) the functions fopen() and fwrite().

ramki067
03-04-2008, 04:09 AM
First you need to have a <form> line that specifies the PHP script to run
when the form is submitted:

<form action="myprocessingscript.php" method="post">
.
.
.
<input type="submit" name="submit" value="Save Data">
</form>


Then you have some decisions to make ...

In the PHP script called "myprocessingscript.php", it will open a text
file and append your data ... but append it on one line with a comma
separating the values, or what? Tell us what your file should look like?

I mention comma separation because it could be a .csv file that you
import into Excel?

Not enough information to answer your question.

Thanks. I've a form element set to POST. My main objective is to write these textbox data to a file and parallely a WINDOWS command window should open and execute a perl file. Thats all.

The text file which the code has to write will be as below.



Input_File C:\Program Files\Apache Group\Apache2\htdocs\Automation_streams.txtt
Detailed_Results C:\Audio_Regress\files\Results_MPEG_48kHz_7405.txt
Test_Summary C:\Audio_Regress\files\Test_summary_MPEG_48kHz_7405.txt
Reference_FFT_Location C:\Audio_Regress\FFT\Ref\MPEG
Sync_Delay 0
Path cd /home/raghav/Phase2pt0_Blr/Brutus


where the text boxes will replace the values of Detailed Results, Test Summary,Reference_FFT_Location and Path as shown above.
Any help?

Thanks,
Ramki.

mlseim
03-04-2008, 01:36 PM
Here's the PHP script to write to a file, but not sure about the Windows/Perl thing ...



<?php

// Get form variables using POST method
$Det_Results=stripslashes($_POST['Det_Results']);
$Test_sum=stripslashes($_POST['Test_sum']);
$Ref_fft=stripslashes($_POST['Ref_fft']);
$bui_path=stripslashes($_POST['bui_path']);

// Open and write file
$myFile="datafile.txt";
$fh = fopen($myFile, 'w+') or die("can't open file");
fwrite($fh, "Input_File C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Automation_streams.txt
Detailed_Results $Det_Results
Test_Summary $Test_sum
Reference_FFT_Location $Ref_fft
Sync_Delay 0
Path $bui_path");
fclose($fh);

echo "file written\n";
?>


You also don't need this part in your form:
<INPUT type="submit" value="Run Automation" onclick="" />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum