User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,058 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,269 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1885 | Replies: 1
Reply
Join Date: Jul 2005
Posts: 1
Reputation: onemanarmy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
onemanarmy onemanarmy is offline Offline
Newbie Poster

help with creating form counter

  #1  
Jul 25th, 2005
hello,

i am creating a web form and i would like to use some kind of counter to create a 'form number' or something similar.

what i did so far was using php to read a txt file on the server, insert that value into a hidden field. (i made the form so that when it is submitted, all the results are sent via an HTML based email...no mysql was used). and then that value is increased by 1, and saved again.

the above works fine, but my problem is that if a form is NOT submitted, the value would increment, and i dont want that. so, i am asking for some advice on how to make it so that it will increment only when the form is successfully submitted.
and i should also mention that i used some javascript for basic form validation....is that a problem? i am still a novice in php.

any tips/suggestions would be most appreciated.

thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: help with creating form counter

  #2  
Jul 25th, 2005
Are you wanting a counter to tell you how many times the form has been submitted? You have some options.

One thing you could do is simply use your website stats to see how many times your submission or thankyou page has been loaded. This requires that you submit your form to a specific page or that you redirect the browser after the HTML form is emailed to a specific page.

Another option is to go with your own counter like you are doing now. This could be stored in a database or a file--like you are doing now. Instead of loading the counter and incrementing it on the page that creates the form, do it on the page (or in the code section) that processes the form.

For example:

[HTML]
<form method="post" action="thankyou.php">
<input name="first_name" type="text" />
<input name="last_name" type="text" />
<input name="email" type="text" />
</form>
[/HTML]

thankyou.php[PHP]
<?php

/*
You can access your form variables through $_POST[].
*/
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];

/*
Now do your counter thing here. Read in the number, increment it by one
then write it back to the file. You already know how to do that, so I'll not
code it here.

Insert code to email the form results to whoever you want.
*/

?>

<h1>Thank you, <?= $first_name ?>!

[/PHP]

Something like that.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC