Forum OpenACS Development: can't read "msg_keys": variable is array

Hi there,

To pass all the values through pages

1. Use Ajax
Every input box will be submited on real time. After the user stop editing the new translation message, the box is submited using Ajax New Request

new Ajax.Request('translate-message',{asynchronous:true,method:'post',parameters:'return_url=@return_url@&message_key=@messages.message_key&message_value=@message_value@});

2. Create a structure: array or list to pass the values (FAILED)
I dont know how to manipulate arrays within multirows

3. Make the input field's name as the respective message_key

I have a bunch of input fields within a form (the number and names of the fields can vary. They are dynamic).
I want to send them to another page.

The form gets filled from a template::list.

The list has one of the elements as described bellow:
...
translated_text {
label "Translation"
display_template {
if @messages.translated_p@ false
input type="text" name="@messages.message_key;noquote@"
/if
else
@messages.translated_text@
/else
}

The name of every input field is the message_key of a respective message.

Then the multirow is :

multirow create messages message_key orig_text translated_text translate_url translated_p counter msg_keys

foreach message_key [lang::util::get_message_lookups] {
.
.
.
if {!$translated_p} {
lappend msg_keys $message_key
incr counter
}
multirow append messages $message_key $orig_text $translated_text $translate_url $translated_p $counter $msg_keys
}

The form as in the ADP page

form action="/acs-lang/translation-edit" method="POST" name="form"
listtemplate name="messages"/listtemplate
input type="submit" name="submit" value="Translate All"
/form

Now, in the other page i've written the following bellow only to see if the values have been passed through pages.

ad_page_contract {

Edit i18n tranlations
} {
{msg_keys ""}

}

ns_log Notice "PAGE translation-edit"
set i 0
foreach {msg} $msg_keys {
incr i
ns_log Notice "$i. $msg"
ns_lof Notice ""

}



But i got no errors in the new page. However the variable msg_keys is null and no logs were written at error.log

How would i pass a multidimensional variable through the pages?

I tried also with array as parameter, But it didn't work

ad_page_contract {

Edit i18n translations
} {
{msg_keys:array}

}

[22/Sep/2010:22:49:42][32704.2955893648][-default:10-] Error: rp_report_error: Error rendering error page (!)
can't read "msg_keys": variable is array
while executing
"multirow append messages $message_key $orig_text $translated_text $translate_url $translated_p $counter $msg_keys"
("foreach" body line 20)
invoked from within
"foreach message_key [lang::util::get_message_lookups] {

set locale [ad_conn locale]

# Extra args mean no substitution
set or..."
("uplevel" body line 49)
invoked from within
"uplevel {
set locale [ad_conn locale]

set display_p [expr {[lang::util::translator_mode_p] && [ad_conn locale] ne "en_US" }]

array set msg_values {}..."
(procedure "code::tcl::/var/www/projop/projop/packages/acs-lang/lib/mess..." line 2)
invoked from with

Collapse
Posted by Iuri Sampaio on
I believe the solution is to use aolserver procs ns_*

Although I don't have much experience with them i used
ns_set print $myform

and it returned me the form properly even the values are there.

How can i treat them in the page now?
How to assign them to an array?

[23/Sep/2010:14:39:27][18086.3065723792][-default:4-] Notice: PAGE translation-edit
[23/Sep/2010:14:39:27][18086.3065723792][-default:4-] Notice: FORM
Unamed set:
Projects_1 = fsdfsdfa
With_members_of_my_dept_2 =
Mine_3 =
lt_intranet-coreProject__4 =
lt_intranet-coreOn_Track_5 =
no_value_6 =
View_Projects_7 =
Project_Status_8 =
Project_Type_9 =
Profile_Accounting_10 =
Profile_Customers_11 =
Profile_Employees_12 =
Profile_Freelance_Managers_13 =
Profile_Freelancers_14 =
Profile_Helpdesk_15 =
Profile_HR_Managers_16 =
Profile_P_O_Admins_17 =
Profile_Project_Managers_18 =
...

I found the proc ns_get_multipart_formdata
http://www.aolserver.com/docs/devel/tcl/api/conn.html#ns_get_multipart_formdata

But it is used to files, not to arrays.

Collapse
Posted by Dave Bauer on
Hi,

I suspect you are making this more complicated than it needs to be.

Can you step back and explain what you are trying to accomplish? I think there is something more I need to know to give you advice on the best solution.

I don't think passing a multirow through multiple page requests is a good idea and there probably is a much simpler solution.

In general it is best to use the database to persist values between requests. That is a core feature of openacs.

Collapse
Posted by Iuri Sampaio on
Thanks Dave.

The answer is here

set myform [ns_getform]
if {[string equal "" $myform]} {
ns_log Notice "No Form was submited"
} else {
ns_log Notice "FORM"
# ns_set print $myform

for {set i 0} {$i < [ns_set size $myform]} {incr i} {
set varname [ns_set key $myform $i]
set varvalue [ns_set value $myform $i]

ns_log Notice " $varname - $varvalue"
}
}

The form has been passed properly through the pages. The issue was just how to get the values.

I wasn't making anything complicated i was just using the existing page and code without touching too much on its structure