damion Posted March 14, 2014 Share Posted March 14, 2014 I have a contact form with 4 fields, and a one field newsletter signup form (email only) and I would like to keep things tidy and have only one csv file. Ideally each writing to seperate tabs in the file. Can this be done? Thanks Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 14, 2014 Share Posted March 14, 2014 Your question is does not make sense you could you explain it more clearly. Quote Link to comment Share on other sites More sharing options...
damion Posted March 14, 2014 Author Share Posted March 14, 2014 Sure! Thanks for your time. I have 2 forms on one page - a contact form that has basic fields (ie. name, email address, message, etc.). This one is only on my contact page. Then I also have another form which is even more basic. This one only has an email field with a submit button (this is for newsletter signups and is on all my page footers). Instead of having the contact form write to one csv file, and the newsletter form write to a second csv file, is it possible to have both forms write to one file (form action="combinedFormData.php") and in the file could there be functionality to understand which form was submitted and then do what's required to process it. Once I get that far, I think the best way in an organizational standpoint is to have each form write to its own tab in the csv file rather than blend everything together in a single column? Then of course I'll need a way to access/view the information (seperatley) like someone normally would - sorry about that Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 14, 2014 Share Posted March 14, 2014 (edited) Instead of having the contact form write to one csv file, and the newsletter form write to a second csv file, is it possible to have both forms write to one file Yes and in the file could there be functionality to understand which form was submitted and then do what's required to process it. yes, add a hidden input field for what type of form has been submitted, eg <input type="hidden" name="type" value="newsletter" /> <!-- add this field for newsletter form --> <input type="hidden" name="type" value="contact" /> <!-- add this field for contact form --> Now in combinedFormData.php you'd do something like this to determine what form was submitted switch($_POST['type'])) { case 'contact': // code to add contact info to csv file break; case 'newsletter': // code to add newsletter info to csv file break; default: // display error, invalid type defined } You'd then write the data to the file using fputcsv. You may want to add a type field so you know weather it is a contact or newsletter. Once I get that far, I think the best way in an organizational standpoint is to have each form write to its own tab in the csv file rather than blend everything together in a single column? Then of course I'll need a way to access/view the information (seperatley) like someone normally would - sorry about that You can then easily read the data from the csv file using fgetcsv. Edited March 14, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
damion Posted March 17, 2014 Author Share Posted March 17, 2014 Thank you for that, great info and it makes sense. This is a tough one for me to get to work Ch0cu3r. Been at it a good part of the weekend, but not giving up quite yet! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.