Create CSV from form data...with a catch

Hi All:)
What I want to attempt is really out of my league - although I have had ‘some’ success from another post

I basically need to create a php script that will take form data and enter it into a csv file. This turnsout to be pretty straight forward…as much as it can for a complete novice…

Currently the script writes one value per column in the CSV file ie First Name, Last Name, etc… (these are example id’s from the above tutorial - my final form will have other id’s)

My problem is that I require more than one form variable to be written to ONE column in the CSV and these variables must be placed with specific classes.

So my resulting CSV would look something like this:

formvariable1,formvariable2,<div class=“one”>formvariable3</div><div class=“two”>formvariable4</div>,formvariable5

Does this make any sense?

Any help would really be appreciated :slight_smile:

What part do you need help with? It’s nothing different than that tutorial, you’re just concatenating a string. In the style of that example:

$formvariable1 = $_POST['formvariable1'];
$formvariable2 = $_POST['formvariable2'];
$formvariable3 = $_POST['formvariable3'];
$formvariable4 = $_POST['formvariable4'];
$formvariable5 = $_POST['formvariable5'];

$csvData = $formvariable1 . ',' . $formvariable2 . ',<div class="one">' . $formvariable3 . '</div><div class="two">' . $formvariable4 . '</div>,' . $formvariable5 . "\

Hi Dan,

The solution distilled in my mind over night whilst thinking about it over and over. Thank you very much for the reply and confirmation! I’ll give it another try and see how I progress.

It would honestly make more sense to apply the <div> and styling to the data as you lift it out of the csv file and display it. Keep data as data for as long as you possibly can, and keep your options open - is the rule of thumb.

I completely agree - keep data as data. How all this begun is that I am using a Wordpress plugin Catablog to catalogue a clients stamps website.

The plugin has a great import (via CSV) function but the styling must be contained within the CSV in order for it to display in the way that I have customised the layout for my client.

Once the data is uploaded it is uploaded and there is no way to modify it…unless you add the div’s one entry at a time to each description…which kinda defeats the point of importing to save time:(

My client is completely green to anything remotely complicated (like editing a CSV file) so I thought to use a simple form that he can use to generate the CSV.

phew…that was the long version…

Nice of you to explain, you didn’t have to.

There exists some “PHP programs” (actually, classes) that provide a front end to csv files I think. (imagine like PhpMyAdmin is to your database, forms that link to the csv file and allow non-programmers to edit the fields themselves)

[google]php csv edit class[/google]

One of the first links is to PHP Classes website. I hung around on there for years - amazed what people could do with PHP. The site is a bit of a pain to use and look at, and the coding of some of the classes is not always of the highest quality, but you will get lots of ideas. Most classes have a readme file or comments in the source code which tell you how to get started with it.

Always read the licence carefully before downloading any of the classes.

You may find it worth subscribing to the site just to get a weekly trickle of new classes which will keep pushing your horizons, even if you do not use them yourself.

Nice one Cups - thanks for the insights:)