I'm using cassiopeia template and the default contact form which is ok, except that the telephone number is missing. I want this adding after the e-mail field
I hope that someone can give me the clue, why the field is not added to the fieldset and how to solve it.
1. I've been trying this with a plugin first to inject field in the fieldset with onContentPrepareForm(Form $form, $data)
2. But later I thought, and thats the one I prefer, maybe it is better to make override of contact - default_form.php and inject the field into the fieldset like:But the number of fields is still 6 at the end, so the field is not added to the fieldset!!???
3. It is not the one I prefer but I have also tried straight were the fields are rendered, by adding:
I hope that someone can give me the clue, why the field is not added to the fieldset and how to solve it.
1. I've been trying this with a plugin first to inject field in the fieldset with onContentPrepareForm(Form $form, $data)
Code:
class PlgSystemAddTelephoneNumber extends CMSPlugin { public function onContentPrepareForm(Form $form, $data) { ... }
Code:
<?php foreach ($this->form->getFieldsets() as $fieldset) : ?> <?php if ($fieldset->name === 'captcha' && $this->captchaEnabled) : ?> <?php continue; ?> <?php endif; ?> <?php $fields = $this->form->getFieldset($fieldset->name); ?> <?php if ($fieldset->name === 'contact') { echo 'Dit is de fieldset name: '."$fieldset->name: " . count($fields);// $fieldset->name: = contact and number of fields is 6 $telephoneFieldXml = ' <field name="jform[contact_telephone]" type="text" label="Telephone" description="Please provide your phone number." required="false" filter="string" id="contact-telephone-field" />'; $telephoneField = new SimpleXMLElement($telephoneFieldXml); if ($telephoneField) {// $telephoneField = true echo '<pre>Telephone field created successfully.</pre>'; } else { echo '<pre>Error: Unable to create the telephone field.</pre>'; } $result = $this->form->setField($telephoneField, 'jform[contact_telephone]', 'contact'); echo '<pre>setField() result: ' . ($result ? 'true' : 'false') . '</pre>';// result is true // Refresh fields after adding $fields = $this->form->getFieldset($fieldset->name); echo 'Dit is de fieldset name: '."$fieldset->name: " . count($fields);// Number of fields is still 6!!?? } ?> <?php if (count($fields)) : ?>
3. It is not the one I prefer but I have also tried straight were the fields are rendered, by adding:
Code:
<?php if ($field->name === 'jform[contact_email]') : ?> ... than adding here the field
Statistics: Posted by nkamp — Sun Jan 05, 2025 9:15 pm