Hi 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". It will look some thing like as below -
*Company * *Start-Date* *End-Date* *Add More ...* ** If user clicks on button "*Add More ...*" then it should add one more line and my form should look as below
*Company * *Start-Date* *End-Date* *Add More ...* *Company * *Start-Date* *End-Date* *Add More ...*
So how many times user clicks "*Add More ...*", those many rows should be shown up.
How can I acheive it in Drupal. As per documentation and google search AHAH is capable of doing it. Please correct me if wrong.
My custom form code is as below. My questions are -
1. How can I add 4 fields in one line. By default these are coming below of earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add More ...*" button, by default it may call submit handler.
A step by step approach will help me, as first time I am looking at AHAH.
Best Regards Austin
You can use the 3.x Alpha 1 of CCK. http://drupal.org/project/cck
I used this on a site recently and it worked well.
Thanks,
Steve
Steve Kessler Owner, DenverDataMan (303) 587-4428
This email was sent from my Droid. On Mar 9, 2011 7:39 PM, "Austin Einter" austin.einter@gmail.com wrote:
Hi 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". It will look some thing like as below -
*Company * *Start-Date* *End-Date* *Add More ...* ** If user clicks on button "*Add More ...*" then it should add one more line and my form should look as below
*Company * *Start-Date* *End-Date* *Add More ...* *Company * *Start-Date* *End-Date* *Add More ...*
So how many times user clicks "*Add More ...*", those many rows should be shown up.
How can I acheive it in Drupal. As per documentation and google search
AHAH
is capable of doing it. Please correct me if wrong.
My custom form code is as below. My questions are -
- How can I add 4 fields in one line. By default these are coming below
of
earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add More ...*" button, by default it may call submit handler.
A step by step approach will help me, as first time I am looking at AHAH.
Best Regards Austin
Can this be achieved in Drual 7 as well, If so, can you please give a brief about it
On Thu, Mar 10, 2011 at 8:28 AM, Steve Kessler skessler@denverdataman.comwrote:
You can use the 3.x Alpha 1 of CCK. http://drupal.org/project/cck
I used this on a site recently and it worked well.
Thanks,
Steve
Steve Kessler Owner, DenverDataMan (303) 587-4428
This email was sent from my Droid. On Mar 9, 2011 7:39 PM, "Austin Einter" austin.einter@gmail.com wrote:
Hi 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". It will look some thing like as below -
*Company * *Start-Date* *End-Date* *Add More ...* ** If user clicks on button "*Add More ...*" then it should add one more
line
and my form should look as below
*Company * *Start-Date* *End-Date* *Add More ...* *Company * *Start-Date* *End-Date* *Add More ...*
So how many times user clicks "*Add More ...*", those many rows should be shown up.
How can I acheive it in Drupal. As per documentation and google search
AHAH
is capable of doing it. Please correct me if wrong.
My custom form code is as below. My questions are -
- How can I add 4 fields in one line. By default these are coming below
of
earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add
More
...*" button, by default it may call submit handler.
A step by step approach will help me, as first time I am looking at AHAH.
Best Regards Austin
-- [ Drupal support list | http://lists.drupal.org/ ]
Can this be achieved in Drual 7 as well, If so, can you please give a brief about it
Seems this is the way to do it in D7: http://drupal.org/project/field_collection
F
Thanks Steve. I wanted to do it through custom module because of certain reasons. I had three questions.
1. How can I add 4 fields in one line. By default these are coming below of earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add More ...*" button, by default it may call submit handler.
Now I have resolved 1st issue through CSS rules.
Please give me input on 2nd and 3rd questions.
Thanks
On Thu, Mar 10, 2011 at 8:28 AM, Steve Kessler skessler@denverdataman.comwrote:
You can use the 3.x Alpha 1 of CCK. http://drupal.org/project/cck
I used this on a site recently and it worked well.
Thanks,
Steve
Steve Kessler Owner, DenverDataMan (303) 587-4428
This email was sent from my Droid. On Mar 9, 2011 7:39 PM, "Austin Einter" austin.einter@gmail.com wrote:
Hi 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". It will look some thing like as below -
*Company * *Start-Date* *End-Date* *Add More ...* ** If user clicks on button "*Add More ...*" then it should add one more
line
and my form should look as below
*Company * *Start-Date* *End-Date* *Add More ...* *Company * *Start-Date* *End-Date* *Add More ...*
So how many times user clicks "*Add More ...*", those many rows should be shown up.
How can I acheive it in Drupal. As per documentation and google search
AHAH
is capable of doing it. Please correct me if wrong.
My custom form code is as below. My questions are -
- How can I add 4 fields in one line. By default these are coming below
of
earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add
More
...*" button, by default it may call submit handler.
A step by step approach will help me, as first time I am looking at AHAH.
Best Regards Austin
-- [ Drupal support list | http://lists.drupal.org/ ]
My form code is as below.
//Add a wrapper for the AHAH variables. $form['work_history_wrapper'] = array( '#title' => t("Work history: Mention all the companies you gave worked so far"), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, '#prefix' => '<div class="clear-block" id="work-history-wrapper">', '#suffix' => '</div>', ); $form['work_history_wrapper']['company'] = array( '#type' => 'textfield', '#title' => t('Company'), '#size' => 30, '#maxlength' => 100, ); $form['work_history_wrapper']['sdate'] = array( '#type' => 'date', '#title' => t('Start Date'), ); $form['work_history_wrapper']['edate'] = array( '#type' => 'date', '#title' => t('End Date'), ); $form['work_history_wrapper']['morecompany'] = array( '#type' => 'button', '#value' => 'Add More Company...', '#attributes' => array('onclick' => 'return false;'), );
Please let me know,, how can I make use of AHAH, so that on clicking add more company button, will add more rows.
Thanks
On Thu, Mar 10, 2011 at 3:16 PM, Austin Einter austin.einter@gmail.comwrote:
Thanks Steve. I wanted to do it through custom module because of certain reasons. I had three questions.
- How can I add 4 fields in one line. By default these are coming below
of earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add More ...*" button, by default it may call submit handler.
Now I have resolved 1st issue through CSS rules.
Please give me input on 2nd and 3rd questions.
Thanks
On Thu, Mar 10, 2011 at 8:28 AM, Steve Kessler < skessler@denverdataman.com> wrote:
You can use the 3.x Alpha 1 of CCK. http://drupal.org/project/cck
I used this on a site recently and it worked well.
Thanks,
Steve
Steve Kessler Owner, DenverDataMan (303) 587-4428
This email was sent from my Droid. On Mar 9, 2011 7:39 PM, "Austin Einter" austin.einter@gmail.com wrote:
Hi 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". It will look some thing like as below -
*Company * *Start-Date* *End-Date* *Add More ...* ** If user clicks on button "*Add More ...*" then it should add one more
line
and my form should look as below
*Company * *Start-Date* *End-Date* *Add More ...* *Company * *Start-Date* *End-Date* *Add More ...*
So how many times user clicks "*Add More ...*", those many rows should
be
shown up.
How can I acheive it in Drupal. As per documentation and google search
AHAH
is capable of doing it. Please correct me if wrong.
My custom form code is as below. My questions are -
- How can I add 4 fields in one line. By default these are coming below
of
earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add
More
...*" button, by default it may call submit handler.
A step by step approach will help me, as first time I am looking at
AHAH.
Best Regards Austin
-- [ Drupal support list | http://lists.drupal.org/ ]
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 *Error occured*. Please suggest me, where I am going wrong.
<?php function submitresume_menu() { $items = array(); $items['submitresume/form'] = array( 'title' => t('Submit Your Resume'), 'page callback' => 'submitresume_form', 'access arguments' => array('access content'), 'description' => t('Submit Your Resume'), 'type' => MENU_CALLBACK, ); $items['submitresume/form/morecompanies'] = array( 'page callback' => 'submitresume_my_form_add_more_companies', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function submitresume_form() { return drupal_get_form('submitresume_my_form'); } function submitresume_my_form($form_state) {
$form = array('#cache' => TRUE,);
if (isset($form_state['all_companies'])) { $all_companies = $form_state['all_companies']; } else { $all_companies = 1; }
$form['name'] = array( '#type' => 'fieldset', '#title' => t('Personal Information'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['name']['persname'] = array( '#type' => 'textfield', '#title' => t('Name'), '#required' => TRUE, '#description' => "Please enter your name.", '#size' => 20, '#maxlength' => 20, ); $form['name']['email'] = array( '#type' => 'textfield', '#title' => t('Email ID'), '#required' => TRUE, '#description' => "Please enter your valid email-id.", '#size' => 20, '#maxlength' => 20, ); $form['name']['mobile'] = array( '#type' => 'textfield', '#title' => t('Mobile Number'), '#required' => TRUE, '#description' => "Please enter your valid mobile number.", '#size' => 20, '#maxlength' => 20, ); $form['name']['birthdate'] = array( '#type' => 'textfield', '#title' => t('Date of Birth'), '#required' => TRUE, '#description' => "Please enter your date of birth in DD/MM/YYYY format.", '#size' => 20, '#maxlength' => 20, ); $form['work'] = array( '#type' => 'fieldset', '#title' => t('Work Information'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['work']['yearsexp'] = array( '#type' => 'textfield', '#title' => t('Years of Experience'), '#description' => "Please enter your years of experience.", '#size' => 20, '#maxlength' => 20, ); $form['work']['dlocation'] = array( '#type' => 'textfield', '#title' => t('Preferred work location'), '#description' => "Please enter your preferred work location.", '#size' => 20, '#maxlength' => 20, ); $form['resume'] = array( '#type' => 'file', '#title' => "Upload Resume", '#description' => 'Browse and select your resume', '#required' => TRUE, );
//////////////////////////////////////////////////////////////// for ($delta = 0; $delta < $all_companies; $delta++) { //Add a wrapper for the companies and add more button. $form['work_history_wrapper'] = array( '#title' => t("Work history: Mention all the companies you gave worked so far"), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, '#prefix' => '<div class="clear-block" id="work-history-wrapper">', '#suffix' => '</div>', ); //Container for just companies $form['work_history_wrapper']['allcompanies'] = array( '#prefix' => '<div id="all-companies">', '#suffix' => '</div>', ); $form['work_history_wrapper']['allcompanies']['company'] = array( '#type' => 'textfield', '#title' => t('Company'), '#size' => 30, '#maxlength' => 100, ); $form['work_history_wrapper']['allcompanies']['sdate'] = array( '#type' => 'date', '#title' => t('Start Date'), ); $form['work_history_wrapper']['allcompanies']['edate'] = array( '#type' => 'date', '#title' => t('End Date'), ); } $form['work_history_wrapper']['morecompany'] = array( '#type' => 'submit', '#value' => t('Add More Companies...'), '#weight' => 1, //'#submit' => array('add_more_companies_submit'), // If no javascript action. '#ahah' => array( 'path' => 'submitresume/form/morecompanies', 'wrapper' => 'work-history-wrapper', 'method' => 'replace', 'effect' => 'fade', ), );
/////////////////////////////////////////////////////////////// $form['submit'] = array( '#type' => 'submit', '#value' => 'Submit', ); return $form; } function add_more_companies_submit($form, &$form_state) { // Set the form to rebuild and run submit handlers. node_form_submit_build_node($form, $form_state); // Make the changes we want to the form state. if ($form_state['values']['morecompany']) { $n = $_GET['q'] == 'submitresume/form/morecompanies' ? 1 : 5; $form_state['all_companies'] = count($form_state['values']['allcompanies']) + $n; } }
function submitresume_my_form_add_more_companies() { include_once 'modules/node/node.pages.inc'; $form_state = array('storage' => NULL, 'submitted' => FALSE); $form_build_id = $_POST['form_build_id']; // Get the form from the cache. $form = form_get_cache($form_build_id, $form_state); $args = $form['#parameters']; $form_id = array_shift($args); // We will run some of the submit handlers so we need to disable redirecting. $form['#redirect'] = FALSE; // We need to process the form, prepare for that by setting a few internals // variables. $form['#post'] = $_POST; $form['#programmed'] = FALSE; $form_state['post'] = $_POST; // Build, validate and if possible, submit the form. drupal_process_form($form_id, $form, $form_state); // This call recreates the form relying solely on the form_state that the // drupal_process_form set up. $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); // Render the new output. $choice_form = $form['work_history_wrapper']['allcompanies']; unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers. $output = theme('status_messages') . drupal_render($choice_form); drupal_json(array('status' => TRUE, 'data' => $output)); } function submitresume_validate($form, &$form_state) { } // Adds a submit handler/function to our form to send a successful // completion message to the screen.
function submitresume_submit($form, &$form_state) { drupal_set_message(t('The form has been submitted.')); } ?>
On Thu, Mar 10, 2011 at 8:08 AM, Austin Einter austin.einter@gmail.comwrote:
Hi 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". It will look some thing like as below -
*Company * *Start-Date* *End-Date* *Add More ...* ** If user clicks on button "*Add More ...*" then it should add one more line and my form should look as below
*Company * *Start-Date* *End-Date* *Add More ...* *Company * *Start-Date* *End-Date* *Add More ...*
So how many times user clicks "*Add More ...*", those many rows should be shown up.
How can I acheive it in Drupal. As per documentation and google search AHAH is capable of doing it. Please correct me if wrong.
My custom form code is as below. My questions are -
- How can I add 4 fields in one line. By default these are coming below
of earlier field. 2. How to make use of AHAH. 3. Also one more challenge for me is how do act on "onClick" of "*Add More ...*" button, by default it may call submit handler.
A step by step approach will help me, as first time I am looking at AHAH.
Best Regards Austin