Alter field value in a form I've created a module so users can insert a link.

When users will insert their link, i wish to add a suffix to the link.

For exemple : they will add a link > "www.test.com"

I want to be able to add to the link once they hit save "http://"

So the link will be http://www.test.com

When i do :

$form['attributes']['href']['#prefix'] = 'prefix';


I get :


What's the best way to do it without using $form['attributes']['href']['#default_value']

Many thanks,
As you want the suffix to be added when the save button is added you need to add a custom submit handler. In the hook_form_alter do something like       $form['actions']['submit']['#submit'][] = 'mymodule_form_submit'; and in the submit function mymodule_form_submit save the value you want.

function mymodule_form_submit(&amp;$form, FormStateInterface $form_state) {
  $entity = $form_state-&gt;getFormObject()-&gt;getEntity();
  // Get the value of your field
  $my_val = $entity-&gt;get('field_name')-&gt;getValue();
  // Set new value
  $entity-&gt;set('field_name', 'http://' . $my_val);
  //Save the entity
  $entity-&gt;save();
}