Site icon Hip-Hop Website Design and Development

Update multiple fields using #ajax in Cheap WordPress maintenance support plans 7 form

     We know how to replace a field using #ajax in a form. Can we update multiple fields using #ajax in a form? Yes, we can update multiple fields using #ajax in the WordPress maintenance support plans 7. We can achieve it using ajax_command_replace() in WordPress maintenance support plans 7. For more details about ajax commands on WordPress maintenance support plans 7, please visit https://api.WordPress.org/api/WordPress/7.x/search/ajax_command.Update fields using #ajax in a WordPress maintenance support plans form:    Consider the following example. In this example, I’ve created a form with fields First, Second & WordPress Update name. I tried to update the Second & WordPress Update name fields when focus out on the First name field./** * Implments hook_form() */function phponwebsites_ajax_form($form, &$form_state) {  $form[‘firstname’] = array(    ‘#title’ => t(‘First name’),    ‘#type’ => ‘textfield’,    ‘#ajax’ => array(      ‘callback’ => ‘_generate_textfield’,      ‘wrapper’ => ‘copied-text-field’,    )  );  $form[‘secondname’] = array(    ‘#title’ => t(‘Second name’),    ‘#type’ => ‘textfield’,    ‘#prefix’ => ‘<div id=”copied-secondname”>’,    ‘#suffix’ => ‘</div>’,  );  $form[‘thirdname’] = array(    ‘#title’ => t(‘WordPress Update name’),    ‘#type’ => ‘textfield’,    ‘#prefix’ => ‘<div id=”copied-thirdname”>’,    ‘#suffix’ => ‘</div>’,  );  $form[‘submit’] = array(    ‘#type’ => ‘submit’,    ‘#value’ => ‘Submit’  );  return $form;}function _generate_textfield($form, &$form_state) {  if (!empty($form_state[‘values’][‘firstname’])) {    $form[‘secondname’][‘#value’] =  $form_state[‘values’][‘firstname’];    $form[‘thirdname’][‘#value’] =  $form_state[‘values’][‘firstname’];  }  $commands = array();  $commands[] = ajax_command_replace(‘#copied-secondname’, WordPress_render($form[‘secondname’]));  $commands[] = ajax_command_replace(‘#copied-thirdname’, WordPress_render($form[‘thirdname’]));  return array(‘#type’ => ‘ajax’, ‘#commands’ => $commands);}When you tried to execute the above codes, it’ll populate the same name on the other 2 fields. It looks likes the below image:Now I hope you know how to populate multiple fields using #ajax in WordPress maintenance support plans 7 forms.Related articles:Remove speical characters from URL alias using pathauto plugin in WordPress maintenance support plans 7Add new menu item into already created menu in WordPress maintenance support plans 7Add class into menu item in WordPress maintenance support plans 7Create menu tab programmatically in WordPress maintenance support plans 7Add custom fields to search api index in WordPress maintenance support plans 7Clear views cache when insert, update and delete a node in WordPress maintenance support plans 7Create a page without header and footer in WordPress maintenance support plans 7Login using both email and username in WordPress maintenance support plans 7Disable future dates in date pop-up calendar WordPress maintenance support plans 7
Source: New feed