...

View Full Version : Help With "Submitting" Button Actions



Feriscool
09-04-2011, 06:10 PM
This is the first time I've ever tried this so please bear with me. I created this with some html code:

http://i.imgur.com/twTo2.png

What I need this to do is when the person hits submit, it sends the text in each field to a file located on the web host. I need it to look something like this:
http://i.imgur.com/WFYxa.png

Here's the code I have (not sure if it will help):

<div id="welcom_pan">
<h2><span>submit your</span>VIDEO</h2><br>
<p><form>
YouTube Link to Video <br><input type="text" name="youtubelink" size ="50"/><br /><br />
Do you accept the rules (below)? <br><input type="radio" name="yes" value="yes" /> Yes <input type="radio" name="no" value="no" /> No<br /><br />
What's happening in the video?
</form>
<form method="post">
<textarea name="comments" cols="40" rows="5"></textarea><br>
</form><br>
<input type="submit" value="Submit" />
</p>
</div>

Anyone help?

Fou-Lu
09-05-2011, 12:49 AM
Okay and what have you tried? So far all we see is HTML code, what are you using to processing the input and write to a file?

Feriscool
09-05-2011, 01:51 AM
Okay and what have you tried? So far all we see is HTML code, what are you using to processing the input and write to a file?

Alright, so I basically got it working, but there are couple things wrong with it. How can I make each new submission create the text from the fields on the next line in the output file?


<?PHP

$filename = "output.txt"; #Must CHMOD to 666
$quantity = $_POST['quantity'];
$item = $_POST['item'];

$fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
if ($fp) {
fwrite ($fp, $quantity . ", " . $item);
fclose ($fp);
echo ("Thank you for submitting your video!");
}
else {
echo ("There was a problem submitting your video. Try again, or report the issue.");
}

?>

Fou-Lu
09-05-2011, 04:53 PM
Alright, so I basically got it working, but there are couple things wrong with it. How can I make each new submission create the text from the fields on the next line in the output file?


<?PHP

$filename = "output.txt"; #Must CHMOD to 666
$quantity = $_POST['quantity'];
$item = $_POST['item'];

$fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
if ($fp) {
fwrite ($fp, $quantity . ", " . $item);
fclose ($fp);
echo ("Thank you for submitting your video!");
}
else {
echo ("There was a problem submitting your video. Try again, or report the issue.");
}

?>

Add a PHP_EOL constant to the string you are inserting: fwrite($fp, quantity . ', ' . $item . PHP_EOL);.
Note that you probably want to open the file in append mode, not write mode.

Feriscool
09-05-2011, 05:18 PM
Add a PHP_EOL constant to the string you are inserting: fwrite($fp, quantity . ', ' . $item . PHP_EOL);.
Note that you probably want to open the file in append mode, not write mode.

It's still not creating a new line in the output.txt file so that when the next person submits more text in the forms, it just over-writes the existing text.

ASTP001
09-05-2011, 07:39 PM
$fp = fopen ($filename, "w");


change that to

$fp = fopen ($filename, "a");

according to fou-lou, that should fix it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum