XF 2.1 add new field to contact form

asma

Member
Within the contact form .. I have name, email, subject and messages fields. Now, I have added "mobile" field to the form .. it shows correctly within the website.
However, the received email doesn't include the mobile number that the user entered .. I opened the email template, but I don't know how to configure it correctly
Please help

the contact form codes:

<xf:title>{{ phrase('contact_us') }}</xf:title> <xf:form action="{{ link('misc/contact') }}" class="block" ajax="true" data-force-flash-message="true"> <div class="block-container"> <div class="block-body"> <xf:if is="!$xf.visitor.user_id"> <xf:textboxrow name="username" autofocus="autofocus" maxlength="{{ max_length($xf.visitor, 'username') }}" label="{{ phrase('your_name') }}" required="required" hint="{{ phrase('required') }}" /> <xf:textboxrow name="email" maxlength="{{ max_length($xf.visitor, 'email') }}" type="email" label="{{ phrase('your_email_address') }}" required="required" hint="{{ phrase('required') }}" /> <xf:else /> <xf:formrow label="{{ phrase('your_name') }}">{$xf.visitor.username}</xf:formrow> <xf:if is="$xf.visitor.email"> <xf:formrow label="{{ phrase('your_email_address') }}">{$xf.visitor.email}</xf:formrow> <xf:else /> <xf:textboxrow name="email" type="email" label="{{ phrase('your_email_address') }}" required="required" hint="{{ phrase('required') }}" /> </xf:if> </xf:if> <xf:captcharow label="{{ phrase('verification') }}" hint="{{ phrase('required') }}" /> <xf:textboxrow name="mobile" label="{{ phrase('mobile') }}" required="required" hint="{{ phrase('required') }}" /> <xf:textboxrow name="subject" label="{{ phrase('subject') }}" required="required" hint="{{ phrase('required') }}" /> <xf:textarearow name="message" rows="5" autosize="true" label="{{ phrase('message') }}" required="required" hint="{{ phrase('required') }}" /> </div> <xf:submitrow submit="{{ phrase('send') }}" /> </div> <xf:redirect /> </xf:form>


contact email template:

<mail:subject> {{ phrase('contact_email_subject', { 'subject': $subject, 'board_title': $xf.options.boardTitle }) }} </mail:subject> {{ phrase('contact_email_body_html', { 'user': '<a href="mailto:' . $email . '">' . $name . ' &lt;' . {$email} . '&gt;</a>', 'ip': $ip, 'board': '<a href="' . link('canonical:index') . '">' . $xf.options.boardTitle . '</a>' }) }} <h2>{$subject}</h2> <div class="message">{$message|nl2br}</div>
 
There is a part between both!

1. Show form (change the form!)
2. Sent => data will be processed and sent to the template for email
3. email is sent.

You can view /src/xf/pub/controller/misc.php

Code:
    protected function setupContactService()
    {
        /** @var \XF\Service\Contact $contactService */
        $contactService = $this->service('XF:Contact');

        $visitor = \XF::visitor();

        $input = $this->filter([
            'username' => 'str',
            'email' => 'str',
            'subject' => 'str',
            'message' => 'str'
        ]);

So extend the class, extend the filter, then maybe just add the value of the new field to the message.
A coder should do this in ten minutes for you.
 
Top Bottom