| | |
help with creating form counter
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2005
Posts: 1
Reputation:
Solved Threads: 0
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
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
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.
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.
![]() |
Similar Threads
- Creating a time counter (Visual Basic 4 / 5 / 6)
- Need help creating a simple Counter program using classes (C++)
- Please help with email form script (PHP)
- Javascript, Form fields validation and submit (JavaScript / DHTML / AJAX)
- Posting values to a payment gateway without using a form (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: Case Help
- Next Thread: PHP Parse error: parse error, unexpected T_STRING
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl data database date directory display download dynamic echo email error file files folder foreach form forms function functions google href htaccess html httppost image include insert integration ip java javascript joomla limit link links login loop mail md5 menu mlm mod_rewrite multiple mysql mysql_real_escape_string oop parse paypal pdf php problem query radio random recursion regex remote replace script search server session sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video volume votedown web xml youtube





