Forum Moderators: coopster

Message Too Old, No Replies

seperating information inputed into multiple line text field?

         

norek

3:02 am on Oct 5, 2005 (gmt 0)

10+ Year Member



How do I seperate information from a multiple line text field?

For example, if I have the following:

Name of person
555-555-5555
123 Address Road,
City, ON K1J 9E8

Is it possible to seperate this so that when I submit my form, it will insert the name, number, address, city, province, postal code into different MySQL records?

Can I make it so that:
$name = THE_FIRST_LINE
$number = THE_SECOND_LINE
$address = THE_THIRD_LINE (without the final ",")
$city = PART_BEFORE_FIRST_COMMA
$province = PART_BETWEEN_FIRST_AND_SECOND_COMMA
$postalcode = LAST_7_CHARACTERS_OF_LINE_4

?

pniac

4:16 am on Oct 5, 2005 (gmt 0)



Try something like this:

<?php
$pieces = explode("
", $_POST['formfield']);

// here you transform the data in the field form into an array, with the items split for every new line

$name = $pieces[0]; // first line
$number = $pieces[1]; // second line
?>

etc. With strlen() and substr() you could take out the comma and select postal code etc.

Check also:
[php.net...]
[php.net...]
[php.net...]

(you could use strlen to find the length of the address, and then chop it off 1 character before it ends -- to get rid of the comma)

norek

5:47 am on Oct 6, 2005 (gmt 0)

10+ Year Member



I can get it to read the first line, but when it comes to $num, it stops working there... is my code below bad?

if ($add_quick == 'on') {
$pieces = explode("
", $_POST['dump']);

$title = $pieces[0];
$num = $pieces[1];
$street = $pieces[2];
$city = $pieces[3];
$province = $pieces[4];
}

norek

5:52 am on Oct 6, 2005 (gmt 0)

10+ Year Member



n/m, it worked when i did this...

$pieces = explode("\n", $_POST['dump']);

jatar_k

3:25 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the best way to do it is to make them multiple fields. The method you are using relies too heavily on users entering properly formatted data.