Jump to content

Recommended Posts

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 :(

 

 

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 by Ch0cu3r
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.