Fri, 17 May 2024
NetArt Media     Pay 2, Get 3!    


Processing Form Textarea Lists

By: Anton, NetArt Media
Wed, 1 August 2018
Processing Form Textarea Lists

HTML Form Textarea Bulk List - PHP Processing


I like to process bulk lists from HTML textarea fields, as it can save a lot of time and effort compared to entering things in individually. This article first shows you how to process a textarea list for a simple return, with each entry broken into a different line at the bottom of a page. As helpful as this is, however, I also provide an idea of how to enter each line of data into a MySQL database table, each being stored on it's own particular row inside the table.


The code block above contains all the necessary elements for processing a textarea with a bulk list of data entered into it. The code is configured to look for new lines in the field, so keep that in mind if you plan on ever using this example.

If I was to enter a list of names like so into the textarea field - Jeff, Janice, John, Lisa, Dan, but all typed in on their own lines and without the comma, this would be the result...

Jeff
Janice
John
Lisa
Dan

Textareas won't naturally process in this fashion, so turning the list of names into an array and configuring a foreach statement needs to be carried out before you will get a similar result.

The code looks for carriage returns in the textarea. The process may vary according to operating systems, but I have found it it work on both Windows and Linux servers, so far. Notice that I replaced the 'n' with an 'r'. While this may not be necessary for a simple return on a web page, it does need to be used when processing the bulk list array for a MySQL database table. If it isn't used, the 'n' will show up in a SQL file. I learned this the hard way, so following my example should save you some headache.


Above is a block of code that works well for inserting each name, written onto it's own line in the textarea field, into a separate database table row. It's important to have your id column configured to AUTO INCREMENT in order for a new id to be inserted into the table with each particular name.


Category: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox