<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="place"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I have not used form values in this way
before and am unsure if they will work this way. Typically $form_state[‘storage’]
is where you might place these values that are part the form that may be
modified by <st1:City w:st="on"><st1:place w:st="on">ajax</st1:place></st1:City>
callback handlers. Have you tried using $form_state[‘storage’]
instead of $form_state[‘values’] for your $all_categories data? <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
support-bounces@drupal.org [mailto:support-bounces@drupal.org] <b><span
style='font-weight:bold'>On Behalf Of </span></b>Kamal Palei<br>
<b><span style='font-weight:bold'>Sent:</span></b> Sunday, September 09, 2012
8:44 PM<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">support@drupal.org</st1:PersonName><br>
<b><span style='font-weight:bold'>Subject:</span></b> [support] Drupal 7
AHAH/AJAX issue</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Hi List<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I am trying to learn <st1:City w:st="on"><st1:place w:st="on">ajax</st1:place></st1:City>
stuff in Drupal 7.<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I want to have a simple <font color=gray><span style='color:gray'>questionnaire</span></font> form.
Where I will have a single textfield.<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>In that text field one will type a question category, and if he wants
to type more question categories, user need to click a button
"Add More Categories".<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Please see link <a
href="http://www.netcloudsystems.com/?q=questionnaire/form/manage">http://www.netcloudsystems.com/?q=questionnaire/form/manage</a><o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>The whole source code is at the end of this email. When <st1:City
w:st="on"><st1:place w:st="on">ajax</st1:place></st1:City> callback fires, I
want to remember how many textfields I need to add, so that when a section of
form is updated in _form() hook, I can according add those many textfields.<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I am trying to manage that using a variable "$all_categories"
and form element $form['all_categories'] (of type value).<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I tried many options, always I find $all_categories value is
1. So I am unable to add more textfields. <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>My observation is whatever I set in <st1:City w:st="on"><st1:place
w:st="on">ajax</st1:place></st1:City> callback, in _form hook api, I find
value is lost.<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Kindly guide me what I am missing.<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Best Regards<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Kamal<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><strong><b><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>NECS, <st1:City w:st="on"><st1:place w:st="on">Bangalore</st1:place></st1:City></span></font></b></strong><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'><?php</span></font></i></em><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'>function questionnaire_menu() {</span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman"> $items = array();</font></i></em><br>
<em><i><font face="Times New Roman"> </font></i></em><br>
<em><i><font face="Times New Roman"> $items['questionnaire/form/manage'] =
array(</font></i></em><br>
<em><i><font face="Times New Roman"> 'title' => t('Manage questions'),</font></i></em><br>
<em><i><font face="Times New Roman"> 'page callback' =>
'questionnaire_form',</font></i></em><br>
<em><i><font face="Times New Roman"> 'access arguments' =>
array('question manage'),</font></i></em><br>
<em><i><font face="Times New Roman"> 'type' => MENU_SUGGESTED_ITEM,</font></i></em><br>
<em><i><font face="Times New Roman"> );</font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'> return $items;</span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman">}</font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'>function questionnaire_permission() </span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman">{</font></i></em><br>
<em><i><font face="Times New Roman"> return array(</font></i></em><br>
<em><i><font face="Times New Roman"> 'question manage' => array(</font></i></em><br>
<em><i><font face="Times New Roman"> 'title' => t('Question
management'),</font></i></em><br>
<em><i><font face="Times New Roman"> 'description' =>
t('Provides question management capability'),</font></i></em><br>
<em><i><font face="Times New Roman"> ),</font></i></em><br>
<em><i><font face="Times New Roman"> );
</font></i></em><br>
<em><i><font face="Times New Roman">}</font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'>function questionnaire_form() </span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman">{</font></i></em><br>
<em><i><font face="Times New Roman"> return
drupal_get_form('questionnaire_my_form');</font></i></em><br>
<em><i><font face="Times New Roman">}</font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'>function questionnaire_my_form($form,
&$form_state) </span></font></i></em><i><font color="#000099"><span
style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman">{ </font></i></em><br>
<em><i><font face="Times New Roman"> $form_state['cache'] = TRUE;</font></i></em><br>
<em><i><font face="Times New Roman"> </font></i></em><br>
<em><i><font face="Times New Roman"> $all_categories =
!empty($form_state['values']['all_categories']) ?
$form_state['values']['all_categories'] : 1; </font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'> $form['all_categories'] = array(</span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman"> '#type' => 'value', </font></i></em><br>
<em><i><font face="Times New Roman"> '#default_value' =>
$all_categories,</font></i></em><br>
<em><i><font face="Times New Roman"> '#value' =>
$all_categories);</font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'> // The prefix/suffix
provide the div that we're replacing, named by </span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman"> // #<st1:City w:st="on"><st1:place
w:st="on">ajax</st1:place></st1:City>['wrapper'] above. </font></i></em><br>
<em><i><font face="Times New Roman"> $form['category_fieldset'] =
array( </font></i></em><br>
<em><i><font face="Times New Roman">
'#title' => t("Questions Categories"), </font></i></em><br>
<em><i><font face="Times New Roman">
'#prefix' => '<div id="category-div">', </font></i></em><br>
<em><i><font face="Times New Roman">
'#suffix' => '</div>', </font></i></em><br>
<em><i><font face="Times New Roman">
'#type' => 'fieldset', </font></i></em><br>
<em><i><font face="Times New Roman">
'#description' => t('Please enter the question categories'), </font></i></em><br>
<em><i><font face="Times New Roman"> );</font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
<em><i><font color="#000099" face="Times New Roman"><span style='color:#000099'>
for ($i=1; $i<= $all_categories ; $i++) </span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman"> { </font></i></em><br>
<em><i><font face="Times New Roman"> $key = 'ctg'
. $i;</font></i></em><br>
<em><i><font face="Times New Roman">
$form['category_fieldset']['category'][$key] =
array( </font></i></em><br>
<em><i><font face="Times New Roman">
'#type' => 'textfield', </font></i></em><br>
<em><i><font face="Times New Roman">
'#title' => "Question category $i", </font></i></em><br>
<em><i><font face="Times New Roman">
); </font></i></em><br>
<em><i><font face="Times New Roman"> } </font></i></em></span></font></i><o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'> $form['category_fieldset']['add_more_category']
= array( </span></font></i></em><i><font color="#000099"><span
style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman">
'#type' => 'submit',</font></i></em><br>
<em><i><font face="Times New Roman">
'#value' => t('Add More Categories'),</font></i></em><br>
<em><i><font face="Times New Roman">
'#<st1:City w:st="on"><st1:place w:st="on">ajax</st1:place></st1:City>' =>
array( </font></i></em><br>
<em><i><font face="Times New Roman">
'callback' => 'questionnaire_category_callback',</font></i></em><br>
<em><i><font face="Times New Roman">
'wrapper' => 'category-div', </font></i></em><br>
<em><i><font face="Times New Roman">
'method' => 'replace', </font></i></em><br>
<em><i><font face="Times New Roman">
'effect' => 'fade', </font></i></em><br>
<em><i><font face="Times New Roman">
), </font></i></em><br>
<em><i><font face="Times New Roman"> );</font></i></em><br>
<em><i><font face="Times New Roman"> </font></i></em><br>
<em><i><font face="Times New Roman"> $form['submit'] =
array( </font></i></em><br>
<em><i><font face="Times New Roman">
'#type' => 'submit', </font></i></em><br>
<em><i><font face="Times New Roman">
'#value' => t('Submit'), </font></i></em><br>
<em><i><font face="Times New Roman">
); </font></i></em><br>
<em><i><font face="Times New Roman"> </font></i></em><br>
<em><i><font face="Times New Roman"> return $form;</font></i></em><br>
<em><i><font face="Times New Roman">} </font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'>function
questionnaire_category_callback($form, &$form_state) </span></font></i></em><i><font
color="#000099"><span style='color:#000099;font-style:italic'><br>
<em><i><font face="Times New Roman">{ </font></i></em><br>
<em><i><font face="Times New Roman">
$form_state['values']['all_categories'] =
$form_state['values']['all_categories'] + 1;</font></i></em><br>
<em><i><font face="Times New Roman"> return $form['category_fieldset'];</font></i></em><br>
<em><i><font face="Times New Roman">}</font></i></em></span></font></i><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><em><i><font size=3 color="#000099" face="Times New Roman"><span
style='font-size:12.0pt;color:#000099'>?></span></font></i></em><o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
</div>
</div>
</body>
</html>