0

I use a custom module to change the text of my register form submit button:

<?php
function registration_button_override_form_alter(&$form, &$form_state, $form_id)
{
  //check to see if user is logged in so that this is only displayed to anon users that are registering
     global $user;
     if ($user->uid == 0) {
     if ($form_id == 'user_register_form') {

     // Change register button text.
     $form['actions']['submit']['#value'] = t('Jetzt registrieren'); 

     }
  }
}
?>

This works fine. Now, I try to adjust this code that the button label text changes if a certain field on the registration form has a certain value selected.

I added this line:

if (isset($row->field_data_field_registrierung_als[0]['value']) == 1)

This doesn't work. When thinking about it the form probably should load again in order to change the text, right? Does somebody know how this could be done?

EDIT:

My HTML:

<select id="edit-field-registrierung-als-und" name="field_registrierung_als[und]" class="form-select required">
<option value="_none">- Wert wählen -</option>
<option value="1">A</option>
<option value="2">B</option>
</select>

<input id="edit-submit--2" name="op" value="Neues Benutzerkonto erstellen" class="form-submit" type="submit">

My jQuery:

(function ($) {
$("#edit-field-registrierung-als").change(function() {
if $( this.value == "2")
$("#edit-submit--2").val("Registrieren");
}
}) (jQuery);
0

First of all you don't need to check if isset is equals 1.

Then I think you must use the form_state or do this with jQuery, like this:

if(document.getElementById('checkbox-is').checked) {
  $("#submit-id").text("Jetzt registrieren");
}

UPDATE: I have edited your code to look like this:

(function ($) {
  $("#edit-field-registrierung-als").change(function() {
    if ($(this).value == "2") {
      $("#edit-submit--2").val("Registrieren");
    }
  }
}) (jQuery);
  • Thannks for your help. I've got this code now but it doesn't work (see edited question). Does somebody see a mistake in it? – ThuleNB May 4 '18 at 5:30
  • Try to take a look at the code i have updated. – user72672 May 4 '18 at 5:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.