Re: More D7 form woes

Niveditha Samudrala <[email protected]> Thu, 19 Feb 2015 16:38:48 +0530
Newsgroups gmane.comp.php.drupal.support
Message-ID <CAM2heapZz9hS12_pT+LO8Kb1STnEenDbeUBA+VgvbnGFMCnRXQ@mail.gmail.com>
--===============5338192763337355330==
Content-Type: multipart/alternative; boundary=001a113d3702ce250f050f6ef5ae

--001a113d3702ce250f050f6ef5ae
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi Team,

I don't want to receive any emails from this group.
Please remove it.

Thanks in Advance.

Regards,
Niveditha Samudrala

On Wed, Feb 18, 2015 at 9:43 PM, Metzler, David <[email protected]>
wrote:

>  Sounds like you got it, but it looks like you were struggling with
> changing values on validation, which I=E2=80=99ve struggled with before s=
o I
> thought I=E2=80=99d let you know the secret sauce.  It=E2=80=99s the $for=
m_state[=E2=80=98input=E2=80=99]
> that people usually miss.
>
>
>
> When changing the values in a validation handler or form rebuilding
> function do the following:
>
> 1.)    Change the #default value in the form:
>
> 2.)    Change the corresponding $form_state[=E2=80=98values=E2=80=99] ele=
ment
>
> 3.)    Change the $form_state[=E2=80=98input=E2=80=99] element for the sa=
me value.
>
>
>
> I usually do this in one statement like:
>
>
>
> $form[=E2=80=98myfield=E2=80=99][=E2=80=98#default_value=E2=80=99] =3D $f=
orm_state[=E2=80=98values=E2=80=99][=E2=80=98myfield=E2=80=99] =3D
> $form_state[=E2=80=98input=E2=80=99][=E2=80=98my_field=E2=80=99] =3D $foo=
;
>
>
>
> Dave
>
>
>
> *From:* [email protected] [mailto:[email protected]] *O=
n
> Behalf Of *Jeff Greenberg
> *Sent:* Tuesday, February 17, 2015 4:08 PM
> *To:* [email protected]
> *Subject:* Re: [support] More D7 form woes
>
>
>
> Got it. I cheated in the most horrendous way, though. Doing the change of
> the body in hook_node_presave works. Of course, that hook has no view int=
o
> the form structure, just the node, and getting the value into the node ha=
s
> been the issue. So, when the new body value is assembled, I store it in a
> session variable and retrieve it during presave.
>
>
>
> On Tue, Feb 17, 2015 at 5:04 PM, Jeff Greenberg <
> [email protected]> wrote:
>
> I don't think he filter will do it. I'm thinking my description of how I'=
m
> changing the body was too generic. The body is fed through some logic tha=
t
> selects strings from it that are likely tag values for the given category=
,
> and then those become links within the body, as well as the checkboxes fr=
om
> the previous issue.
>
>
>
> Seems that requesting rebuild at the end of validation causes the usual
> way of changing form values during validation to fail.
>
>
>
>
> On Feb 17, 2015, at 16:31, Jamie Holly <[email protected]> wrote=
:
>
>  Instead of doing that, why not just create a custom format filter and do
> the changes then? That also gives the benefit of being resuable on any
> other place you might need it in the future, like blocks, plus can easily
> be modified, undone, whatever by changing the code, since the final marku=
p
> is cached and the original kept in tact.
>
>  Jamie Holly
>
> http://hollyit.net
>
> On 2/17/2015 4:06 PM, Jeff Greenberg wrote:
>
>  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=3Dtrue, whi=
ch
> 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=3Dtrue 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
>
>
>
>
>
>  --
> [ Drupal support list | http://lists.drupal.org/ ]
>
>
>
>
>
> --
>
> ---
>
> drupal.org/user/367108
>
> linkedin.com/in/jeffrgreenberg
>
> accidentalcoder.com / ayendesigns.com
>
> @accidentalcoder
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>

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

<div dir=3D"ltr"><div><div><div><div>Hi Team,<br><br></div>I don&#39;t want=
 to receive any emails from this group. <br></div>Please remove it.<br><br>=
</div><div>Thanks in Advance.<br><br></div>Regards,<br></div>Niveditha Samu=
drala <br></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">O=
n Wed, Feb 18, 2015 at 9:43 PM, Metzler, David <span dir=3D"ltr">&lt;<a hre=
f=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
u</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div link=3D"blue" vlink=3D"purple" lang=3D"EN-US">
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d">Sounds like you got it, b=
ut it looks like you were struggling with changing values on validation, wh=
ich I=E2=80=99ve struggled with before so I thought I=E2=80=99d let you
 know the secret sauce.=C2=A0 It=E2=80=99s the $form_state[=E2=80=98input=
=E2=80=99] that people usually miss. <u></u>
<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>=C2=A0<u></u></spa=
n></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d">When changing the values =
in a validation handler or form rebuilding function do the following:<u></u=
><u></u></span></p>
<p><u></u><span style=3D"font-size:11.0pt;font-family:&quot;Calibri&quot;,&=
quot;sans-serif&quot;;color:#1f497d"><span>1.)<span style=3D"font:7.0pt &qu=
ot;Times New Roman&quot;">=C2=A0=C2=A0=C2=A0
</span></span></span><u></u><span style=3D"font-size:11.0pt;font-family:&qu=
ot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Change the #default =
value in the form:
<u></u><u></u></span></p>
<p><u></u><span style=3D"font-size:11.0pt;font-family:&quot;Calibri&quot;,&=
quot;sans-serif&quot;;color:#1f497d"><span>2.)<span style=3D"font:7.0pt &qu=
ot;Times New Roman&quot;">=C2=A0=C2=A0=C2=A0
</span></span></span><u></u><span style=3D"font-size:11.0pt;font-family:&qu=
ot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Change the correspon=
ding $form_state[=E2=80=98values=E2=80=99] element
<u></u><u></u></span></p>
<p><u></u><span style=3D"font-size:11.0pt;font-family:&quot;Calibri&quot;,&=
quot;sans-serif&quot;;color:#1f497d"><span>3.)<span style=3D"font:7.0pt &qu=
ot;Times New Roman&quot;">=C2=A0=C2=A0=C2=A0
</span></span></span><u></u><span style=3D"font-size:11.0pt;font-family:&qu=
ot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Change the $form_sta=
te[=E2=80=98input=E2=80=99] element for the same value.
<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>=C2=A0<u></u></spa=
n></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d">I usually do this in one =
statement like:
<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>=C2=A0<u></u></spa=
n></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d">$form[=E2=80=98myfield=E2=
=80=99][=E2=80=98#default_value=E2=80=99] =3D $form_state[=E2=80=98values=
=E2=80=99][=E2=80=98myfield=E2=80=99] =3D $form_state[=E2=80=98input=E2=80=
=99][=E2=80=98my_field=E2=80=99] =3D $foo;
<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>=C2=A0<u></u></spa=
n></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d">Dave<u></u><u></u></span>=
</p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>=C2=A0<u></u></spa=
n></p>
<p class=3D"MsoNormal"><b><span style=3D"font-size:10.0pt;font-family:&quot=
;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style=3D"font-s=
ize:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href=
=3D"mailto:[email protected]" target=3D"_blank">support-bounces@dr=
upal.org</a> [mailto:<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>]
<b>On Behalf Of </b>Jeff Greenberg<br>
<b>Sent:</b> Tuesday, February 17, 2015 4:08 PM<br>
<b>To:</b> <a href=3D"mailto:[email protected]" target=3D"_blank">support@=
drupal.org</a><br>
<b>Subject:</b> Re: [support] More D7 form woes<u></u><u></u></span></p><di=
v><div class=3D"h5">
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
<div>
<p class=3D"MsoNormal">Got it. I cheated in the most horrendous way, though=
. Doing the change of the body in hook_node_presave works. Of course, that =
hook has no view into the form structure, just the node, and getting the va=
lue into the node has been the issue.
 So, when the new body value is assembled, I store it in a session variable=
 and retrieve it during presave.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
<div>
<p class=3D"MsoNormal">On Tue, Feb 17, 2015 at 5:04 PM, Jeff Greenberg &lt;=
<a href=3D"mailto:[email protected]" target=3D"_blank">listmai=
[email protected]</a>&gt; wrote:<u></u><u></u></p>
<div>
<div>
<p class=3D"MsoNormal">I don&#39;t think he filter will do it. I&#39;m thin=
king my description of how I&#39;m changing the body was too generic. The b=
ody is fed through some logic that selects strings from it that are likely =
tag values for the given category, and then those
 become links within the body, as well as the checkboxes from the previous =
issue.=C2=A0<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">Seems that requesting rebuild at the end of validati=
on causes the usual way of changing form values during validation to fail.<=
u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><u></u>=C2=A0<u></u><=
/p>
</div>
<div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
On Feb 17, 2015, at 16:31, Jamie Holly &lt;<a href=3D"mailto:hovercrafter@e=
arthlink.net" target=3D"_blank">[email protected]</a>&gt; wrote:<u=
></u><u></u></p>
</div>
<blockquote style=3D"margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class=3D"MsoNormal">Instead of doing that, why not just create a custom =
format filter and do the changes then? That also gives the benefit of being=
 resuable on any other place you might need it in the future, like blocks, =
plus can easily be modified, undone,
 whatever by changing the code, since the final markup is cached and the or=
iginal kept in tact.
<br>
<br>
<u></u><u></u></p>
<pre>Jamie Holly<u></u><u></u></pre>
<pre><a href=3D"http://hollyit.net" target=3D"_blank">http://hollyit.net</a=
><u></u><u></u></pre>
<p class=3D"MsoNormal">On 2/17/2015 4:06 PM, Jeff Greenberg wrote:<u></u><u=
></u></p>
</div>
<blockquote style=3D"margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class=3D"MsoNormal">So, my last messages were about needing to create an=
d populate checkboxes based on values determined during the form validation=
 process. This ended up working by:
<u></u><u></u></p>
<div>
<p class=3D"MsoNormal">1. Creating the fields in hook_form_alter<u></u><u><=
/u></p>
</div>
<div>
<p class=3D"MsoNormal">2. Storing the option values as an array during vali=
dation in $form_state[&#39;storage&#39;]<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal">3. Checking in hook_form_alter for $form_state[stora=
ge], and if present, setting the field&#39;s options to the stored array<u>=
</u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">I also need to massage the body value during validat=
ion, basically to convert some strings to links. I tried the 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.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">I tried setting the value in form_state[values] duri=
ng validation, but at the end of validation at this point in the flow I set=
 rebuild=3Dtrue, 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.<u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<div>
<p class=3D"MsoNormal">I then tried using form_set_value in validate. Two i=
ssues there. One is that passing $form[body] as the element doesn&#39;t wor=
k, 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=3Dtrue being set, which causes the change=
 by form_set_value to be overwritten with the value that was there when sub=
mit was clicked.<span style=3D"color:#888888"><br clear=3D"all">
<span><u></u><u></u></span></span></p>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<p class=3D"MsoNormal"><span><span style=3D"color:#888888">-- </span><u></u=
><u></u></span></p>
<div>
<p class=3D"MsoNormal"><span style=3D"color:#888888">--- </span><u></u><u><=
/u></p>
<div>
<p class=3D"MsoNormal"><span style=3D"color:#888888"><a href=3D"http://drup=
al.org/user/367108" target=3D"_blank">drupal.org/user/367108</a><u></u><u><=
/u></span></p>
</div>
<div>
<p class=3D"MsoNormal"><span style=3D"color:#888888"><a href=3D"http://link=
edin.com/in/jeffrgreenberg" target=3D"_blank">linkedin.com/in/jeffrgreenber=
g</a><u></u><u></u></span></p>
</div>
<div>
<p class=3D"MsoNormal"><span style=3D"color:#888888"><a href=3D"http://acci=
dentalcoder.com" target=3D"_blank">accidentalcoder.com</a> /
<a href=3D"http://ayendesigns.com" target=3D"_blank">ayendesigns.com</a><u>=
</u><u></u></span></p>
</div>
<div>
<p class=3D"MsoNormal"><span style=3D"color:#888888">@accidentalcoder<u></u=
><u></u></span></p>
</div>
</div>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><u></u>=C2=A0<u></u><=
/p>
</blockquote>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
</blockquote>
<blockquote style=3D"margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class=3D"MsoNormal"><span style=3D"color:#888888">-- <br>
[ Drupal support list | <a href=3D"http://lists.drupal.org/" target=3D"_bla=
nk">http://lists.drupal.org/</a> ]<u></u><u></u></span></p>
</div>
</blockquote>
</div>
</div>
<p class=3D"MsoNormal"><br>
<br clear=3D"all">
<u></u><u></u></p>
<div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
<p class=3D"MsoNormal">-- <u></u><u></u></p>
<div>
<p class=3D"MsoNormal">---<u></u><u></u></p>
<div>
<p class=3D"MsoNormal"><a href=3D"http://drupal.org/user/367108" target=3D"=
_blank">drupal.org/user/367108</a><u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><a href=3D"http://linkedin.com/in/jeffrgreenberg" ta=
rget=3D"_blank">linkedin.com/in/jeffrgreenberg</a><u></u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal"><a href=3D"http://accidentalcoder.com" target=3D"_bl=
ank">accidentalcoder.com</a> /
<a href=3D"http://ayendesigns.com" target=3D"_blank">ayendesigns.com</a><u>=
</u><u></u></p>
</div>
<div>
<p class=3D"MsoNormal">@accidentalcoder<u></u><u></u></p>
</div>
</div>
</div>
</div></div></div>
</div>

<br>--<br>
[ Drupal support list | <a href=3D"http://lists.drupal.org/" target=3D"_bla=
nk">http://lists.drupal.org/</a> ]<br></blockquote></div><br></div>

--001a113d3702ce250f050f6ef5ae--

--===============5338192763337355330==
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/ ]
--===============5338192763337355330==--