/    Sign up×
Community /Pin to ProfileBookmark

Comments Form

Hi there,

I want to make a couple of comments forms and possible a petition page for my site…

Anyone know where I can find a tutorial?

Cheers
hamstar

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@gaston9x19Apr 18.2005 — Are you gonna want the results of the form and petition to be saved in a database or emailed?
Copy linkTweet thisAlerts:
@hamstarauthorApr 18.2005 — well, i dont really wanna do a database i was hoping to save it to a file on the server... or to a page maybe...
Copy linkTweet thisAlerts:
@gaston9x19Apr 18.2005 — That's doable too, PHP can create and write to files. Have a look at this thread, I posted an example showing how to get form data to write to a file:

http://www.webdeveloper.com/forum/showthread.php?t=63008

Let me know if you have any questions.

P.S. Oh, yeah, the same code that writes to "blank.php" will also create "blank.php" if it doesn't already exist. This example page was supposed to read from the file first though, so you have to create the file to read from.
Copy linkTweet thisAlerts:
@hamstarauthorApr 19.2005 — OK, I've had a look around and I can seem to see anything that helps my cause.

Heres what I want to do in deeper detail.

A user types in comments, and a name. This is sent through GET (I might change it to POST however) from test.php to someform.php.

someform.php grabs the data and also grabs the time and date through the date() function.

Then the data is put into an array.... Now heres where I'm stuck.

I have to open a file called /addons/array as code.

This file contains my $arrays and all the data in them ($namearray, $datearray, $timearray, $commentsarray)

I have tried using fopen() and file_get_contents to pull the data but no such luck.

From what I have seen fgets pulls the data to display it in a printable format.

How can I make it so I can have it as data that the user never sees?
Copy linkTweet thisAlerts:
@bokehApr 19.2005 — file() will grab the file contents to an array

and

file_get_contents() grabs it to a string.

When you say the file contains arrays what do you mean?

Are you hoping to modify this file or just use its contents?
Copy linkTweet thisAlerts:
@hamstarauthorApr 20.2005 — When you say the file contains arrays what do you mean? [/quote]
As in all the code for the arrays and the arrays data is contained in the file.

Are you hoping to modify this file or just use its contents?[/quote]
Both, I have to get the files contents, and append to them.
Copy linkTweet thisAlerts:
@bokehApr 20.2005 — Well it would be helpful to see that file so we can see how it is consructed.
Copy linkTweet thisAlerts:
@hamstarauthorApr 20.2005 — Well... heres the array file:
<i>
</i>$namearray[];
$commentsarray[];
$datearray[];
$timearray[];

$namearray[0]="Harry";
$namearray[1]="Dennis";
$namearray[2]="Dale";
$namearray[3]="Debbie";

$datearray[0]="10/04/05";
$datearray[1]="11/04/05";
$datearray[2]="12/04/05";
$datearray[3]="13/04/05";

$timearray[0]="4:44pm";
$timearray[1]="5:23pm";
$timearray[2]="6:42pm";
$timearray[3]="7:34pm";

$commentsarray[0]="Yeah man, you don't let those bastards push us around this site is great!";
$commentsarray[1]="Great site man";
$commentsarray[2]="YEAH! You sock it to those monopolistic bastards!";
$commentsarray[3]="Hey, you're a wanker!";


And the code to write stuff is like this:
<i>
</i>$name=$_GET['name'];
$_GET['comments'] = str_replace("n", "&lt;BR /&gt;", $_GET['comments']);
$comments=$_GET['comments'];
$date=date("d/m/Y");
$time=date("g:ia");

$arraysize=count($namearray);

$namearray[$arraysize+1]=$name;
$commentsarray[$arraysize+1]=$comments;
$datearray[$arraysize+1]=$date;
$timearray[$arraysize+1]=$time;


And finally the code that prints it to the page.

for($i=0; $i=$arraysize; $i+1)
{
print "This was posted by $namearray[$i] on $datearray[$i] at $timearray[$i]./n"
print "$commentsarray[$i]/n"
}


Yeah.. basically structured the same way as a js assignment I had to do once. ?
Copy linkTweet thisAlerts:
@hamstarauthorApr 26.2005 — come on guys, this is like what PHP is best for. Doesn't anyone know how to do it?
Copy linkTweet thisAlerts:
@BigMoosieApr 26.2005 — I'm not an expert on PHP but I have doen similar things in JavaScript with cookies, what I would do is use whatever mehtod is similar to the escape() function in JavaScript and add the data to the end of the file like so:

*name*date*time*comments

*name2*date2*time2*comments2

(use whatever special character you want to separate the values);

to read from it then you take it as a string with PHP you can use a loop to set up new arrays from it and then a loop to display the data of the arrays.
Copy linkTweet thisAlerts:
@X-rayApr 26.2005 — come on guys, this is like what PHP is best for. Doesn't anyone know how to do it?[/QUOTE]

You're actually making things way to complicated...

I think that BigMoosie is right, that or pregenerating the html code and storing it directry into the file...

About BigMoosie's idea:
[code=php]
<?PHP
$content_array = file("whatever_the_file_is.dat");
$count = count($content_array)
for($i=0;$i<$count;$i++){
$array_parts = explode("*",$content_array);

$name[$i] = $array_parts[0];
$date[$i] = $array_parts[1];
$content[$i] = $array_parts[2];
$rate[$i] = $array_parts[3];
$URL[$i] = $array_parts[4];
}

//here output...
echo "
<table>
<tr>
<td>Name</td><td>Date</td><td>Content</td><td>Rate</td><td>URL</td>
</tr>
";
for($i=0;$i<$count;$i++){
echo "
<tr>
<td>$name[{$i}]</td><td>$date[{$i}]</td><td>$content[{$i}]</td><td>$rate[{$i}]</td><td>$URL[{$i}]</td>
</tr>";
}
echo "
</table>
";
?>
[/code]
×

Success!

Help @hamstar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...