<div> </div>
<div>Finally my module code looks as below. I am trying to make use of AHAH ("Add More Companies..." button), to add next row containing company name, start date and end date fields. On clicking "Add More Companies..." 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"><?php</font></div>
<div><font color="#3333ff">function submitresume_menu() {<br> $items = array();<br> $items['submitresume/form'] = array(<br> 'title' => t('Submit Your Resume'),<br> 'page callback' => 'submitresume_form',<br>
'access arguments' => array('access content'),<br> 'description' => t('Submit Your Resume'),<br> 'type' => MENU_CALLBACK,<br> );</font></div>
<div><font color="#3333ff"> $items['submitresume/form/morecompanies'] = array(<br> 'page callback' => 'submitresume_my_form_add_more_companies',<br> 'access arguments' => array('access content'),<br>
'type' => 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('submitresume_my_form');<br>}</font></div>
<div><font color="#3333ff">function submitresume_my_form($form_state) {<br> <br> $form = array('#cache' => TRUE,);<br> <br> if (isset($form_state['all_companies'])) {<br> $all_companies = $form_state['all_companies'];<br>
}<br> else {<br> $all_companies = 1;<br> }<br> <br> $form['name'] = array(<br> '#type' => 'fieldset',<br> '#title' => t('Personal Information'),<br> '#collapsible' => TRUE,<br>
'#collapsed' => FALSE,<br> );<br> $form['name']['persname'] = array(<br> '#type' => 'textfield',<br> '#title' => t('Name'),<br> '#required' => TRUE,<br>
'#description' => "Please enter your name.",<br> '#size' => 20,<br> '#maxlength' => 20,<br> );<br> $form['name']['email'] = array(<br> '#type' => 'textfield',<br>
'#title' => t('Email ID'),<br> '#required' => TRUE,<br> '#description' => "Please enter your valid email-id.",<br> '#size' => 20,<br> '#maxlength' => 20,<br>
);<br> $form['name']['mobile'] = array(<br> '#type' => 'textfield',<br> '#title' => t('Mobile Number'),<br> '#required' => TRUE,<br> '#description' => "Please enter your valid mobile number.",<br>
'#size' => 20,<br> '#maxlength' => 20,<br> );</font></div>
<div><font color="#3333ff"> $form['name']['birthdate'] = array(<br> '#type' => 'textfield',<br> '#title' => t('Date of Birth'),<br> '#required' => TRUE,<br>
'#description' => "Please enter your date of birth in DD/MM/YYYY format.",<br> '#size' => 20,<br> '#maxlength' => 20,<br> );</font></div>
<div><font color="#3333ff"> $form['work'] = array(<br> '#type' => 'fieldset',<br> '#title' => t('Work Information'),<br> '#collapsible' => TRUE,<br> '#collapsed' => FALSE,<br>
);</font></div>
<div><font color="#3333ff"> $form['work']['yearsexp'] = array(<br> '#type' => 'textfield',<br> '#title' => t('Years of Experience'),<br> '#description' => "Please enter your years of experience.",<br>
'#size' => 20,<br> '#maxlength' => 20,<br> );</font></div>
<div><font color="#3333ff"> $form['work']['dlocation'] = array(<br> '#type' => 'textfield',<br> '#title' => t('Preferred work location'),<br> '#description' => "Please enter your preferred work location.",<br>
'#size' => 20,<br> '#maxlength' => 20,<br> );</font></div>
<div><font color="#3333ff"> $form['resume'] = array(<br> '#type' => 'file',<br> '#title' => "Upload Resume",<br> '#description' => 'Browse and select your resume',<br>
'#required' => TRUE,<br> ); </font></div>
<div><br><font color="#3333ff">////////////////////////////////////////////////////////////////<br>for ($delta = 0; $delta < $all_companies; $delta++) <br>{<br> //Add a wrapper for the companies and add more button.<br>
$form['work_history_wrapper'] = array(<br> '#title' => t("Work history: Mention all the companies you gave worked so far"),<br> '#type' => 'fieldset',<br> '#collapsible' => TRUE,<br>
'#collapsed' => FALSE,<br> '#prefix' => '<div class="clear-block" id="work-history-wrapper">',<br> '#suffix' => '</div>',<br> );</font></div>
<div><font color="#3333ff"> //Container for just companies<br> $form['work_history_wrapper']['allcompanies'] = array(<br> '#prefix' => '<div id="all-companies">',<br> '#suffix' => '</div>',<br>
);</font></div>
<div><font color="#3333ff"> $form['work_history_wrapper']['allcompanies']['company'] = array(<br> '#type' => 'textfield',<br> '#title' => t('Company'),<br> '#size' => 30,<br>
'#maxlength' => 100,<br> );</font></div>
<div><font color="#3333ff"> $form['work_history_wrapper']['allcompanies']['sdate'] = array(<br> '#type' => 'date',<br> '#title' => t('Start Date'),<br> );</font></div>
<div><font color="#3333ff"> $form['work_history_wrapper']['allcompanies']['edate'] = array(<br> '#type' => 'date',<br> '#title' => t('End Date'),<br> );<br>}</font></div>
<div><font color="#3333ff"> $form['work_history_wrapper']['morecompany'] = array(<br>'#type' => 'submit',<br>'#value' => t('Add More Companies...'),<br>'#weight' => 1,<br>
//'#submit' => array('add_more_companies_submit'), // If no javascript action.<br>'#ahah' => array( <br>'path' => 'submitresume/form/morecompanies', <br>'wrapper' => 'work-history-wrapper', <br>
'method' => 'replace', <br>'effect' => 'fade', <br>),<br>);</font></div>
<div><br><font color="#3333ff">///////////////////////////////////////////////////////////////</font></div>
<div><font color="#3333ff">$form['submit'] = array(<br>'#type' => 'submit',<br>'#value' => 'Submit',<br>);</font></div>
<div><font color="#3333ff">return $form;<br>}</font></div>
<div><font color="#3333ff">function add_more_companies_submit($form, &$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['values']['morecompany']) {<br> $n = $_GET['q'] == 'submitresume/form/morecompanies' ? 1 : 5;<br>
$form_state['all_companies'] = count($form_state['values']['allcompanies']) + $n; <br> }<br>}</font></div>
<div><br><font color="#3333ff">function submitresume_my_form_add_more_companies() {<br> include_once 'modules/node/node.pages.inc';<br> $form_state = array('storage' => NULL, 'submitted' => FALSE);<br>
$form_build_id = $_POST['form_build_id'];<br> // Get the form from the cache.<br> $form = form_get_cache($form_build_id, $form_state);<br> $args = $form['#parameters'];<br> $form_id = array_shift($args);<br>
// We will run some of the submit handlers so we need to disable redirecting.<br> $form['#redirect'] = FALSE;<br> // We need to process the form, prepare for that by setting a few internals<br> // variables.<br>
$form['#post'] = $_POST;<br> $form['#programmed'] = FALSE;<br> $form_state['post'] = $_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['work_history_wrapper']['allcompanies'];<br> unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers.<br> $output = theme('status_messages') . drupal_render($choice_form);</font></div>
<div><font color="#3333ff"> drupal_json(array('status' => TRUE, 'data' => $output));<br>}</font></div>
<div><font color="#3333ff">function submitresume_validate($form, &$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, &$form_state) {<br>drupal_set_message(t('The form has been submitted.'));<br>}<br>?></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"><<a href="mailto:austin.einter@gmail.com">austin.einter@gmail.com</a>></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 "add more".</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 "<strong><font color="#ff0000">Add More ...</font></strong>" 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 "<strong><font color="#ff0000">Add More ...</font></strong>", 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 "onClick" of "<strong><font color="#ff0000">Add More ...</font></strong>" 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>