When a buyer goes through the checkout process as anonymous guest, he specifies his email at the "Order information" step in the input
<input data-drupal-selector="edit-contact-information-email" type="email" id="edit-contact-information-email" name="contact_information[email]" value="" size="60" maxlength="254" class="form-email required" required="required" aria-required="true">
The email is stored in the column mail
of the table commerce_order
of the database.
I would like to store a text string via this input in the database.
If I fill the input by JS with text string and even change the type
attribute of the input from email
to text
, the data is not stored in the DB. So there is email validating somewhere.
Where is the validating in JS or PHP?
Or how can I resolve the issue?
You should check the hook form_alter.
Also, you should take a look into the drupal checkout docs too:
https://docs.drupalcommerce.org/commerce2/user-guide/checkout/configure-checkout
You should be aware that changing a form type may impact all other places that needs to read this data.
Regarding the hook alter, Here goes an example.
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'myformID') {
$form['myformMachineName']['myfield']['#type'] = 'textfield';
}
}