2 added 1769 characters in body
source | link

(Sorry for my bad English)

I’m building multi steps form with help of FAPI in front-end section. In the final step of my form I want use some third party js libraries for few task (like uploading file). But my problems begin here. How wrap these js libraries to the FAPI and make ajax callback function. This libraries make dynamic elements and I don’t know how connect theirs event to FAPI system. (Plupload is good example of this js libraries that create dynamic upload button ) I know already that I can use default #ajax callback, but this is for predefined drupal elements like textbox, button,… in FAPI system.

My first idea (didn’t work): deceive drupal FAPI. I get form_id and form_build_id of my form with help of jQuery and make ajax post to q=system/ajax url. But drupal make new form and reset form_state of my old form.

My second idea (I don’t know how implement it): make custom FAPI element for each js library and used it on form. I’m familiar with _element_info hook but unfortunately for complex library like plupload it’s hard for me to accomplish this.

#

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7

http://www.plupload.com/

My form made of thousand lines of code but I try to explain more: In drupal FAPI you use ajax like this (In below code if you click on ‘click me’ button, drupal call ajax_append_callback($form,$form_state){} function but keep value of $form, $form_state and doesn’t make new form. So in the function you can modify $form_state each time. In this case you could hold the number of user click on ‘click me’ button. (if $form_state reset each time of callback invoke, form is stateless.

But remember, you could do this operation only on predefine type of FAPI elements like , button, checkbox,select,…

   $form['anyform'] = array(
  '#value' => t("click me"),
  '#type' => 'submit',
  '#ajax' => array(
  'callback' => 'ajax_append_callback',
),

);

So I made a multistep form with help of $form_state. After each steps state(or values) of form elements stored in $form_state. In final step of my form, I like to use some third party library like plupload. But plupload buttons, are not defined in FAPI system and you can’t use something like below (maybe with help of _element_info hook, it would be possible)

      $form['anyform'] = array(
'#value' => t("click me"),
'#type' => 'plupload',
'#ajax' => array(
  'callback' => 'ajax_append_callback',
),

);

In plupload, when you press upload button, it send files to custom url that you set already. I set url path of upload to ‘system/ajax’ (default drupal path for handling ajax request). In addition force plupload to post ‘fomr_id’ and ‘form_build_id’ of my form to ‘system/ajax’ path. This doesn’t work too. I set url path of upload to my form page menu path. But drupal make my form reset and clean $form_state.

(Sorry for my bad English)

I’m building multi steps form with help of FAPI in front-end section. In the final step of my form I want use some third party js libraries for few task (like uploading file). But my problems begin here. How wrap these js libraries to the FAPI and make ajax callback function. This libraries make dynamic elements and I don’t know how connect theirs event to FAPI system. (Plupload is good example of this js libraries that create dynamic upload button ) I know already that I can use default #ajax callback, but this is for predefined drupal elements like textbox, button,… in FAPI system.

My first idea (didn’t work): deceive drupal FAPI. I get form_id and form_build_id of my form with help of jQuery and make ajax post to q=system/ajax url. But drupal make new form and reset form_state of my old form.

My second idea (I don’t know how implement it): make custom FAPI element for each js library and used it on form. I’m familiar with _element_info hook but unfortunately for complex library like plupload it’s hard for me to accomplish this.

#

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7

http://www.plupload.com/

(Sorry for my bad English)

I’m building multi steps form with help of FAPI in front-end section. In the final step of my form I want use some third party js libraries for few task (like uploading file). But my problems begin here. How wrap these js libraries to the FAPI and make ajax callback function. This libraries make dynamic elements and I don’t know how connect theirs event to FAPI system. (Plupload is good example of this js libraries that create dynamic upload button ) I know already that I can use default #ajax callback, but this is for predefined drupal elements like textbox, button,… in FAPI system.

My first idea (didn’t work): deceive drupal FAPI. I get form_id and form_build_id of my form with help of jQuery and make ajax post to q=system/ajax url. But drupal make new form and reset form_state of my old form.

My second idea (I don’t know how implement it): make custom FAPI element for each js library and used it on form. I’m familiar with _element_info hook but unfortunately for complex library like plupload it’s hard for me to accomplish this.

#

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7

http://www.plupload.com/

My form made of thousand lines of code but I try to explain more: In drupal FAPI you use ajax like this (In below code if you click on ‘click me’ button, drupal call ajax_append_callback($form,$form_state){} function but keep value of $form, $form_state and doesn’t make new form. So in the function you can modify $form_state each time. In this case you could hold the number of user click on ‘click me’ button. (if $form_state reset each time of callback invoke, form is stateless.

But remember, you could do this operation only on predefine type of FAPI elements like , button, checkbox,select,…

   $form['anyform'] = array(
  '#value' => t("click me"),
  '#type' => 'submit',
  '#ajax' => array(
  'callback' => 'ajax_append_callback',
),

);

So I made a multistep form with help of $form_state. After each steps state(or values) of form elements stored in $form_state. In final step of my form, I like to use some third party library like plupload. But plupload buttons, are not defined in FAPI system and you can’t use something like below (maybe with help of _element_info hook, it would be possible)

      $form['anyform'] = array(
'#value' => t("click me"),
'#type' => 'plupload',
'#ajax' => array(
  'callback' => 'ajax_append_callback',
),

);

In plupload, when you press upload button, it send files to custom url that you set already. I set url path of upload to ‘system/ajax’ (default drupal path for handling ajax request). In addition force plupload to post ‘fomr_id’ and ‘form_build_id’ of my form to ‘system/ajax’ path. This doesn’t work too. I set url path of upload to my form page menu path. But drupal make my form reset and clean $form_state.

1
source | link

Change form_state values with custom ajax call but without #ajax commands (fapi)?

(Sorry for my bad English)

I’m building multi steps form with help of FAPI in front-end section. In the final step of my form I want use some third party js libraries for few task (like uploading file). But my problems begin here. How wrap these js libraries to the FAPI and make ajax callback function. This libraries make dynamic elements and I don’t know how connect theirs event to FAPI system. (Plupload is good example of this js libraries that create dynamic upload button ) I know already that I can use default #ajax callback, but this is for predefined drupal elements like textbox, button,… in FAPI system.

My first idea (didn’t work): deceive drupal FAPI. I get form_id and form_build_id of my form with help of jQuery and make ajax post to q=system/ajax url. But drupal make new form and reset form_state of my old form.

My second idea (I don’t know how implement it): make custom FAPI element for each js library and used it on form. I’m familiar with _element_info hook but unfortunately for complex library like plupload it’s hard for me to accomplish this.

#

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7

http://www.plupload.com/