How to process data before sent to database.

N6REJ 18 May, 2016
I' have a very simple text area that will receive a block of data like this...
D7170         C2016 05 06.07433 08 38 24.05 +46 51 03.5          16.1 R      H45
D7170         C2016 05 06.07517 08 38 24.37 +46 51 03.2          16.1 R      H45
D7170         C2016 05 06.07633 08 38 24.81 +46 51 03.1          16.3 R      H45
D7170         C2016 05 06.07708 08 38 25.08 +46 51 02.8          16.1 R      H45
D7170         C2016 05 06.07798 08 38 25.41 +46 51 02.4          16.2 R      H45
D7170         C2016 05 06.07891 08 38 25.77 +46 51 02.1          16.2 R      H45
O8590         C2016 05 06.07976 08 13 20.63 +62 47 47.5          18.3 R      H45
O8590         C2016 05 06.08055 08 13 20.93 +62 47 49.4          18.4 R      H45
O8590         C2016 05 06.08129 08 13 21.21 +62 47 51.7          18.5 R      H45
O8590         C2016 05 06.08205 08 13 21.57 +62 47 54.6          18.3 R      H45
O8590         C2016 05 06.08312 08 13 22.22 +62 47 57.6          18.4 R      H45
O8590         C2016 05 06.08413 08 13 22.64 +62 47 59.6          18.2 R      H45
B5916         C2016 05 06.08508 08 17 02.10 +31 39 33.7          17.2 R      H45
B5916         C2016 05 06.08612 08 17 02.29 +31 39 33.6          17.3 R      H45
B5916         C2016 05 06.08782 08 17 02.64 +31 39 33.2          17.2 R      H45
B5916         C2016 05 06.08918 08 17 02.90 +31 39 33.0          17.2 R      H45
B5916         C2016 05 06.09033 08 17 03.14 +31 39 32.7          17.4 R      H45
B5916         C2016 05 06.09166 08 17 03.39 +31 39 32.7          17.4 R      H45
     K13W45T  C2016 05 06.09353 09 48 53.64 +07 50 09.3          19.1 R      H45
     K13W45T  C2016 05 06.09585 09 48 55.00 +07 49 53.0          19.1 R      H45
     K13W45T  C2016 05 06.09839 09 48 56.65 +07 49 32.2          19.2 R      H45
     K13W45T  C2016 05 06.09927 09 48 57.19 +07 49 26.1          19.3 R      H45
     K13W45T  C2016 05 06.10017 09 48 57.78 +07 49 18.3          19.2 R      H45
     K13W45T  C2016 05 06.10112 09 48 58.31 +07 49 11.8          19.0 R      H45
     K03K02O  C2016 05 06.10245 10 33 40.82 +28 49 59.3          18.3 R      H45
     K03K02O  C2016 05 06.10330 10 33 41.22 +28 50 01.1          18.2 R      H45
     K03K02O  C2016 05 06.10414 10 33 41.66 +28 50 03.0          18.4 R      H45
     K03K02O  C2016 05 06.10483 10 33 42.00 +28 50 04.2          18.4 R      H45
     K03K02O  C2016 05 06.10567 10 33 42.37 +28 50 05.9          18.4 R      H45
     K03K02O  C2016 05 06.10663 10 33 42.85 +28 50 07.6          18.4 R      H45
     K03K02O  C2016 05 06.10754 10 33 43.28 +28 50 09.0          18.5 R      H45
     K03K02O  C2016 05 06.10842 10 33 43.68 +28 50 10.6          18.5 R      H45
     K09D46L  C2016 05 06.10997 10 45 49.18 +57 31 14.0          18.7 R      H45
     K09D46L  C2016 05 06.11091 10 45 49.29 +57 31 12.5          18.8 R      H45
     K09D46L  C2016 05 06.11210 10 45 49.50 +57 31 10.6          18.8 R      H45
     K09D46L  C2016 05 06.11332 10 45 49.60 +57 31 08.2          18.7 R      H45
     K09D46L  C2016 05 06.11430 10 45 49.82 +57 31 06.3          18.7 R      H45
     K09D46L  C2016 05 06.11517 10 45 49.93 +57 31 05.0          19.0 R      H45
     K09D46L  C2016 05 06.11614 10 45 50.06 +57 31 03.5          19.0 R      H45
     K09D46L  C2016 05 06.11724 10 45 50.18 +57 31 01.1          18.8 R      H45
     K16EF6E  C2016 05 06.11815 10 20 47.28 +59 47 57.6          19.8 R      H45
     K16EF6E  C2016 05 06.12001 10 20 46.78 +59 47 58.3          19.6 R      H45
     K16EF6E  C2016 05 06.12155 10 20 46.50 +59 47 58.7          19.9 R      H45
     K16EF6E  C2016 05 06.12268 10 20 46.16 +59 47 58.9          19.8 R      H45
     K16EF6E  C2016 05 06.12393 10 20 45.94 +59 47 59.2          19.8 R      H45
     K16EF6E  C2016 05 06.12527 10 20 45.62 +59 47 59.5          19.7 R      H45
     K15TE3X  C2016 05 06.12658 10 46 20.41 +35 28 08.8          19.5 R      H45
     K15TE3X  C2016 05 06.12784 10 46 21.11 +35 28 04.2          19.7 R      H45
     K15TE3X  C2016 05 06.12888 10 46 21.60 +35 28 00.7          19.7 R      H45
     K15TE3X  C2016 05 06.12998 10 46 22.18 +35 27 57.0          19.8 R      H45
     K15TE3X  C2016 05 06.13102 10 46 22.74 +35 27 53.7          19.7 R      H45
     K15TE3X  C2016 05 06.13201 10 46 23.26 +35 27 50.4          19.7 R      H45
