2 added 59 characters in body
source | link

I have a classic contact form. I can add for example some custom placeholder like this :

function my_theme_form_contact_message_about_your_project_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    // placeholder
    $form['field_contact_name']['widget'][0]['value']['#placeholder'] = t('Saisir votre nom');

} 

It works very well and I can also easily modify wrapper, name, etc.

But for a reason I can’t understand, I am not able to modify the text of the submit button.

Here is what I’ve tried among a lot of things and I think it should be the right thing (as seen on other answers) :

$form['op']['submit']['#value']$form['actions']['submit']['#value'] = t('Post'hello Comments');world!';

Here is the html of the button :

<button data-drupal-selector="edit-submit" class="button button--primary js-form-submit form-submit btn-primary btn" type="submit" id="edit-submit" name="op" value="Envoyer">Envoyer</button>

I use a custom theme based on Bootstrap theme. Do you know why it is not working ? Maybe it is because it’s a button and not a input type="submit" ? Is it a syntax issue ?

Of course, I can do it with jQuery :

$('#edit-submit').text('lorem ipsum');

But I would like to know how to do it the Drupal way.

EDIT :

The solution is :

form['actions']['submit']['#value'] = 'hello world!';

It works on a clean Drupal install but not on the website I am currently working on. 

I have a classic contact form. I can add for example some custom placeholder like this :

function my_theme_form_contact_message_about_your_project_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    // placeholder
    $form['field_contact_name']['widget'][0]['value']['#placeholder'] = t('Saisir votre nom');

} 

It works very well and I can also easily modify wrapper, name, etc.

But for a reason I can’t understand, I am not able to modify the text of the submit button.

Here is what I’ve tried among a lot of things and I think it should be the right thing :

$form['op']['submit']['#value'] = t('Post Comments');

Here is the html of the button :

<button data-drupal-selector="edit-submit" class="button button--primary js-form-submit form-submit btn-primary btn" type="submit" id="edit-submit" name="op" value="Envoyer">Envoyer</button>

I use a custom theme based on Bootstrap theme. Do you know why it is not working ? Maybe it is because it’s a button and not a input type="submit" ? Is it a syntax issue ?

Of course, I can do it with jQuery :

$('#edit-submit').text('lorem ipsum');

But I would like to know how to do it the Drupal way.

I have a classic contact form. I can add for example some custom placeholder like this :

function my_theme_form_contact_message_about_your_project_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    // placeholder
    $form['field_contact_name']['widget'][0]['value']['#placeholder'] = t('Saisir votre nom');

} 

It works very well and I can also easily modify wrapper, name, etc.

But for a reason I can’t understand, I am not able to modify the text of the submit button.

Here is what I’ve tried among a lot of things and I think it should be the right thing (as seen on other answers) :

$form['actions']['submit']['#value'] = 'hello world!';

Here is the html of the button :

<button data-drupal-selector="edit-submit" class="button button--primary js-form-submit form-submit btn-primary btn" type="submit" id="edit-submit" name="op" value="Envoyer">Envoyer</button>

I use a custom theme based on Bootstrap theme.

Of course, I can do it with jQuery :

$('#edit-submit').text('lorem ipsum');

But I would like to know how to do it the Drupal way.

EDIT :

The solution is :

form['actions']['submit']['#value'] = 'hello world!';

It works on a clean Drupal install but not on the website I am currently working on. 

1
source | link

Custom submit button text

I have a classic contact form. I can add for example some custom placeholder like this :

function my_theme_form_contact_message_about_your_project_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    // placeholder
    $form['field_contact_name']['widget'][0]['value']['#placeholder'] = t('Saisir votre nom');

} 

It works very well and I can also easily modify wrapper, name, etc.

But for a reason I can’t understand, I am not able to modify the text of the submit button.

Here is what I’ve tried among a lot of things and I think it should be the right thing :

$form['op']['submit']['#value'] = t('Post Comments');

Here is the html of the button :

<button data-drupal-selector="edit-submit" class="button button--primary js-form-submit form-submit btn-primary btn" type="submit" id="edit-submit" name="op" value="Envoyer">Envoyer</button>

I use a custom theme based on Bootstrap theme. Do you know why it is not working ? Maybe it is because it’s a button and not a input type="submit" ? Is it a syntax issue ?

Of course, I can do it with jQuery :

$('#edit-submit').text('lorem ipsum');

But I would like to know how to do it the Drupal way.