More D7 form woes

Jeff Greenberg <[email protected]> Tue, 17 Feb 2015 16:06:24 -0500
Newsgroups gmane.comp.php.drupal.support
Message-ID <CAPpCgRba7My7ML7VWHQricWHisxF3GEN4NS5M-7QaObuPLtMmw@mail.gmail.com>
--===============3372896221898676214==
Content-Type: multipart/alternative; boundary=047d7bdc1bee538906050f4f1325

--047d7bdc1bee538906050f4f1325
Content-Type: text/plain; charset=UTF-8

So, my last messages were about needing to create and populate checkboxes
based on values determined during the form validation process. This ended
up working by:
1. Creating the fields in hook_form_alter
2. Storing the option values as an array during validation in
$form_state['storage']
3. Checking in hook_form_alter for $form_state[storage], and if present,
setting the field's options to the stored array

I also need to massage the body value during validation, basically to
convert some strings to links. I tried the same method as above, which
didn't work, with the problem being that  $form[body][LANGUAGE_NONE][0]
contains a large meta array, so I wasn't sure what to do with the value.

I tried setting the value in form_state[values] during validation, but at
the end of validation at this point in the flow I set rebuild=true, which
ends up using the values that were present when the form was submitted
(thus overwriting my change) ... which is why I ended up doing the other
fields in hook_form_alter instead.

I then tried using form_set_value in validate. Two issues there. One is
that passing $form[body] as the element doesn't work, I think, because I
end up with $form_state[values][body] having a value instead of it being in
form_state[values][body][LANGUAGE_NONE][0], and, I think, because of
rebuild=true being set, which causes the change by form_set_value to be
overwritten with the value that was there when submit was clicked.

-- 
---
drupal.org/user/367108
linkedin.com/in/jeffrgreenberg
accidentalcoder.com / ayendesigns.com
@accidentalcoder

--047d7bdc1bee538906050f4f1325
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">So, my last messages were about needing to create and popu=
late checkboxes based on values determined during the form validation proce=
ss. This ended up working by:<div>1. Creating the fields in hook_form_alter=
</div><div>2. Storing the option values as an array during validation in $f=
orm_state[&#39;storage&#39;]</div><div>3. Checking in hook_form_alter for $=
form_state[storage], and if present, setting the field&#39;s options to the=
 stored array</div><div><br></div><div>I also need to massage the body valu=
e during validation, basically to convert some strings to links. I tried th=
e same method as above, which didn&#39;t work, with the problem being that =
=C2=A0$form[body][LANGUAGE_NONE][0] contains a large meta array, so I wasn&=
#39;t sure what to do with the value.</div><div><br></div><div>I tried sett=
ing the value in form_state[values] during validation, but at the end of va=
lidation at this point in the flow I set rebuild=3Dtrue, which ends up usin=
g the values that were present when the form was submitted (thus overwritin=
g my change) ... which is why I ended up doing the other fields in hook_for=
m_alter instead.</div><div><br></div><div>I then tried using form_set_value=
 in validate. Two issues there. One is that passing $form[body] as the elem=
ent doesn&#39;t work, I think, because I end up with $form_state[values][bo=
dy] having a value instead of it being in form_state[values][body][LANGUAGE=
_NONE][0], and, I think, because of rebuild=3Dtrue being set, which causes =
the change by form_set_value to be overwritten with the value that was ther=
e when submit was clicked.<br clear=3D"all"><div><br></div>-- <br><div clas=
s=3D"gmail_signature">---<div><a href=3D"http://drupal.org/user/367108" tar=
get=3D"_blank">drupal.org/user/367108</a></div><div><a href=3D"http://linke=
din.com/in/jeffrgreenberg" target=3D"_blank">linkedin.com/in/jeffrgreenberg=
</a></div><div><a href=3D"http://accidentalcoder.com" target=3D"_blank">acc=
identalcoder.com</a> / <a href=3D"http://ayendesigns.com" target=3D"_blank"=
>ayendesigns.com</a></div><div>@accidentalcoder</div></div>
</div></div>

--047d7bdc1bee538906050f4f1325--

--===============3372896221898676214==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-- 
[ Drupal support list | http://lists.drupal.org/ ]
--===============3372896221898676214==--