1

I built a AJAX form so that users can setup their user profiles after logging in. All basic text fields work/update fine. But I can't for the life of me get a image field (Picture) or file field (PDF Resume) to save.

The appropriate widget is displayed, and it allows me to upload the files (both image, and pdf) no problem. I can even see a preview of the image once it's uploaded. The files are definitely in the media section of the content admin page. BUT when I refresh the ajax form page the fields are empty again. Why is it not applying the uploads to the users profile fields?

All other fields update fine.

The form:

<form action="<?php print $ajax_form['#action']; ?>" method="post" id="<?php print $ajax_form['#id']; ?>-header" accept-charset="UTF-8">

<?php print render($ajax_form['user']['field_user_picture']); ?>
<?php print render($ajax_form['user']['field_resume']); ?>

<div class="single-line">
<?php print render($ajax_form['user']['field_user_first_name']['und'][0]) ?>
<?php print render($ajax_form['user']['field_user_last_name']['und'][0]) ?>
</div>

<?php print render($ajax_form['user']['field_user_title']['und'][0]) ?>
<?php print render($ajax_form['user']['field_user_location']['und'][0]) ?>
<?php print render($ajax_form['user']['field_user_summary']['und'][0]) ?>
<?php print render($ajax_form['form_build_id']); ?>
<?php print render($ajax_form['form_token']); ?>
<?php print render($ajax_form['form_id']); ?>
<?php print render($ajax_form['actions']); ?>
<input type="hidden" name="part" value="header"/>
</form>

and then:

 $form['account'] = array(
 '#type' => 'value',
 '#value' => $account,
 );

 $form['#action'] = '/ajax/' . $id . '/' . $type;
 $form['#id'] = 'ajax-form';

 $form_key = 'user';
 $form[$form_key] = array(
'#type' => 'fieldset',
'#title' => 'none',
'#parents' => array($form_key),
);
field_attach_form('user', $account, $form[$form_key], $form_state, LANGUAGE_NONE);

Thank you VERY kindly in advance, Alex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.