<div> </div>
<div>Finally my module code looks as below. I am trying to make use of AHAH (&quot;Add More Companies...&quot; button), to add next row containing company name, start date and end date fields. On clicking &quot;Add More Companies...&quot; button, I am getting a dialog and says <strong>Error occured</strong>. Please suggest me, where I am going wrong.</div>

<div> </div>
<div> </div>
<div><font color="#3333ff">&lt;?php</font></div>
<div><font color="#3333ff">function submitresume_menu() {<br> $items = array();<br> $items[&#39;submitresume/form&#39;] = array(<br> &#39;title&#39; =&gt; t(&#39;Submit Your Resume&#39;),<br> &#39;page callback&#39; =&gt; &#39;submitresume_form&#39;,<br>
 &#39;access arguments&#39; =&gt; array(&#39;access content&#39;),<br> &#39;description&#39; =&gt; t(&#39;Submit Your Resume&#39;),<br> &#39;type&#39; =&gt; MENU_CALLBACK,<br> );</font></div>
<div><font color="#3333ff"> $items[&#39;submitresume/form/morecompanies&#39;] = array(<br> &#39;page callback&#39; =&gt; &#39;submitresume_my_form_add_more_companies&#39;,<br> &#39;access arguments&#39; =&gt; array(&#39;access content&#39;),<br>
 &#39;type&#39; =&gt; MENU_CALLBACK,<br> );</font></div>
<div><font color="#3333ff"> return $items;<br>}</font></div>
<div><font color="#3333ff">function submitresume_form() {<br> return drupal_get_form(&#39;submitresume_my_form&#39;);<br>}</font></div>
<div><font color="#3333ff">function submitresume_my_form($form_state) {<br> <br> $form = array(&#39;#cache&#39; =&gt; TRUE,);<br>  <br> if (isset($form_state[&#39;all_companies&#39;])) {<br>  $all_companies = $form_state[&#39;all_companies&#39;];<br>
 }<br> else {<br>  $all_companies = 1;<br> }<br>  <br> $form[&#39;name&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;fieldset&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Personal Information&#39;),<br> &#39;#collapsible&#39; =&gt; TRUE,<br>
 &#39;#collapsed&#39; =&gt; FALSE,<br> );<br> $form[&#39;name&#39;][&#39;persname&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;textfield&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Name&#39;),<br> &#39;#required&#39; =&gt; TRUE,<br>
 &#39;#description&#39; =&gt; &quot;Please enter your name.&quot;,<br> &#39;#size&#39; =&gt; 20,<br> &#39;#maxlength&#39; =&gt; 20,<br> );<br> $form[&#39;name&#39;][&#39;email&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;textfield&#39;,<br>
 &#39;#title&#39; =&gt; t(&#39;Email ID&#39;),<br> &#39;#required&#39; =&gt; TRUE,<br> &#39;#description&#39; =&gt; &quot;Please enter your valid email-id.&quot;,<br> &#39;#size&#39; =&gt; 20,<br> &#39;#maxlength&#39; =&gt; 20,<br>
 );<br> $form[&#39;name&#39;][&#39;mobile&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;textfield&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Mobile Number&#39;),<br> &#39;#required&#39; =&gt; TRUE,<br> &#39;#description&#39; =&gt; &quot;Please enter your valid mobile number.&quot;,<br>
 &#39;#size&#39; =&gt; 20,<br> &#39;#maxlength&#39; =&gt; 20,<br> );</font></div>
<div><font color="#3333ff"> $form[&#39;name&#39;][&#39;birthdate&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;textfield&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Date of Birth&#39;),<br> &#39;#required&#39; =&gt; TRUE,<br>
 &#39;#description&#39; =&gt; &quot;Please enter your date of birth in DD/MM/YYYY format.&quot;,<br> &#39;#size&#39; =&gt; 20,<br> &#39;#maxlength&#39; =&gt; 20,<br> );</font></div>
<div><font color="#3333ff"> $form[&#39;work&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;fieldset&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Work Information&#39;),<br> &#39;#collapsible&#39; =&gt; TRUE,<br> &#39;#collapsed&#39; =&gt; FALSE,<br>
 );</font></div>
<div><font color="#3333ff"> $form[&#39;work&#39;][&#39;yearsexp&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;textfield&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Years of Experience&#39;),<br> &#39;#description&#39; =&gt; &quot;Please enter your years of experience.&quot;,<br>
 &#39;#size&#39; =&gt; 20,<br> &#39;#maxlength&#39; =&gt; 20,<br> );</font></div>
<div><font color="#3333ff"> $form[&#39;work&#39;][&#39;dlocation&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;textfield&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Preferred work location&#39;),<br> &#39;#description&#39; =&gt; &quot;Please enter your preferred work location.&quot;,<br>
 &#39;#size&#39; =&gt; 20,<br> &#39;#maxlength&#39; =&gt; 20,<br> );</font></div>
<div><font color="#3333ff"> $form[&#39;resume&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;file&#39;,<br> &#39;#title&#39; =&gt; &quot;Upload Resume&quot;,<br> &#39;#description&#39; =&gt; &#39;Browse and select your resume&#39;,<br>
 &#39;#required&#39; =&gt; TRUE,<br> ); </font></div>
<div><br><font color="#3333ff">////////////////////////////////////////////////////////////////<br>for ($delta = 0; $delta &lt; $all_companies; $delta++) <br>{<br> //Add a wrapper for the companies and add more button.<br>
 $form[&#39;work_history_wrapper&#39;] = array(<br> &#39;#title&#39; =&gt; t(&quot;Work history: Mention all the companies you gave worked so far&quot;),<br> &#39;#type&#39; =&gt; &#39;fieldset&#39;,<br> &#39;#collapsible&#39; =&gt; TRUE,<br>
 &#39;#collapsed&#39; =&gt; FALSE,<br> &#39;#prefix&#39; =&gt; &#39;&lt;div class=&quot;clear-block&quot; id=&quot;work-history-wrapper&quot;&gt;&#39;,<br> &#39;#suffix&#39; =&gt; &#39;&lt;/div&gt;&#39;,<br> );</font></div>

<div><font color="#3333ff"> //Container for just companies<br> $form[&#39;work_history_wrapper&#39;][&#39;allcompanies&#39;] = array(<br> &#39;#prefix&#39; =&gt; &#39;&lt;div id=&quot;all-companies&quot;&gt;&#39;,<br> &#39;#suffix&#39; =&gt; &#39;&lt;/div&gt;&#39;,<br>
 );</font></div>
<div><font color="#3333ff"> $form[&#39;work_history_wrapper&#39;][&#39;allcompanies&#39;][&#39;company&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;textfield&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Company&#39;),<br> &#39;#size&#39; =&gt; 30,<br>
 &#39;#maxlength&#39; =&gt; 100,<br> );</font></div>
<div><font color="#3333ff"> $form[&#39;work_history_wrapper&#39;][&#39;allcompanies&#39;][&#39;sdate&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;date&#39;,<br> &#39;#title&#39; =&gt; t(&#39;Start Date&#39;),<br> );</font></div>

<div><font color="#3333ff"> $form[&#39;work_history_wrapper&#39;][&#39;allcompanies&#39;][&#39;edate&#39;] = array(<br> &#39;#type&#39; =&gt; &#39;date&#39;,<br> &#39;#title&#39; =&gt; t(&#39;End Date&#39;),<br> );<br>}</font></div>

<div><font color="#3333ff"> $form[&#39;work_history_wrapper&#39;][&#39;morecompany&#39;] = array(<br>&#39;#type&#39; =&gt; &#39;submit&#39;,<br>&#39;#value&#39; =&gt; t(&#39;Add More Companies...&#39;),<br>&#39;#weight&#39; =&gt; 1,<br>
//&#39;#submit&#39; =&gt; array(&#39;add_more_companies_submit&#39;), // If no javascript action.<br>&#39;#ahah&#39; =&gt; array(      <br>&#39;path&#39; =&gt; &#39;submitresume/form/morecompanies&#39;,      <br>&#39;wrapper&#39; =&gt; &#39;work-history-wrapper&#39;,      <br>
&#39;method&#39; =&gt; &#39;replace&#39;,      <br>&#39;effect&#39; =&gt; &#39;fade&#39;,    <br>),<br>);</font></div>
<div><br><font color="#3333ff">///////////////////////////////////////////////////////////////</font></div>
<div><font color="#3333ff">$form[&#39;submit&#39;] = array(<br>&#39;#type&#39; =&gt; &#39;submit&#39;,<br>&#39;#value&#39; =&gt; &#39;Submit&#39;,<br>);</font></div>
<div><font color="#3333ff">return $form;<br>}</font></div>
<div><font color="#3333ff">function add_more_companies_submit($form, &amp;$form_state) {<br>  // Set the form to rebuild and run submit handlers.<br>  node_form_submit_build_node($form, $form_state);</font></div>
<div><font color="#3333ff">  // Make the changes we want to the form state.<br>  if ($form_state[&#39;values&#39;][&#39;morecompany&#39;]) {<br>    $n = $_GET[&#39;q&#39;] == &#39;submitresume/form/morecompanies&#39; ? 1 : 5;<br>
    $form_state[&#39;all_companies&#39;] = count($form_state[&#39;values&#39;][&#39;allcompanies&#39;]) + $n; <br>  }<br>}</font></div>
<div><br><font color="#3333ff">function  submitresume_my_form_add_more_companies() {<br>  include_once &#39;modules/node/node.pages.inc&#39;;<br>  $form_state = array(&#39;storage&#39; =&gt; NULL, &#39;submitted&#39; =&gt; FALSE);<br>
  $form_build_id = $_POST[&#39;form_build_id&#39;];<br>  // Get the form from the cache.<br>  $form = form_get_cache($form_build_id, $form_state);<br>  $args = $form[&#39;#parameters&#39;];<br>  $form_id = array_shift($args);<br>
  // We will run some of the submit handlers so we need to disable redirecting.<br>  $form[&#39;#redirect&#39;] = FALSE;<br>  // We need to process the form, prepare for that by setting a few internals<br>  // variables.<br>
  $form[&#39;#post&#39;] = $_POST;<br>  $form[&#39;#programmed&#39;] = FALSE;<br>  $form_state[&#39;post&#39;] = $_POST;<br>  // Build, validate and if possible, submit the form.<br>  drupal_process_form($form_id, $form, $form_state);<br>
  // This call recreates the form relying solely on the form_state that the<br>  // drupal_process_form set up.<br>  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);<br>  // Render the new output.<br>
  $choice_form = $form[&#39;work_history_wrapper&#39;][&#39;allcompanies&#39;];<br>  unset($choice_form[&#39;#prefix&#39;], $choice_form[&#39;#suffix&#39;]); // Prevent duplicate wrappers.<br>  $output = theme(&#39;status_messages&#39;) . drupal_render($choice_form);</font></div>

<div><font color="#3333ff">  drupal_json(array(&#39;status&#39; =&gt; TRUE, &#39;data&#39; =&gt; $output));<br>}</font></div>
<div><font color="#3333ff">function submitresume_validate($form, &amp;$form_state) {<br>}</font></div>
<div><font color="#3333ff">// Adds a submit handler/function to our form to send a successful <br>// completion message to the screen.</font></div>
<div><br><font color="#3333ff">function submitresume_submit($form, &amp;$form_state) {<br>drupal_set_message(t(&#39;The form has been submitted.&#39;));<br>}<br>?&gt;</font></div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div><br><br> </div>
<div class="gmail_quote">On Thu, Mar 10, 2011 at 8:08 AM, Austin Einter <span dir="ltr">&lt;<a href="mailto:austin.einter@gmail.com">austin.einter@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hi </div>
<div>I am making a custom form, where I want to have work history of a person in one line and at the end of line a button &quot;add more&quot;.</div>
<div>It will look some thing like as below - </div>
<div> </div>
<div><strong><font color="#3333ff">Company  </font></strong>       <strong><font color="#3333ff">Start-Date</font></strong>      <font color="#3333ff"><strong>End-Date</strong></font>       <font color="#ff0000"><strong>Add More ...</strong></font></div>

<div><strong><font color="#ff0000"></font></strong> </div>
<div>If user clicks on button &quot;<strong><font color="#ff0000">Add More ...</font></strong>&quot; then it should add one more line and my form should look as below</div>
<div> </div>
<div>
<div><strong><font color="#3333ff">Company  </font></strong>       <strong><font color="#3333ff">Start-Date</font></strong>      <font color="#3333ff"><strong>End-Date</strong></font>       <font color="#ff0000"><strong>Add More ...</strong></font></div>

<div>
<div><strong><font color="#3333ff">Company  </font></strong>       <strong><font color="#3333ff">Start-Date</font></strong>      <font color="#3333ff"><strong>End-Date</strong></font>       <font color="#ff0000"><strong>Add More ...</strong></font></div>
</div></div>
<div> </div>
<div>So how many times user clicks &quot;<strong><font color="#ff0000">Add More ...</font></strong>&quot;, those many rows should be shown up.</div>
<div> </div>
<div>How can I acheive it  in Drupal. As per documentation and google search AHAH is capable of doing it.</div>
<div>Please correct me if wrong.</div>
<div> </div>
<div>My custom form code is as below. My questions are - </div>
<div> </div>
<div>1. How can I add 4 fields in one line. By default these are coming  below of earlier field.</div>
<div>2. How to make use of AHAH.</div>
<div>3. Also  one more challenge for me is how do act on &quot;onClick&quot; of  &quot;<strong><font color="#ff0000">Add More ...</font></strong>&quot; button, by default it may call submit handler.</div>
<div> </div>
<div>A step by step approach will help me, as first time I am looking at AHAH.</div>
<div> </div>
<div> Best Regards</div>
<div>Austin</div><font color="#888888">
<div> </div>
<div> </div></font></blockquote></div><br>