Jump to content

Batch process multiline input from textarea


soycharliente

Recommended Posts

I'm trying to create a form that would batch process data rather than using one form to submit multiple entries.

 

I'm having trouble just splitting the data between each line. I've tried two different ways so far and neither do what I want. Right now I'm just trying to split each line into an array element. I'm taking it in steps.

 

First way:

/* Batch button */
if (isset($_POST['BatchSubmit']) && $_POST['BatchSubmit'] == 'Add')
{
foreach ($_POST as $key => $val) { $_POST[$key] = makeSafe(trim($val)); }

$batch = $_POST['batch'];
$lines = explode("\r\n", $batch);
print_r($lines);
}

 

Second way:

/* Batch button */
if (isset($_POST['BatchSubmit']) && $_POST['BatchSubmit'] == 'Add')
{
foreach ($_POST as $key => $val) { $_POST[$key] = makeSafe(trim($val)); }

$batch = nl2br($_POST['batch']);
$lines = explode('<br />', $batch);
print_r($lines);
}

 

Any help with a function I should look at? Thanks.

I don't know why it's working now, but it is. Maybe it's the single quotes. Before I was using double.

$lines = explode('\r\n', $batch);

 

The issue I'm having now is when there's an error, I output the input back into the textarea. However, it inserts \r\n into the text.

 

How can I get it to display exactly how it was inputted?

Are you saying I should NOT use single quotes? It didn't explode properly when I did use double quotes. It works as wanted when I use single. When I pull the information from the $_POST array, it has those literal characters in it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.