23187         C2016 05 06.13363 10 40 15.54 +56 18 13.8          18.5 R      H45
23187         C2016 05 06.13476 10 40 15.73 +56 18 13.4          18.6 R      H45
23187         C2016 05 06.13578 10 40 15.94 +56 18 12.7          18.4 R      H45
23187         C2016 05 06.13678 10 40 16.10 +56 18 12.2          18.3 R      H45
23187         C2016 05 06.13869 10 40 16.46 +56 18 10.9          18.5 R      H45
23187         C2016 05 06.13988 10 40 16.67 +56 18 10.2          18.5 R      H45
     K16G02S  C2016 05 06.37371 14 32 10.04 +10 09 30.9          18.0 R      H45
     K16G02S  C2016 05 06.37472 14 32 10.02 +10 09 33.7          18.1 R      H45
     K16G02S  C2016 05 06.37556 14 32 09.97 +10 09 36.3          18.0 R      H45
     K16G02S  C2016 05 06.37639 14 32 09.90 +10 09 39.1          18.0 R      H45
     K16G02S  C2016 05 06.37714 14 32 09.85 +10 09 41.3          18.1 R      H45
     K16G02S  C2016 05 06.37811 14 32 09.80 +10 09 43.9          18.0 R      H45
     K05J46C  C2016 05 06.37896 15 20 52.84 +22 44 17.0          18.7 R      H45
     K05J46C  C2016 05 06.37982 15 20 52.74 +22 44 16.1          18.6 R      H45
     K05J46C  C2016 05 06.38083 15 20 52.64 +22 44 15.2          18.7 R      H45
     K05J46C  C2016 05 06.38183 15 20 52.52 +22 44 14.3          18.8 R      H45
     K05J46C  C2016 05 06.38274 15 20 52.43 +22 44 13.4          18.8 R      H45
     K05J46C  C2016 05 06.38373 15 20 52.29 +22 44 12.6          18.6 R      H45
     K16B13U  C2016 05 06.38580 16 39 39.91 -08 05 18.1          16.7 R      H45
     K16B13U  C2016 05 06.38695 16 39 39.86 -08 05 09.4          16.8 R      H45
     K16B13U  C2016 05 06.38785 16 39 39.81 -08 05 02.6          16.8 R      H45
     K16B13U  C2016 05 06.38877 16 39 39.77 -08 04 55.5          16.8 R      H45
     K16B13U  C2016 05 06.38967 16 39 39.73 -08 04 48.5          16.8 R      H45
     K16B13U  C2016 05 06.39041 16 39 39.68 -08 04 43.0          16.9 R      H45
     K16E86P  C2016 05 06.39175 16 34 23.30 -01 30 32.1          19.4 R      H45
     K16E86P  C2016 05 06.39322 16 34 23.47 -01 30 31.5          19.4 R      H45
     K16E86P  C2016 05 06.39422 16 34 23.54 -01 30 31.3          19.2 R      H45
     K16E86P  C2016 05 06.39504 16 34 23.61 -01 30 31.2          19.2 R      H45
     K16E86P  C2016 05 06.39695 16 34 23.77 -01 30 30.1          19.4 R      H45
     K16E86P  C2016 05 06.39795 16 34 23.92 -01 30 29.8          19.3 R      H45
     K16H00M  C2016 05 06.39936 16 03 36.48 +46 14 02.2          20.0 R      H45
     K16H00M  C2016 05 06.40075 16 03 36.11 +46 13 57.7          20.1 R      H45
     K16H00M  C2016 05 06.40182 16 03 35.75 +46 13 54.1          19.9 R      H45
     K16H00M  C2016 05 06.40276 16 03 35.43 +46 13 51.0          20.0 R      H45
     K16H00M  C2016 05 06.40384 16 03 35.00 +46 13 46.4          19.9 R      H45
     K16H00M  C2016 05 06.40487 16 03 34.75 +46 13 42.9          19.9 R      H45
     K11O24P  C2016 05 06.40606 16 17 03.53 +48 23 35.9          19.9 R      H45
     K11O24P  C2016 05 06.40716 16 17 03.12 +48 23 32.4          19.8 R      H45
     K11O24P  C2016 05 06.40845 16 17 02.61 +48 23 28.5          19.8 R      H45
     K11O24P  C2016 05 06.40943 16 17 02.25 +48 23 24.5          19.9 R      H45
     K11O24P  C2016 05 06.41049 16 17 01.87 +48 23 21.9          19.7 R      H45
     K11O24P  C2016 05 06.41165 16 17 01.43 +48 23 18.0          19.6 R      H45
     K16H19D  C2016 05 06.41271 16 13 17.41 +38 00 32.1          19.3 R      H45
     K16H19D  C2016 05 06.41385 16 13 17.19 +38 00 34.2          19.5 R      H45
     K16H19D  C2016 05 06.41491 16 13 17.00 +38 00 35.8          19.4 R      H45
     K16H19D  C2016 05 06.41613 16 13 16.67 +38 00 39.1          19.5 R      H45
     K16H19D  C2016 05 06.41732 16 13 16.46 +38 00 41.1          19.4 R      H45
     K16H19D  C2016 05 06.41845 16 13 16.17 +38 00 43.9          19.4 R      H45
     K16B14Z  C2016 05 06.42087 18 34 59.46 +63 21 55.2          19.3 R      H45
     K16B14Z  C2016 05 06.42201 18 34 59.26 +63 21 53.2          19.3 R      H45
     K16B14Z  C2016 05 06.42311 18 34 58.98 +63 21 51.9          19.5 R      H45
     K16B14Z  C2016 05 06.42428 18 34 58.71 +63 21 49.4          19.6 R      H45
     K16B14Z  C2016 05 06.42538 18 34 58.50 +63 21 48.0          19.4 R      H45
     K16B14Z  C2016 05 06.42651 18 34 58.30 +63 21 45.8          19.5 R      H45
     K10N01W  C2016 05 06.42840 18 24 51.15 +56 27 36.5          19.2 R      H45
     K10N01W  C2016 05 06.42972 18 24 51.31 +56 27 37.6          19.2 R      H45
     K10N01W  C2016 05 06.43071 18 24 51.45 +56 27 38.2          19.3 R      H45
     K10N01W  C2016 05 06.43167 18 24 51.45 +56 27 38.7          19.3 R      H45
     K10N01W  C2016 05 06.43276 18 24 51.65 +56 27 39.1          19.1 R      H45


Spaces are CRITICAL! I need to take each line and verify that its 80 characters, including spaces and NOT including the carriage return. Then I need to send each line as a database entry.
How can I make this happen?
GreyHead 18 May, 2016
Hi Bear,

First question - is a textarea the best way to input this data? Depending on what the source is uploading a CSV file might be simpler???

You can process the text area content using a Custom Code action in the form On Submit event. I'd explode the data into an array on a line feed or carriage return if it's present; then loop through the array doing whatever validation is necessary. Finally use a DB Save set to Multi-Save to save the array of validated data into the table.

Bob
N6REJ 18 May, 2016
yeah, it MUST be text.. he enters it as a chunk... this is all data going to harvard and they have easily 100 entries at a time.. so doing line by line would be a show stopper.
the data comes from some fancy astronomy program that takes their images and translates that into a long exacting datastring.
just to give you an idea, this is only 1 evenings observations...

D7170         C2016 05 06.07433 08 38 24.05 +46 51 03.5          16.1 R      H45
D7170         C2016 05 06.07517 08 38 24.37 +46 51 03.2          16.1 R      H45
D7170         C2016 05 06.07633 08 38 24.81 +46 51 03.1          16.3 R      H45
D7170         C2016 05 06.07708 08 38 25.08 +46 51 02.8          16.1 R      H45
D7170         C2016 05 06.07798 08 38 25.41 +46 51 02.4          16.2 R      H45
D7170         C2016 05 06.07891 08 38 25.77 +46 51 02.1          16.2 R      H45
O8590         C2016 05 06.07976 08 13 20.63 +62 47 47.5          18.3 R      H45
O8590         C2016 05 06.08055 08 13 20.93 +62 47 49.4          18.4 R      H45
O8590         C2016 05 06.08129 08 13 21.21 +62 47 51.7          18.5 R      H45
O8590         C2016 05 06.08205 08 13 21.57 +62 47 54.6          18.3 R      H45
O8590         C2016 05 06.08312 08 13 22.22 +62 47 57.6          18.4 R      H45
O8590         C2016 05 06.08413 08 13 22.64 +62 47 59.6          18.2 R      H45
B5916         C2016 05 06.08508 08 17 02.10 +31 39 33.7          17.2 R      H45
B5916         C2016 05 06.08612 08 17 02.29 +31 39 33.6          17.3 R      H45
B5916         C2016 05 06.08782 08 17 02.64 +31 39 33.2          17.2 R      H45
B5916         C2016 05 06.08918 08 17 02.90 +31 39 33.0          17.2 R      H45
B5916         C2016 05 06.09033 08 17 03.14 +31 39 32.7          17.4 R      H45
B5916         C2016 05 06.09166 08 17 03.39 +31 39 32.7          17.4 R      H45
     K13W45T  C2016 05 06.09353 09 48 53.64 +07 50 09.3          19.1 R      H45
     K13W45T  C2016 05 06.09585 09 48 55.00 +07 49 53.0          19.1 R      H45
     K13W45T  C2016 05 06.09839 09 48 56.65 +07 49 32.2          19.2 R      H45
     K13W45T  C2016 05 06.09927 09 48 57.19 +07 49 26.1          19.3 R      H45
     K13W45T  C2016 05 06.10017 09 48 57.78 +07 49 18.3          19.2 R      H45
     K13W45T  C2016 05 06.10112 09 48 58.31 +07 49 11.8          19.0 R      H45
     K03K02O  C2016 05 06.10245 10 33 40.82 +28 49 59.3          18.3 R      H45
     K03K02O  C2016 05 06.10330 10 33 41.22 +28 50 01.1          18.2 R      H45
     K03K02O  C2016 05 06.10414 10 33 41.66 +28 50 03.0          18.4 R      H45
     K03K02O  C2016 05 06.10483 10 33 42.00 +28 50 04.2          18.4 R      H45
     K03K02O  C2016 05 06.10567 10 33 42.37 +28 50 05.9          18.4 R      H45
     K03K02O  C2016 05 06.10663 10 33 42.85 +28 50 07.6          18.4 R      H45
     K03K02O  C2016 05 06.10754 10 33 43.28 +28 50 09.0          18.5 R      H45
     K03K02O  C2016 05 06.10842 10 33 43.68 +28 50 10.6          18.5 R      H45
     K09D46L  C2016 05 06.10997 10 45 49.18 +57 31 14.0          18.7 R      H45
     K09D46L  C2016 05 06.11091 10 45 49.29 +57 31 12.5          18.8 R      H45
     K09D46L  C2016 05 06.11210 10 45 49.50 +57 31 10.6          18.8 R      H45
     K09D46L  C2016 05 06.11332 10 45 49.60 +57 31 08.2          18.7 R      H45
     K09D46L  C2016 05 06.11430 10 45 49.82 +57 31 06.3          18.7 R      H45
     K09D46L  C2016 05 06.11517 10 45 49.93 +57 31 05.0          19.0 R      H45
     K09D46L  C2016 05 06.11614 10 45 50.06 +57 31 03.5          19.0 R      H45
     K09D46L  C2016 05 06.11724 10 45 50.18 +57 31 01.1          18.8 R      H45
     K16EF6E  C2016 05 06.11815 10 20 47.28 +59 47 57.6          19.8 R      H45
     K16EF6E  C2016 05 06.12001 10 20 46.78 +59 47 58.3          19.6 R      H45
     K16EF6E  C2016 05 06.12155 10 20 46.50 +59 47 58.7          19.9 R      H45
     K16EF6E  C2016 05 06.12268 10 20 46.16 +59 47 58.9          19.8 R      H45
     K16EF6E  C2016 05 06.12393 10 20 45.94 +59 47 59.2          19.8 R      H45
     K16EF6E  C2016 05 06.12527 10 20 45.62 +59 47 59.5          19.7 R      H45
     K15TE3X  C2016 05 06.12658 10 46 20.41 +35 28 08.8          19.5 R      H45
     K15TE3X  C2016 05 06.12784 10 46 21.11 +35 28 04.2          19.7 R      H45
     K15TE3X  C2016 05 06.12888 10 46 21.60 +35 28 00.7          19.7 R      H45
     K15TE3X  C2016 05 06.12998 10 46 22.18 +35 27 57.0          19.8 R      H45
     K15TE3X  C2016 05 06.13102 10 46 22.74 +35 27 53.7          19.7 R      H45
     K15TE3X  C2016 05 06.13201 10 46 23.26 +35 27 50.4          19.7 R      H45
