Hello,<div><br></div><div>Also consider using AHAH Helper (<a href="http://www.drupal.org/project/ahah_helper">http://www.drupal.org/project/ahah_helper</a>) module which significantly simplifies the usage of AHAH. Using AHAH Helper you only need to implement o form building function and submit/validate callbacks. The module comes with example module which explains the basic usage of its API.<br clear="all">
<br><div>--<div>Kindest regards,<br>Adam Ludwinski</div><div>Weever Web Warehouse<br>mobile: +48 606 107 297<br><a href="mailto:adam.ludwinski@weever.net" target="_blank">adam.ludwinski@weever.net</a><br><a href="http://www.weever.net/" target="_blank">http://www.weever.net</a></div>
<div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">Al. Jerozolimskie 87 piêtro 2<br>02-001 Warszawa</span></div><div><br></div><div><br></div><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">____________________________________________<br>
<br>Niniejsza wiadomosc wraz z ewentualnymi zalacznikami jest poufna i<br>stanowi prawnie zastrzezona korespondencje przeznaczona wylacznie dla<br>jej odbiorcy. Jesli odbiorca tej wiadomosci nie jest jej adresatem,<br>niniejszym informujemy, ze otrzymali ja Panstwo omylkowo. W zwiazku z<br>
tym prosimy o niezwloczne powiadomienie o tym nadawcy zwrotna poczta<br>elektroniczna oraz o usuniecie otrzymanej wiadomosci wraz z<br>ewentualnymi zalacznikami.<br><br>This e-mail message with any attached files is confidential and as a<br>
legally privileged correspondence is assigned exclusively for<br>recipient. If you are not intended recipient we inform that delivery<br>is made by mistake. Please notify the sender immediately and then<br>delete this e-mail with all attachments.<br>
____________________________________________</span></div></div><br>
<br><br><div class="gmail_quote">On 11 March 2011 09:12, Austin Einter <span dir="ltr"><<a href="mailto:austin.einter@gmail.com">austin.einter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>Thanks Randy.</div>
<div>I will try to use those examples as a starting point.</div>
<div> </div>
<div>Thanks</div>
<div>Austin<font color="#888888"><br><br></font></div><div><div></div><div class="h5">
<div class="gmail_quote">On Fri, Mar 11, 2011 at 11:59 AM, Randy Fay <span dir="ltr"><<a href="mailto:randy@randyfay.com" target="_blank">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><br>On Thu, Mar 10, 2011 at 9:10 PM, Austin Einter <<a href="mailto:austin.einter@gmail.com" target="_blank">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" target="_blank">randy@randyfay.com</a><br>+1 970.462.7450<br></font></blockquote></div><br>
</div></div></blockquote></div><br></div>