Add custom field (Phone Number) to 'Ask A Question' form - VirtueMart 3 (SOLVED)

Started by SAWebCo, August 18, 2016, 21:01:04 PM

Previous topic - Next topic

SAWebCo

Joomla 3.6.2, VirtueMart 3.0.9, Live Site: www.profilecreations.co.za

Adding Custom (Phone Number) Field To 'Ask A Question' form

Please help guys.

My client needs the 'Ask A Question' form to capture the customer's phone number.

Having dug around in Google all day I have followed several forum posts and their instructions but have only got half way to getting this to work.

None of the forum posts refer to VM 3.., but it seems this is common request with the 'Ask A Question' form.

So far, so good...
My form on the front-end shows the field to add the phone number.
The phone number is accepted and form sent successfully.
I receive the email but the phone number is not shown.

This is what I have changed in VM3:

1. Copied 'form.php', 'mail_html_question.php', and 'mail_raw_question.php' files from the folder (components/com_virtuemart/views/askquestion)
to my template (/public_html/templates/t3_blank/html/com_virtuemart/askquestion).

2. In the copied 'form.php' file I have added the following, after the "email" section:

<tr>
<td><label for="phone"><?php echo vmText::_('COM_VIRTUEMART_SHOPPER_FORM_PHONE')  ?> : </label></td>
<td><input type="text" class="validate[required,minSize[8],maxSize[15]]" value="<?php echo $this->phone ? $this->phone : $askQuestionData['phone'] ?>" name="phone" id="name" size="30"  validation="required phone"/></td>
</tr>

3. In the 'mail_html_question.php' file I have edited the following code to include '$this->phone'.
See the underlined, bold section below:

<td align="center" style="border-bottom : 1px solid #dad8d8;">
<span style="font-size: 14px; font-weight: bold"><?php echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->name, $this->user->email, $this->phone); ?></span>
<br /><br /><?php echo $this->comment; ?><br /><br />
</td>

4. In the 'mail_raw_question.php' file I have edited the following code to include '$this->phone'.
See the underlined, bold section below:

echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->name, $this->user->email, $this->phone) . "\n";

echo $this->comment. "\n";

----------------------------------------------------------------------------------------------------------------

The website in question is www.profilecreations.co.za, and is a live, well used and much visited site.

My feeling is this is a simple omission or error on my part.

I'm not a coder, I'm a designer, so I'm totally stumped and can't afford another day like today.

Please can someone help.

You help is much appreciated.

Thank you in advance.

J

GJC Web Design

I don't see anywhere where u capture the Post

in the view html.php   function renderMailLayout () you need something like

$this->phone = vRequest::getString ('phone');

if the value actually gets past to the email template then the lang constant will need another var

e.g.

COM_VIRTUEMART_QUESTION_MAIL_FROM = "A question was asked by %s (%s) - Phone: %s"

but echo out $this->phone to make sure this is correct

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

SAWebCo

Thank you GJC  ;) ;) ;) but to be honest I didn't fully understand what you meant.

However, I really appreciate your help and the form is now fully working with the phone number appearing in the email received.

If anyone else needs this on their 'Ask A Question' this is working for me on Joomla 3.6.2, VM 3.0.9

It is now working with the following changes:

1. Changed  /public_html/components/com_virtuemart/views/askquestion/view.html.php

(See bold section)

function renderMailLayout () {

      $this->setLayout ('mail_html_question');
      $this->comment = vRequest::getString ('comment');
      $this->phone = vRequest::getString ('phone');

      $this->user = JFactory::getUser ();
      if (empty($this->user->id)) {
         $fromMail = vRequest::getEmail ('email'); //is sanitized then
         $fromName = vRequest::getVar ('name', ''); //is sanitized then
         //$fromMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromMail);
         $fromName = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromName);
         $this->user->email = $fromMail;
         $this->user->name = $fromName;
      }

2. changed /public_html/templates/t3_blank/html/com_virtuemart/askquestion/form.php

