Okay.. Imagine someone fills out a form and this info is sent to a process page:
$name
$email1
$email2
$phone
Then all that info is displayed, if it is incorrect then they go back and do it again. If it is correct they click confirm and all the info is written to 2 separate .txt files and sent in an email.
I could guess at how to do this but it would take my weeks to se-bug it, so if anyone can help, I would be extremely gratefull.
Comments
1. Cut all of the code below and save it into a file called form.php. If you want to use another file name, make sure you change the "action" value in the html form.
2. Create a file named details.txt and put it in the same location as the form.php file. Again, if you want to use a different file name and path, make sure you change the first parameter (new name + full path) in the fopen command.
3. If you want to activate email sending, please uncomment the email command first
4. What it does is a. allow the user to enter name and email info, b. send an email (if the email comman is uncommented) to the admin and c. save the info to a file.
5. Load the form.php file and the details.txt file to your server and call it using a browser.
6. Let me know how it goes (it may be a crude little piece of code but I've finally got my butt to install Apache, MySQL and PHP in my laptop - so I've actually tested the script and it works )
This is the form:
But imagine, in order to get to the page with that form on, they clicked a link that was something like www.website.com/form.php?ProductName ...
Then, after the details are enterd and submitted, if there is an error they go back, if not the see a page with all their details on, if the think they are correct they click Submit again and then the details are written to a file named general.txt and a file named ProductName.txt
And all the details are sent in an email to one specific email address.
I know thats complicated and I understand it may not be possible... but please, any help is greatly appreciated.
Thanks in advance!
-CBG
1. User get to form by 2 ways - either:
a. www.website.com/form.php?ProductName or
b. www.website.com/form.php
2. If user got to the website through (a), then the information needs to be saved to 2 files (general.txt and productname.txt). If the user to the site through (b), then the information only needs to be saved to 1 file (general.txt)
3. When the user clicks submit, some checking neds to be performed - if there errors, show them the form again. If there are no errors, show them a confirmation page with all their information.
4. At the confirmation page, if they click on OK, the information gets saved, an email gets sent and a Thank You page is displayed.
Correct?
What I would need is in the error checks, to check that the ProductName field (hidden if possible) is not empty. If it is empty then its an error and it says "You Did Not Pick a Product!!!" and sends them back TWO pages to the page where they clicked the link that takes them to the form....
Ok???
I've got a wedding dinner to attend in an hour's time. Hopefully I'd still be sober when I get home. Otherwise, I'll get it coded up tomorrow for you.
And I'll put a link on the site too
1. I am attaching a zip
2. The zip contains 4 files - 2 PHP scripts and 2 empty text files where the user's information will be saved. If you rename the files, you will have to change the scripts to reflect the new names (which should be easy)
3. Upload all the 4 files into your server - put them together in the same location. If location needs to be different, you will have to modify the paths to the files in the scripts (which again, should be easy)
4. Test it out viewing form.php through a browser
Logic:
1. The user either gets to form.php by keying in the url in the browser or through a generated link (e.g. form.php?productname=abc)
2. The user keys in his information
3. The script does some checking - if there are problems, inform the user about the problems and force the user to rectify. I have only put in checking for a few fields - if you need more checking, just copy the existing checking to cover more fields
4. If there are no errors, show the details to the user for confirmation
5. When the user confirms, write the information to a file named repo_general.txt
6. If the user came in through a generated link, write the information to an additional file called repo_product.txt
Good luck - tell me how it goes...
If the user came in through the link website.com/form.php then that is an error becasue the ProductName field is empty.
And there will be lots of generated links such as:
form.php?productname=item1
form.php?productname=something2
form.php?productname=no3
form.php?productname=thisis4
So, if a user uses the form at form.php?productname=no3
then the info is saved to a general.txt file AND a file called no3.txt
So at some point it needs to check if that file exists. If not, create it and then add the line of info....
Sorry... Maybe i didnt explain it well enough before
1. If $productname is empty, don't proceed - display error message
2. If $productname is not empty, save in 2 files - general.txt and a file named after the product. The script needs to check if the file exists (i.e. if it's an existing product or a new product) - if does not exist, create a new file and save into the new file. If exists, save to the existing file
3. Will there be a situation in which data gets saved to general.txt only and not to a product file?
Also, could you make it so that its not called "product name"... For example, The links would be site.com/form.php?p=NAME
so the field is called "p" ...?
Thanks Ever So Much.
I will be linking from this site to yours and when I get more forum points, ill send some more to you too!
Hey, don't worry about the "links" and the "forum points"... I'm doing it for fun.
1. Zip file contains only 2 files - form.php and process.php. As usual, if you change the names of these files, you need to change the references to these files in the scripts too (very simple to do).
2. Upload both files to the same location in your server. If you need to put them in different directories, you will need to change the paths in the scripts.
3. Test out by calling form.php - http://www.yoursite.com/form.php?p=whatever and http://www.yoursite.com/form.php
4. The logic you requested will be performed
5. The script will write data into general.txt (if not found, the script will create one)
6. The script will also write data into <whatever>.txt (also, if not found, the script will create one). <whatever> will correspond to the parameter pass in through http://www.yoursite.com/form.php?p=whatever
7. The data files will be automatically created in the same directory as the scripts (i.e. form.php and process.php). If you need to keep the data files in a different directory, modify the path variable in the process.php file.
Hope it goes well. Appreciate if you could tell me the results.
I got these errors: I suspect I just need to chnage some CHMODS... But what files do I need to change the CHMOD of and what too?
You only need to worry about lines 12 and 18 - the other errors are caused by 12 and 18. Basically lines 12 and 18 are trying to create files to store the information. Creation is done using the fopen command - and both failed. Do you need to specify any settings in your host to allow the PHP scripts to create files?
In the worst case, if we cannot get this fixed, you could manually create the files and upload it to the server...
I dont believe there are any special settings or anything...
I'm sure I have fopen commands in a link directory.
I will check.
Edit:
I have this code in a link directory process page: If thats the same commands as this form process then at least we know it should work.
Are you sure its not just the CHMOD...
I can't help thinking thats what it means when it says "Permission denied"...
I spoke to someone else who knows a little PHP and they said to just try to change the Chmod anyway...
So I set the folder to 777 and it all works!
Thanks ever so much daboss!
Your a star!
And I will be putting a link on the site to yours because I never could ahve done this without your help and with any luck it's gonna be a big earner for me
Let me know your Url and link text!
If you want it in a database as Forge suggested, I only have to change a couple of lines in process.php - 10 minutes work. Give me a shout if you decide to use a database
Anyway, good luck.
If you do want to link to my site (:)), the details are as per my signature.
I ahve never set up or run a MySQL database. And, to be frank, I can't be arsed to work it all out.
As the old saying goes: Don't fix it if it ain't broke.
And text files have worked fine for me before...
As for the cosmetics, I know...
But I don't want it to look particulalry fancy. I will probably just put everything pretty much as it is into the layout.
Thanks Ever So Much, once again, daboss.