23187         C2016 05 06.13363 10 40 15.54 +56 18 13.8          18.5 R      H45
23187         C2016 05 06.13476 10 40 15.73 +56 18 13.4          18.6 R      H45
23187         C2016 05 06.13578 10 40 15.94 +56 18 12.7          18.4 R      H45
23187         C2016 05 06.13678 10 40 16.10 +56 18 12.2          18.3 R      H45
23187         C2016 05 06.13869 10 40 16.46 +56 18 10.9          18.5 R      H45
23187         C2016 05 06.13988 10 40 16.67 +56 18 10.2          18.5 R      H45
     K16G02S  C2016 05 06.37371 14 32 10.04 +10 09 30.9          18.0 R      H45
     K16G02S  C2016 05 06.37472 14 32 10.02 +10 09 33.7          18.1 R      H45
     K16G02S  C2016 05 06.37556 14 32 09.97 +10 09 36.3          18.0 R      H45
     K16G02S  C2016 05 06.37639 14 32 09.90 +10 09 39.1          18.0 R      H45
     K16G02S  C2016 05 06.37714 14 32 09.85 +10 09 41.3          18.1 R      H45
     K16G02S  C2016 05 06.37811 14 32 09.80 +10 09 43.9          18.0 R      H45
     K05J46C  C2016 05 06.37896 15 20 52.84 +22 44 17.0          18.7 R      H45
     K05J46C  C2016 05 06.37982 15 20 52.74 +22 44 16.1          18.6 R      H45
     K05J46C  C2016 05 06.38083 15 20 52.64 +22 44 15.2          18.7 R      H45
     K05J46C  C2016 05 06.38183 15 20 52.52 +22 44 14.3          18.8 R      H45
     K05J46C  C2016 05 06.38274 15 20 52.43 +22 44 13.4          18.8 R      H45
     K05J46C  C2016 05 06.38373 15 20 52.29 +22 44 12.6          18.6 R      H45
     K16B13U  C2016 05 06.38580 16 39 39.91 -08 05 18.1          16.7 R      H45
     K16B13U  C2016 05 06.38695 16 39 39.86 -08 05 09.4          16.8 R      H45
     K16B13U  C2016 05 06.38785 16 39 39.81 -08 05 02.6          16.8 R      H45
     K16B13U  C2016 05 06.38877 16 39 39.77 -08 04 55.5          16.8 R      H45
     K16B13U  C2016 05 06.38967 16 39 39.73 -08 04 48.5          16.8 R      H45
     K16B13U  C2016 05 06.39041 16 39 39.68 -08 04 43.0          16.9 R      H45
     K16E86P  C2016 05 06.39175 16 34 23.30 -01 30 32.1          19.4 R      H45
     K16E86P  C2016 05 06.39322 16 34 23.47 -01 30 31.5          19.4 R      H45
     K16E86P  C2016 05 06.39422 16 34 23.54 -01 30 31.3          19.2 R      H45
     K16E86P  C2016 05 06.39504 16 34 23.61 -01 30 31.2          19.2 R      H45
     K16E86P  C2016 05 06.39695 16 34 23.77 -01 30 30.1          19.4 R      H45
     K16E86P  C2016 05 06.39795 16 34 23.92 -01 30 29.8          19.3 R      H45
     K16H00M  C2016 05 06.39936 16 03 36.48 +46 14 02.2          20.0 R      H45
     K16H00M  C2016 05 06.40075 16 03 36.11 +46 13 57.7          20.1 R      H45
     K16H00M  C2016 05 06.40182 16 03 35.75 +46 13 54.1          19.9 R      H45
     K16H00M  C2016 05 06.40276 16 03 35.43 +46 13 51.0          20.0 R      H45
     K16H00M  C2016 05 06.40384 16 03 35.00 +46 13 46.4          19.9 R      H45
     K16H00M  C2016 05 06.40487 16 03 34.75 +46 13 42.9          19.9 R      H45
     K11O24P  C2016 05 06.40606 16 17 03.53 +48 23 35.9          19.9 R      H45
     K11O24P  C2016 05 06.40716 16 17 03.12 +48 23 32.4          19.8 R      H45
     K11O24P  C2016 05 06.40845 16 17 02.61 +48 23 28.5          19.8 R      H45
     K11O24P  C2016 05 06.40943 16 17 02.25 +48 23 24.5          19.9 R      H45
     K11O24P  C2016 05 06.41049 16 17 01.87 +48 23 21.9          19.7 R      H45
     K11O24P  C2016 05 06.41165 16 17 01.43 +48 23 18.0          19.6 R      H45
     K16H19D  C2016 05 06.41271 16 13 17.41 +38 00 32.1          19.3 R      H45
     K16H19D  C2016 05 06.41385 16 13 17.19 +38 00 34.2          19.5 R      H45
     K16H19D  C2016 05 06.41491 16 13 17.00 +38 00 35.8          19.4 R      H45
     K16H19D  C2016 05 06.41613 16 13 16.67 +38 00 39.1          19.5 R      H45
     K16H19D  C2016 05 06.41732 16 13 16.46 +38 00 41.1          19.4 R      H45
     K16H19D  C2016 05 06.41845 16 13 16.17 +38 00 43.9          19.4 R      H45
     K16B14Z  C2016 05 06.42087 18 34 59.46 +63 21 55.2          19.3 R      H45
     K16B14Z  C2016 05 06.42201 18 34 59.26 +63 21 53.2          19.3 R      H45
     K16B14Z  C2016 05 06.42311 18 34 58.98 +63 21 51.9          19.5 R      H45
     K16B14Z  C2016 05 06.42428 18 34 58.71 +63 21 49.4          19.6 R      H45
     K16B14Z  C2016 05 06.42538 18 34 58.50 +63 21 48.0          19.4 R      H45
     K16B14Z  C2016 05 06.42651 18 34 58.30 +63 21 45.8          19.5 R      H45
     K10N01W  C2016 05 06.42840 18 24 51.15 +56 27 36.5          19.2 R      H45
     K10N01W  C2016 05 06.42972 18 24 51.31 +56 27 37.6          19.2 R      H45
     K10N01W  C2016 05 06.43071 18 24 51.45 +56 27 38.2          19.3 R      H45
     K10N01W  C2016 05 06.43167 18 24 51.45 +56 27 38.7          19.3 R      H45
     K10N01W  C2016 05 06.43276 18 24 51.65 +56 27 39.1          19.1 R      H45

