<div>Thanks Randy.</div>
<div>I will try to use those examples as a starting point.</div>
<div> </div>
<div>Thanks</div>
<div>Austin<br><br></div>
<div class="gmail_quote">On Fri, Mar 11, 2011 at 11:59 AM, Randy Fay <span dir="ltr"><<a href="mailto:randy@randyfay.com">randy@randyfay.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Please start your investigations using the AHAH Example in the<br>Examples Project (<a href="http://drupal.org/project/examples" target="_blank">http://drupal.org/project/examples</a>) and<br>
<a href="http://randyfay.com/ahah" target="_blank">http://randyfay.com/ahah</a>. If you build a form starting with that<br>foundation, then please come back for help at that point.<br><br>Thanks,<br>-Randy<br>
<div>
<div></div>
<div class="h5"><br>On Thu, Mar 10, 2011 at 9:10 PM, Austin Einter <<a href="mailto:austin.einter@gmail.com">austin.einter@gmail.com</a>> wrote:<br>> Hi All<br>> I am quite new to AHAH, strugling to find how it works. I referred<br>
> documentation and poll module.<br>> I want 3 fields in a fieldset, Company, Start-Date, End-Date.<br>><br>> I have a button "Add More Company", if clicked, it should add a new row<br>> having Company, Start-Date, End-Date dynamically.<br>
> How many times user clicks, those many rows needs to be added.<br>><br>> To get the above mentioned form, I have put the code as below.<br>> However, on button click, new rows are not adding up.<br>><br>> Please help me to find whats the error with code.<br>
><br>> Regards,<br>> Austin<br>><br>> Code<br>> ===============================================<br>> <?php<br>> 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>> );<br>> $items['submitresume/form/morecompanies'] = array(<br>> 'page callback' => 'submitresume_add_more_companies',<br>> 'access arguments' => array('access content'),<br>
> 'type' => MENU_CALLBACK,<br>> );<br>> return $items;<br>> }<br>> function submitresume_form() {<br>> return drupal_get_form('submitresume_my_form');<br>> }<br>> function submitresume_my_form($form_state) {<br>
> $form = array('#cache' => TRUE,);<br>> if (isset($form_state['all_companies'])) {<br>> $all_companies = $form_state['all_companies'];<br>> }<br>> else {<br>> $all_companies = 1;<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<br>
> far"),<br>> '#type' => 'fieldset',<br>> '#collapsible' => TRUE,<br>> '#collapsed' => FALSE,<br>> '#prefix' => '<div class="clear-block" id="work-history-wrapper">',<br>
> '#suffix' => '</div>',<br>> );<br>> //Container for just companies<br>> $form['work_history_wrapper']['allcompanies'] = array(<br>> '#prefix' => '<div id="all-companies">',<br>
> '#suffix' => '</div>',<br>> );<br>> for ($delta = 0; $delta < $all_companies; $delta++)<br>> {<br>> //Need to do: Get the company name, start date and end date, pass it to<br>
> submitresume_add_one_company_form, so that it is shown properly<br>> $form['work_history_wrapper']['allcompanies'][$delta] =<br>> submitresume_add_one_company_form($delta, $company_name, $compsdt,<br>
> $compedt);<br>> }<br>> $form['work_history_wrapper']['morecompany'] = array(<br>> '#type' => 'button',<br>> '#value' => t('Add More Companies'),<br>
> '#weight' => 1,<br>> '#submit' => array('add_more_companies_submit'), // If no javascript<br>> action.<br>> '#ahah' => array(<br>> 'path' => 'submitresume/form/morecompanies',<br>
> 'wrapper' => 'all-companies',<br>> 'method' => 'replace',<br>> 'effect' => 'fade',<br>> ),<br>> );<br>><br>> $form['submit'] = array(<br>
> '#type' => 'submit',<br>> '#value' => 'Submit',<br>> );<br>> return $form;<br>> }<br>> function submitresume_add_one_company_form($delta, $company_name, $compsdt,<br>
> $compedt) {<br>> $form = array(<br>> '#tree' => TRUE,<br>> );<br>> $form['companies'] = array(<br>> '#type' => 'textfield',<br>> '#title' => t('Company')."-".$delta,<br>
> '#parents' => array('allcompanies', $delta, 'companies'),<br>> '#size' => 30,<br>> '#maxlength' => 100,<br>> );<br>> $form['startdate'] = array(<br>
> '#type' => 'date',<br>> '#title' => t('Start Date'),<br>> '#parents' => array('allcompanies', $delta, 'startdate'),<br>> );<br>> $form['enddate'] = array(<br>
> '#type' => 'date',<br>> '#title' => t('End Date'),<br>> '#parents' => array('allcompanies', $delta, 'enddate'),<br>> );<br>> return $form;<br>
> }<br>> 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);<br>> // 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'] =<br>> count($form_state['values']['allcompanies']) + $n;<br>
> }<br>> }<br>> function submitresume_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<br>> 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<br>> duplicate wrappers.<br>
> $output = theme('status_messages') . drupal_render($choice_form);<br>> drupal_json(array('status' => TRUE, 'data' => $output));<br>> }<br>> function submitresume_validate($form, &$form_state) {<br>
> }<br>> function submitresume_submit($form, &$form_state) {<br>> drupal_set_message(t('The form has been submitted.'));<br>> }<br>> ?><br>><br><br><br><br></div></div><font color="#888888">--<br>
Randy Fay<br>Drupal Module and Site Development<br><a href="mailto:randy@randyfay.com">randy@randyfay.com</a><br>+1 970.462.7450<br></font></blockquote></div><br>