(See bold section)

<table class="askform">
   <tr>
      <td><label for="name"><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_NAME')  ?> : </label></td>
      <td><input type="text" class="validate[required,minSize[3],maxSize[64]]" value="<?php echo $this->user->name ? $this->user->name : $askQuestionData['name'] ?>" name="name" id="name" size="30"  validation="required name"/></td>
   </tr>                                             
   <tr>
      <td><label for="email"><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_EMAIL')  ?> : </label></td>
      <td><input type="text" class="validate[required,custom[email]]" value="<?php echo $this->user->email ? $this->user->email : $askQuestionData['email'] ?>" name="email" id="email" size="30"  validation="required email"/></td>
   </tr>
        <tr>
      <td><label for="phone"><?php echo vmText::_('COM_VIRTUEMART_SHOPPER_FORM_PHONE')  ?> : </label></td>
      <td><input type="text" class="validate[required,minSize[8],maxSize[15]]" value="<?php echo $this->phone ? $this->phone : $askQuestionData['phone'] ?>" name="phone" id="name" size="30"  validation="required phone"/></td>
   </tr>

   <tr>
      <td colspan="2"><label for="comment"><?php echo vmText::sprintf('COM_VIRTUEMART_ASK_COMMENT', $min, $max); ?></label></td>
   </tr>
   <tr>
      <td colspan="2"><textarea title="<?php echo vmText::sprintf('COM_VIRTUEMART_ASK_COMMENT', $min, $max) ?>" class="validate[required,minSize[<?php echo $min ?>],maxSize[<?php echo $max ?>]] field" id="comment" name="comment" rows="8"><?php echo $askQuestionData['comment'] ?></textarea></td>
   </tr>
</table>


3. changed /public_html/templates/t3_blank/html/com_virtuemart/askquestion/mail_html_question.php

(See bold section)

<tr>
   <td align="center" style="border-bottom : 1px solid #dad8d8;">                           <span style="font-size: 14px; font-weight: bold"><?php echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->name, $this->user->email); ?></span>
      <br /><br /><?php echo $this->phone; ?><br /><br />
      <br /><br /><?php echo $this->comment; ?><br /><br />
   </td>
</tr>

4. changed /public_html/templates/t3_blank/html/com_virtuemart/askquestion/mail_raw_question.php

<?php
defined('_JEXEC') or die('');

echo vmText::sprintf('COM_VIRTUEMART_WELCOME_VENDOR', $this->vendor->vendor_store_name) . "\n" . "\n";
echo vmText::_('COM_VIRTUEMART_QUESTION_ABOUT') . ' '. $this->product->product_name;
if ($this->product->product_sku) echo vmText::_('COM_VIRTUEMART_PRODUCT_SKU').' '.$this->product->product_sku .')' ;
echo "\n" . "\n";
echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->name, $this->user->email) . "\n";
echo $this->phone. "\n";
echo $this->comment. "\n";

--------------------------------------------------------

It's working for me.

Thanks again GJC for you valued input.  :)

Studio 42

Hi,
$this->phone = vRequest::getString ('phone'); is not a good idea in renderMailLayout
simply use vRequest::getString ('phone'); in in your tmpl/ files
If you want add it in the session, add it in your overide tmpl/ files to.
When you update VM, you loose all your changes with your current core hacks, moving all this in the template never get removed(or if T3 include the files by default

pcbest

Thank you for the information. I made the changes to the 4 files in virtuemart core files (after making backup of original) and it worked fine. I was unable to get it to work using template overrides, which is how I prefer to do any modification. My template is named Sirus, and there is a HTML/com_virtuemart folder in it. I have successfully modified products amd category listings by copying categories.php and products.php into a sublayouts sub-folder. I created a views sub-folder and copied the entire askquestion folder into it and made the modifications to those files, but my changes were not detected by virtuemart. Did I do something wrong? I know I made the mods correctly because it works when I do it to the core files. I am running Virtuemart 3.08 and I plan on updating to 3.09 and beyond. Here is my folder structure:
sirus(template folder)
    html
   com_virtuemart
      index.html
      sublayouts
         categories.php
         index.html
         products.php
      views
         askquestion
            view.html.php
            tmpl
               form.php
               mail_html_question.php
               mail_raw_question.php

Studio 42

SImply copy code from
1. Changed  /public_html/components/com_virtuemart/views/askquestion/view.html.php
at the begin of
3. changed /public_html/templates/t3_blank/html/com_virtuemart/askquestion/mail_html_question.php
and
4. changed /public_html/templates/t3_blank/html/com_virtuemart/askquestion/mail_raw_question.php

jflash

I want to update this post (because it works in VM 3.4.x) If someone changes file /public_html/components/com_virtuemart/views/askquestion/view.html.php then after Virtuemart update this change gone. According to SAWebCo post maybe its better to replace in his code:

3. changed /public_html/templates/t3_blank/html/com_virtuemart/askquestion/mail_html_question.php
this: <br /><br /><?php echo $this->phone; ?><br /><br />
to this: <br /><br /><?php echo (empty($_POST['phone']) ? '':$_POST['phone']); ?><br /><br />

4. changed /public_html/templates/t3_blank/html/com_virtuemart/askquestion/mail_raw_question.php
this: echo $this->phone. "\n";
to this: echo (empty($_POST['phone']) ? '':$_POST['phone']) . "\n";

Now we dont need to change core file view.html.php. For me it works (Y)

GJC Web Design

you should be using vRequest::getString ('phone'); instead of  $_POST['phone'] for escaping/security reasons etc
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Ed Kiefer

I followed everything on this page and I'm getting an error in the "Phone" field. <br /><b>Notice</b>:  Undefined property: VirtueMartViewAskquestion::$phone in <b>/home/luxefi5/public_html/components/com_virtuemart/views/askquestion/tmpl/form.php</b> on line <b>77</b><br /><br /><b>Notice</b>:  Undefined variable: askQuestionData in <b>/home/luxefi5/public_html/components/com_virtuemart/views/askquestion/tmpl/form.php</b> on line <b>77</b><br />

I'm using VirtueMart 3.6.0 10113

Jörgen

Probably a PHP syntax error, You have not understood the changes needed and no one can guess what You have done wrong.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Ed Kiefer

Thanks for the quick response!
Does everything look correct? I have done this with success a couple of time before. But I just upgraded Virtuemart and forgot to backup my altered files.

form.php
<tr>
      <td><label for="phone"><?php echo vmText::_('COM_VIRTUEMART_SHOPPER_FORM_PHONE')  ?> : </label></td>
      <td><input type="text" class="validate[required,minSize[8],maxSize[15]]" value="<?php echo $this->phone $this->phone $askQuestionData['phone'?>" name="phone" id="name" size="30"  validation="required phone"/></td>
   </tr> 


mail_html_question.php
<br /><br /><?php echo $this->phone?><br /><br />

mail_raw_question.php
echo $this->phone. "\n";

view_html_question.php
$this->phone = vRequest::getString ('phone');

Here is the page: https://luxefifthwheel.com/fifth-wheels-for-sale/all-fifth-wheels-for-sale/2019-luxe-elite-lg-39fb-detail

Studio 42

Why hack the core for nothing in view_html_question.php ?
Simply replace $this->phone by vRequest::getString ('phone')

Ed Kiefer

Here is a screen shot of what I'm getting. I just need to figure out why I'm getting an error in the phone field. Is there another way to do this without hacking the core? Maybe a plugin? or file override?

Ed Kiefer

Is there a plugin or override file to add a phone number in the "Ask Question" feature? So I don't have to hack the code?

Studio 42

mail_html_question.php can be override in the template.
Do not use $this->phone, but $phone = vRequest::getString ('phone'); and use $phone always directly in the mail_html_question.php file override