The goal is to allow the user to either plot a trail (field_trail_map) or to upload a gpx track (field_gpx_track), but ultimately I want both to save to the same field (field_trail_map).
I've got two fields
field_trail_map (a Geofield OpenLayers Map)
field_gpx_track (Geofield Geocode from another field (field_upload_gpx_track - File File))
If field_gpx_track is populated and field_trail_map isn't, I want the value of field_gpx_track to be saved to the field_trail_map field
I can't seem to get the syntax right and I'd appreciate some help, thanks.
When I print_r($node);
This is what field_trail_map looks like when it's populated
[field_trail_map] => Array
(
[und] => Array
(
[0] => Array
(
[wkt] => LINESTRING (-1.69626541282 51.7015304017, -1.6997415557 51.6989770051, -1.6986686721 51.6977534515, -1.6986686721 51.6967692648, -1.695664598 51.6983386334, -1.69738121177 51.6992429906, -1.69506378318 51.7009718585, -1.69583625938 51.7016633871)
[geo_type] => linestring
[lat] => 51.6992163219
[lon] => -1.69740266931
[top] => 51.7016633871
[bottom] => 51.6967692648
[right] => -1.69506378318
[left] => -1.6997415557
)
)
)
This is what field_trail_map looks like when it's empty
[field_trail_map] => Array
(
[und] => Array
(
)
)
field_gpx_track doesn't exist in the array if it's not populated
This is what field_gpx_track looks like when it's populated
[field_gpx_track] => Array
(
[und] => Array
(
[0] => Array
(
[wkt] => GEOMETRYCOLLECTION (POINT (-121.72904 45.44283), POINT (-121.71349 45.41), POINT (-121.70404 45.41124), POINT (-121.69937 45.3926), LINESTRING (-121.7295456 45.4431641, -121.72908 45.4428615, -121.7279085 45.4425697, -121.726736 45.4424274, -121.7260429 45.4422017, -121.7252347 45.4416576, -121.7241181 45.4406144, -121.722489 45.4398193, -121.7226112 45.4387649, -121.7224328 45.4383933, -121.7224159 45.437785, -121.7226603 45.4372204, -121.7226007 45.4347837, -121.721648 45.4332, -121.7223143 45.4334576, -121.7222102 45.432173, -121.7219974 45.4316609, -121.7220616 45.4303068, -121.7209685 45.4270753, -121.7211872 45.426761, -121.7212623 45.4260133, -121.7214738 45.4257683, -121.7217762 45.42574, -121.7226009 45.4259485, -121.7223672 45.4249972, -121.7219816 45.4246035, -121.721983 45.4238682, -121.7216494 45.4226721, -121.7217998 45.422412, -121.7218767 45.4211497, -121.720865 45.4193319, -121.7202956 45.4186435, -121.7200745 45.4185934, -121.7196035 45.4178963, -121.7198115 45.4171101, -121.719325 45.4166827, -121.7190778 45.4161855, -121.7193146 45.4159291, -121.7193939 45.4153644, -121.7191578 45.4151268, -121.7191043 45.4148071, -121.7187962 45.414631, -121.7187236 45.4142524, -121.7185595 45.4142844, -121.7180429 45.413352, -121.7181383 45.4131406, -121.7179036 45.4130356, -121.7168789 45.4118436, -121.7156569 45.4109205, -121.714525 45.4104523, -121.7143814 45.410493, -121.7140608 45.4102075, -121.7134527 45.4099806, -121.713461 45.4099792, -121.7134937 45.4091489, -121.7132504 45.4086133, -121.712767 45.4080616, -121.7126047 45.4076426, -121.7122301 45.4075043, -121.711898 45.4070652, -121.7114766 45.4068712, -121.7108634 45.4067987, -121.7106934 45.4064528, -121.7110326 45.4057286, -121.710828 45.4056813, -121.7109216 45.4055566, -121.7093884 45.4047244, -121.7083824 45.4039059, -121.7077738 45.4037176, -121.7074489 45.4034533, -121.7071945 45.4026499, -121.7067004 45.4019737, -121.7067477 45.4018086, -121.7063918 45.4014084, -121.7059701 45.4013177, -121.7058914 45.4011965, -121.7053257 45.4010688, -121.7054978 45.4008116, -121.7053495 45.4006075, -121.7054856 45.4005546, -121.7049765 45.3991622, -121.7042976 45.398556, -121.704226 45.3981831, -121.7036992 45.3973151, -121.703637 45.3967974, -121.7033742 45.3963985, -121.7029688 45.3945456, -121.7015918 45.3920595, -121.7012029 45.3907614, -121.7010483 45.3906454, -121.7008185 45.3906726, -121.7008263 45.3909774, -121.70043 45.3911315, -121.6998193 45.3909963, -121.6997923 45.3908688, -121.6994679 45.3917895, -121.6994847 45.3926205, -121.6992485 45.3925915, -121.6995661 45.3928117), LINESTRING (-121.6995658 45.3928201, -121.6998805 45.3935449, -121.699771 45.3937897, -121.6999492 45.3941789, -121.7001375 45.3942372, -121.6999452 45.3946353, -121.7005823 45.3953599, -121.7006533 45.3957081, -121.7016813 45.3964324, -121.7016905 45.3965766, -121.7028225 45.396906, -121.7033856 45.3968739, -121.7040597 45.3974854, -121.7044455 45.398611, -121.7050832 45.3993308, -121.7055117 45.4006454, -121.7049952 45.4017924, -121.7048065 45.402869, -121.7056599 45.4055213, -121.7058477 45.4055606, -121.7058619 45.4055556, -121.7055424 45.4057016, -121.7058247 45.4064672, -121.705649 45.406555, -121.7055042 45.4081392, -121.7052201 45.4084785, -121.7053029 45.4089125, -121.705073 45.4097597, -121.7049047 45.4098359, -121.7049419 45.4101859, -121.7045409 45.4109946, -121.7040909 45.4110654, -121.7039421 45.4113353, -121.7047169 45.4119105, -121.7046115 45.4120297, -121.7049762 45.4123835, -121.7053677 45.412502, -121.7051916 45.4134357, -121.7046182 45.4135832, -121.7044171 45.4139565, -121.7041636 45.4140658, -121.7041176 45.4145098, -121.7043045 45.4141414, -121.7050125 45.4141558, -121.7071948 45.4136095, -121.7080044 45.4126067, -121.7088539 45.4122181, -121.7092346 45.4124283, -121.7101625 45.4119295, -121.7104037 45.4124117, -121.710797 45.4122553, -121.7107601 45.4116919, -121.7110571 45.4116619, -121.7114942 45.4113536, -121.7117619 45.4114186, -121.7125886 45.4110215, -121.7125816 45.4106014, -121.712959 45.4104916, -121.7130066 45.4102544, -121.7134279 45.4099714, -121.7134529 45.4099747, -121.7158641 45.4110685, -121.717194 45.4121873, -121.7179663 45.4131063, -121.7186587 45.4146646, -121.7190281 45.4147872, -121.7192079 45.4153143, -121.7193714 45.4153716, -121.7190904 45.4164891, -121.7196833 45.4172221, -121.7195244 45.4179416, -121.7197987 45.4185782, -121.7207025 45.419354, -121.7218387 45.4214007, -121.7215644 45.4226606, -121.721869 45.424759, -121.7221738 45.4249036, -121.722569 45.4259458, -121.7216118 45.425702, -121.7212258 45.4260738, -121.7208974 45.4272087, -121.7209468 45.4277253, -121.721389 45.4283981, -121.7213453 45.4288768, -121.7219605 45.4301857, -121.721934 45.4312165, -121.7222528 45.4334856, -121.7216508 45.4331572, -121.7217366 45.433607, -121.7225997 45.4350551, -121.7226122 45.4371233, -121.7223631 45.4378561, -121.7225545 45.4387304, -121.7223926 45.4397525, -121.7243251 45.4407832, -121.7260896 45.4422796, -121.7291117 45.4428882, -121.7295917 45.4431708))
[geo_type] => geometrycollection
[lat] => 45.4169081075
[lon] => -121.71442012
[top] => 45.4431708
[bottom] => 45.3906454
[right] => -121.6992485
[left] => -121.7295917
)
[1] => Array
(
[wkt] => POINT (-121.72904 45.44283)
[geo_type] => point
[lat] => 45.44283
[lon] => -121.72904
[top] => 45.44283
[bottom] => 45.44283
[right] => -121.72904
[left] => -121.72904
)
[2] => Array
(
[wkt] => POINT (-121.71349 45.41)
[geo_type] => point
[lat] => 45.41
[lon] => -121.71349
[top] => 45.41
[bottom] => 45.41
[right] => -121.71349
[left] => -121.71349
)
[3] => Array
(
[wkt] => POINT (-121.70404 45.41124)
[geo_type] => point
[lat] => 45.41124
[lon] => -121.70404
[top] => 45.41124
[bottom] => 45.41124
[right] => -121.70404
[left] => -121.70404
)
[4] => Array
(
[wkt] => POINT (-121.69937 45.3926)
[geo_type] => point
[lat] => 45.3926
[lon] => -121.69937
[top] => 45.3926
[bottom] => 45.3926
[right] => -121.69937
[left] => -121.69937
)
[5] => Array
(
[wkt] => LINESTRING (-121.7295456 45.4431641, -121.72908 45.4428615, -121.7279085 45.4425697, -121.726736 45.4424274, -121.7260429 45.4422017, -121.7252347 45.4416576, -121.7241181 45.4406144, -121.722489 45.4398193, -121.7226112 45.4387649, -121.7224328 45.4383933, -121.7224159 45.437785, -121.7226603 45.4372204, -121.7226007 45.4347837, -121.721648 45.4332, -121.7223143 45.4334576, -121.7222102 45.432173, -121.7219974 45.4316609, -121.7220616 45.4303068, -121.7209685 45.4270753, -121.7211872 45.426761, -121.7212623 45.4260133, -121.7214738 45.4257683, -121.7217762 45.42574, -121.7226009 45.4259485, -121.7223672 45.4249972, -121.7219816 45.4246035, -121.721983 45.4238682, -121.7216494 45.4226721, -121.7217998 45.422412, -121.7218767 45.4211497, -121.720865 45.4193319, -121.7202956 45.4186435, -121.7200745 45.4185934, -121.7196035 45.4178963, -121.7198115 45.4171101, -121.719325 45.4166827, -121.7190778 45.4161855, -121.7193146 45.4159291, -121.7193939 45.4153644, -121.7191578 45.4151268, -121.7191043 45.4148071, -121.7187962 45.414631, -121.7187236 45.4142524, -121.7185595 45.4142844, -121.7180429 45.413352, -121.7181383 45.4131406, -121.7179036 45.4130356, -121.7168789 45.4118436, -121.7156569 45.4109205, -121.714525 45.4104523, -121.7143814 45.410493, -121.7140608 45.4102075, -121.7134527 45.4099806, -121.713461 45.4099792, -121.7134937 45.4091489, -121.7132504 45.4086133, -121.712767 45.4080616, -121.7126047 45.4076426, -121.7122301 45.4075043, -121.711898 45.4070652, -121.7114766 45.4068712, -121.7108634 45.4067987, -121.7106934 45.4064528, -121.7110326 45.4057286, -121.710828 45.4056813, -121.7109216 45.4055566, -121.7093884 45.4047244, -121.7083824 45.4039059, -121.7077738 45.4037176, -121.7074489 45.4034533, -121.7071945 45.4026499, -121.7067004 45.4019737, -121.7067477 45.4018086, -121.7063918 45.4014084, -121.7059701 45.4013177, -121.7058914 45.4011965, -121.7053257 45.4010688, -121.7054978 45.4008116, -121.7053495 45.4006075, -121.7054856 45.4005546, -121.7049765 45.3991622, -121.7042976 45.398556, -121.704226 45.3981831, -121.7036992 45.3973151, -121.703637 45.3967974, -121.7033742 45.3963985, -121.7029688 45.3945456, -121.7015918 45.3920595, -121.7012029 45.3907614, -121.7010483 45.3906454, -121.7008185 45.3906726, -121.7008263 45.3909774, -121.70043 45.3911315, -121.6998193 45.3909963, -121.6997923 45.3908688, -121.6994679 45.3917895, -121.6994847 45.3926205, -121.6992485 45.3925915, -121.6995661 45.3928117)
[geo_type] => linestring
[lat] => 45.4169047404
[lon] => -121.714397024
[top] => 45.4431641
[bottom] => 45.3906454
[right] => -121.6992485
[left] => -121.7295456
)
[6] => Array
(
[wkt] => LINESTRING (-121.6995658 45.3928201, -121.6998805 45.3935449, -121.699771 45.3937897, -121.6999492 45.3941789, -121.7001375 45.3942372, -121.6999452 45.3946353, -121.7005823 45.3953599, -121.7006533 45.3957081, -121.7016813 45.3964324, -121.7016905 45.3965766, -121.7028225 45.396906, -121.7033856 45.3968739, -121.7040597 45.3974854, -121.7044455 45.398611, -121.7050832 45.3993308, -121.7055117 45.4006454, -121.7049952 45.4017924, -121.7048065 45.402869, -121.7056599 45.4055213, -121.7058477 45.4055606, -121.7058619 45.4055556, -121.7055424 45.4057016, -121.7058247 45.4064672, -121.705649 45.406555, -121.7055042 45.4081392, -121.7052201 45.4084785, -121.7053029 45.4089125, -121.705073 45.4097597, -121.7049047 45.4098359, -121.7049419 45.4101859, -121.7045409 45.4109946, -121.7040909 45.4110654, -121.7039421 45.4113353, -121.7047169 45.4119105, -121.7046115 45.4120297, -121.7049762 45.4123835, -121.7053677 45.412502, -121.7051916 45.4134357, -121.7046182 45.4135832, -121.7044171 45.4139565, -121.7041636 45.4140658, -121.7041176 45.4145098, -121.7043045 45.4141414, -121.7050125 45.4141558, -121.7071948 45.4136095, -121.7080044 45.4126067, -121.7088539 45.4122181, -121.7092346 45.4124283, -121.7101625 45.4119295, -121.7104037 45.4124117, -121.710797 45.4122553, -121.7107601 45.4116919, -121.7110571 45.4116619, -121.7114942 45.4113536, -121.7117619 45.4114186, -121.7125886 45.4110215, -121.7125816 45.4106014, -121.712959 45.4104916, -121.7130066 45.4102544, -121.7134279 45.4099714, -121.7134529 45.4099747, -121.7158641 45.4110685, -121.717194 45.4121873, -121.7179663 45.4131063, -121.7186587 45.4146646, -121.7190281 45.4147872, -121.7192079 45.4153143, -121.7193714 45.4153716, -121.7190904 45.4164891, -121.7196833 45.4172221, -121.7195244 45.4179416, -121.7197987 45.4185782, -121.7207025 45.419354, -121.7218387 45.4214007, -121.7215644 45.4226606, -121.721869 45.424759, -121.7221738 45.4249036, -121.722569 45.4259458, -121.7216118 45.425702, -121.7212258 45.4260738, -121.7208974 45.4272087, -121.7209468 45.4277253, -121.721389 45.4283981, -121.7213453 45.4288768, -121.7219605 45.4301857, -121.721934 45.4312165, -121.7222528 45.4334856, -121.7216508 45.4331572, -121.7217366 45.433607, -121.7225997 45.4350551, -121.7226122 45.4371233, -121.7223631 45.4378561, -121.7225545 45.4387304, -121.7223926 45.4397525, -121.7243251 45.4407832, -121.7260896 45.4422796, -121.7291117 45.4428882, -121.7295917 45.4431708)
[geo_type] => linestring
[lat] => 45.4179954506
[lon] => -121.714578752
[top] => 45.4431708
[bottom] => 45.3928201
[right] => -121.6995658
[left] => -121.7295917
)
[7] => Array
(
[wkt] => GEOMETRYCOLLECTION (POINT (-121.72904 45.44283), POINT (-121.71349 45.41), POINT (-121.70404 45.41124), POINT (-121.69937 45.3926), LINESTRING (-121.7295456 45.4431641, -121.72908 45.4428615, -121.7279085 45.4425697, -121.726736 45.4424274, -121.7260429 45.4422017, -121.7252347 45.4416576, -121.7241181 45.4406144, -121.722489 45.4398193, -121.7226112 45.4387649, -121.7224328 45.4383933, -121.7224159 45.437785, -121.7226603 45.4372204, -121.7226007 45.4347837, -121.721648 45.4332, -121.7223143 45.4334576, -121.7222102 45.432173, -121.7219974 45.4316609, -121.7220616 45.4303068, -121.7209685 45.4270753, -121.7211872 45.426761, -121.7212623 45.4260133, -121.7214738 45.4257683, -121.7217762 45.42574, -121.7226009 45.4259485, -121.7223672 45.4249972, -121.7219816 45.4246035, -121.721983 45.4238682, -121.7216494 45.4226721, -121.7217998 45.422412, -121.7218767 45.4211497, -121.720865 45.4193319, -121.7202956 45.4186435, -121.7200745 45.4185934, -121.7196035 45.4178963, -121.7198115 45.4171101, -121.719325 45.4166827, -121.7190778 45.4161855, -121.7193146 45.4159291, -121.7193939 45.4153644, -121.7191578 45.4151268, -121.7191043 45.4148071, -121.7187962 45.414631, -121.7187236 45.4142524, -121.7185595 45.4142844, -121.7180429 45.413352, -121.7181383 45.4131406, -121.7179036 45.4130356, -121.7168789 45.4118436, -121.7156569 45.4109205, -121.714525 45.4104523, -121.7143814 45.410493, -121.7140608 45.4102075, -121.7134527 45.4099806, -121.713461 45.4099792, -121.7134937 45.4091489, -121.7132504 45.4086133, -121.712767 45.4080616, -121.7126047 45.4076426, -121.7122301 45.4075043, -121.711898 45.4070652, -121.7114766 45.4068712, -121.7108634 45.4067987, -121.7106934 45.4064528, -121.7110326 45.4057286, -121.710828 45.4056813, -121.7109216 45.4055566, -121.7093884 45.4047244, -121.7083824 45.4039059, -121.7077738 45.4037176, -121.7074489 45.4034533, -121.7071945 45.4026499, -121.7067004 45.4019737, -121.7067477 45.4018086, -121.7063918 45.4014084, -121.7059701 45.4013177, -121.7058914 45.4011965, -121.7053257 45.4010688, -121.7054978 45.4008116, -121.7053495 45.4006075, -121.7054856 45.4005546, -121.7049765 45.3991622, -121.7042976 45.398556, -121.704226 45.3981831, -121.7036992 45.3973151, -121.703637 45.3967974, -121.7033742 45.3963985, -121.7029688 45.3945456, -121.7015918 45.3920595, -121.7012029 45.3907614, -121.7010483 45.3906454, -121.7008185 45.3906726, -121.7008263 45.3909774, -121.70043 45.3911315, -121.6998193 45.3909963, -121.6997923 45.3908688, -121.6994679 45.3917895, -121.6994847 45.3926205, -121.6992485 45.3925915, -121.6995661 45.3928117), LINESTRING (-121.6995658 45.3928201, -121.6998805 45.3935449, -121.699771 45.3937897, -121.6999492 45.3941789, -121.7001375 45.3942372, -121.6999452 45.3946353, -121.7005823 45.3953599, -121.7006533 45.3957081, -121.7016813 45.3964324, -121.7016905 45.3965766, -121.7028225 45.396906, -121.7033856 45.3968739, -121.7040597 45.3974854, -121.7044455 45.398611, -121.7050832 45.3993308, -121.7055117 45.4006454, -121.7049952 45.4017924, -121.7048065 45.402869, -121.7056599 45.4055213, -121.7058477 45.4055606, -121.7058619 45.4055556, -121.7055424 45.4057016, -121.7058247 45.4064672, -121.705649 45.406555, -121.7055042 45.4081392, -121.7052201 45.4084785, -121.7053029 45.4089125, -121.705073 45.4097597, -121.7049047 45.4098359, -121.7049419 45.4101859, -121.7045409 45.4109946, -121.7040909 45.4110654, -121.7039421 45.4113353, -121.7047169 45.4119105, -121.7046115 45.4120297, -121.7049762 45.4123835, -121.7053677 45.412502, -121.7051916 45.4134357, -121.7046182 45.4135832, -121.7044171 45.4139565, -121.7041636 45.4140658, -121.7041176 45.4145098, -121.7043045 45.4141414, -121.7050125 45.4141558, -121.7071948 45.4136095, -121.7080044 45.4126067, -121.7088539 45.4122181, -121.7092346 45.4124283, -121.7101625 45.4119295, -121.7104037 45.4124117, -121.710797 45.4122553, -121.7107601 45.4116919, -121.7110571 45.4116619, -121.7114942 45.4113536, -121.7117619 45.4114186, -121.7125886 45.4110215, -121.7125816 45.4106014, -121.712959 45.4104916, -121.7130066 45.4102544, -121.7134279 45.4099714, -121.7134529 45.4099747, -121.7158641 45.4110685, -121.717194 45.4121873, -121.7179663 45.4131063, -121.7186587 45.4146646, -121.7190281 45.4147872, -121.7192079 45.4153143, -121.7193714 45.4153716, -121.7190904 45.4164891, -121.7196833 45.4172221, -121.7195244 45.4179416, -121.7197987 45.4185782, -121.7207025 45.419354, -121.7218387 45.4214007, -121.7215644 45.4226606, -121.721869 45.424759, -121.7221738 45.4249036, -121.722569 45.4259458, -121.7216118 45.425702, -121.7212258 45.4260738, -121.7208974 45.4272087, -121.7209468 45.4277253, -121.721389 45.4283981, -121.7213453 45.4288768, -121.7219605 45.4301857, -121.721934 45.4312165, -121.7222528 45.4334856, -121.7216508 45.4331572, -121.7217366 45.433607, -121.7225997 45.4350551, -121.7226122 45.4371233, -121.7223631 45.4378561, -121.7225545 45.4387304, -121.7223926 45.4397525, -121.7243251 45.4407832, -121.7260896 45.4422796, -121.7291117 45.4428882, -121.7295917 45.4431708))
[geo_type] => geometrycollection
[lat] => 45.4169081075
[lon] => -121.71442012
[top] => 45.4431708
[bottom] => 45.3906454
[right] => -121.6992485
[left] => -121.7295917
)
)
)
Comments
You can use the
You can use the element_validate in the form API and implement the logic that you have mentioned
. Alternately, you can also implement the logic prior to form submission callback. Hope that helps.
Thanks, I'll have a look at
Thanks, I'll have a look at element_validate, but it was more the syntax that I was having problems with - I'm not a programmer.
I'd tried
but that was giving me errors.
I think you are trying to
I think you are trying to access array as object. Try this
Hope that helps.
This worked for me, thanks
This worked for me, thanks very much for your help.