I don't see the onsubmit event... I'm in simple if that matters...
if I have this right, I would do..

<?php

$invalidEntry = '';

/* lets make sure last character is a EOL */
$data = {astrometrydata} . PHP_EOL;

/* convert line endings to *nix format and strip empty lines */
    $data = preg_replace( '/\n$/','',preg_replace( '/^\n/','',preg_replace( '/[\r\n]+/',"\n",{astrometrydata} ) ) );

/* convert to an array now. */
    $data = explode("\n",$data);

/* process array into entries */
foreach($data as $line){
if( strlen($line) === '80'){ 

$validEntry = $line . PHP_EOL;

send $LINE TO DATABASE AS ROW
RETURN TO ???

} else {

$invalidEntry .= $line . PHP_EOL;

}

if( $invalidEntry ){
echo '<div class = "alert alert-danger">' . The following lines were invalid and need to be restructured before they will be accepted... THESE ITEMS WERE NOT PUT INTO THE DATABASE<br><pre>' . $invalidEntry . '</pre></div><br>';
}

echo '<div class="alert alert-success"> The following lines were successfully submitted to the database<br><pre>' . $validEntry . '</pre></div><br>';

EXIT ROUTINE SOMEHOW

?>

The items in italics I have no clue what they should be.

Finally use a DB Save set to Multi-Save to save the array of validated data into the table.


I've no clue what this means.

Lastly if it possible to do this with each $line ?

Using Tools Other Than cURL
If you wish to call the script via tools other than cURL, you are not to use the script listed above for testing purposes.
If you wish to test your script, use minorplanetcenter.net/submit_obs_test instead of minorplanetcenter.net/submit_obs. The format of the call to the test script is exactly the same as that of the functional script. The test script runs the same basic checks as the functional script. To test your script, simply issue the following command:

curl minorplanetcenter.net/submit_obs_test -F "source=<myobs.txt"

where myobs.txt is replaced with the local file name of the observation batch you wish to submit. Be sure to include the "<"--that is very important! You will get back a CurlID confirming that the batch was received. The submitted batch is NOT passed to the processing routines for processing.


Thanks in advance, especially for the rapid response.
GreyHead 19 May, 2016
Hi Bear,

I'm not suggesting that they enter it line by line - just guessing that the source is a file output from something else and it might be simpler to upload a .txt.or.csv file than copy and paste into a textarea. Either will work.

For your code:

a. You can't use the {input_name} syntax in PHP, user $form->data['input_name'] instead.

b. This will divide the data up into two sub-arrays:
<?php

/* lets make sure last character is a EOL */
$data = $form->data['astrometrydata'] . PHP_EOL;
/* convert line endings to *nix format and strip empty lines */
$data = preg_replace( '/\n$/', '', preg_replace( '/^\n/','',preg_replace( '/[\r\n]+/', "\n", $data ) ) );

/* convert to an array now. */
$data = explode("\n", $data);

/* process array into entries */
$valid = array();
$invalid = array();
foreach ( $data as $line ) {
  if( strlen($line) === '80') {
    $invalid[] = $line;
  } else {
    $valid[] = $line;
  }
}
$form->data['valid'] = $valid;
$form->data['invalid'] = $invalid;
?>


c. Then use a DB Save action to save the 'valid' sub-array to your table. For this you need to switch your Form Type to Advanced on the form General tab (don't switch back again later). You will then be able to remove some unused actions and drag in a DB Save action to the On Submit event you will see on the Setup Tab.

d, Use a Custom Code action to show the invalid data
<div>These records were invalid, please correct and re-submit:</div>
<?php
$invalid = implode("\n", $form->data['invalid']);
echo "<div>{$invalid}</div>";
?>


e. Repeat for the valid ones if necessary

f. You can do the cURL part - by writing the 'valid' sub-array to a text file on your server then using the cURL action to send it. I see that the file also needs a 'valid observational header' you don't appear to have that here - whatever it is?

Bob

[[>> later: fixed some typos <<]]
N6REJ 19 May, 2016
Fantastic answer... I created a user profile plugin ( https://github.com/N6REJ/Joomla_Astronomer/tree/plg_astronomerprofile ) that has 4 params. the header is one of those params.
This topic is locked and no more replies can be posted.