List Info

Thread: passing a hash back inside a form




passing a hash back inside a form
user name
2006-06-06 08:42:16
Hi,

I'm passing an array of hashes into a template, and it displays fine. ; I'd like to pass the hash back to the script again, but am having problems.

Below the data is passed and displayed ok, but when I submit the form, the [% element %] is passed pack to my script as a scalar , with an example value of "HASH(0x10a88f4)"

Am I able to pass back the hash ion the simplistic way ?

The reason for this, is that there are approx 50 fields inside the hash, and I'd like the user to be able to edit 2 of them , before submitting this data to a database.


Regards

Martin


script
my %r = (   elem1 => 'one,
          ;        elem2 => 'two',
        ;          ...
   ;           );
push(elem_data,\%r);


Template
<form ...>
[% FOREACH element IN elem_data %]
  <tr><td>[% element.elem1 %]</td&gt;
 &nbsp;   ; &nbsp; <td>[% element.elem2 %]</td&gt;
 &nbsp;   ; &nbsp; <td><input name=";elem_data&quot; value=&quot;[% element %]"&gt;</td&gt;
</tr>
[% END %]
</form>

passing a hash back inside a form
user name
2006-06-06 15:04:00
Martin Bower wrote:

> Below the data is passed and displayed ok, but when I
submit the form, 
> the [% element %] is passed pack to my script as a
scalar , with an 
> example value of "HASH(0x10a88f4)"
> 
> Am I able to pass back the hash ion the simplistic way
?
> 
> The reason for this, is that there are approx 50 fields
inside the hash, 
> and I'd like the user to be able to edit 2 of them ,
before submitting 
> this data to a database.
> 
> 
> Regards
> 
> Martin
> 
> 
> script
> my %r = (   elem1 => 'one,
>                   elem2 => 'two',
>                   ...
>               );
> push(elem_data,\%r);
> 
> 
> Template
> <form ...>
> [% FOREACH element IN elem_data %]
>   <tr><td>[% element.elem1 %]</td>
>         <td>[% element.elem2 %]</td>
>         <td><input
name="elem_data" value="[% element
%]"></td>
> </tr>
> [% END %]
> </form>


I don't think there is an easy way to do this currently,
although something like [% element.each.join(',') | html
%] might work maybe. You should probably urlencode it too,
so things like line returns are escaped. You're probably
better off just creating your own serialize virtual method
that uses base64, though. Also, the each behavior is going
to be changing in TT3, so I would be aware of that.

You could also just use a foreach and make a bunch of hidden
inputs. Or just store the hash on the server and assign the
form a unique id that would associate it with the hash.

-- Josh

_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
passing a hash back inside a form
user name
2006-06-06 15:48:19
> Also, the each behavior is going to be changing in
TT3...

I see these occasional allusions to TT3, but not much more
than
these oblique references.  Is there something more for the
curious and interested on this subject?  A plan? A feature
list?

Thanks!

Mark

_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
passing a hash back inside a form
user name
2006-06-06 16:05:08
On 6/6/06, markd <markimmermail.com> wrote:
>
> > Also, the each behavior is going to be changing in
TT3...
>
> I see these occasional allusions to TT3, but not much
more than
> these oblique references.  Is there something more for
the
> curious and interested on this subject?  A plan? A
feature list?

There is some info here:

http://www.tt2.org/v3/

and there is a pre-alpha snapshot that you can look at as
well (but it
could be out of date by now since it has been there for a
while):

http://www.tt2.org/download/Template-Toolkit-2.51.tar.gz


or browse it online:

ht
tp://www.tt2.org/download/Template-Toolkit-2.51/

Cheers,

Cees

_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
passing a hash back inside a form
user name
2006-06-06 17:36:48
markd wrote:
> I see these occasional allusions to TT3, but not much
more than
> these oblique references.  Is there something more for
the
> curious and interested on this subject?  A plan? A
feature list?

The "official" site is here:

   http://tt3.template-
toolkit.org/

It's a little out of date and some of the design has
changed since I 
wrote those pages and code.  There's no real plan, and only
a handful of 
featured discussed, but there is code you can download and
play with 
(but not use in any real application).

There's also the slides from a talk I gave to bond.pm about
some of 
the planned features:

   http://wardley.org/computers/perl/bond.pm.html#
Template_Toolkit_3

TT3 coding is spurious and appears in high energy bursts
between babies, 
jobs, TT2 releases and other real life distraction.  But the
design 
process is ongoing and has been trickling along for about 5
years now. 
Randal's taking bets on which comes first: Perl 6 or TT3


Anyway I've now got a pretty good idea about how it is all
going to work 
and I'm just waiting for some free time to get back into
coding it 
again.  I've currently got a big job on for a client which
is expected 
to run until October.  I'm hoping that when that's done
the few months 
at the end of the year/start of the next will give me a
chance to get it 
finished or close to it.

Cheers
A


_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )