News:

Looking for documentation? Take a look on our wiki

Main Menu

How to make the User comment text box as a Required field???

Started by david.kwock, July 04, 2012, 08:08:57 AM

Previous topic - Next topic

david.kwock

Hello, :D

I am trying to add a Empty validation rule for the 'Leave comment' text-box on the check out page.
Which file should I look at to make it as a compulsory filed????

Thank you!!  :)

David

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

david.kwock

Thank you, Milbo  :D

I have looked at the file and tried to insert form validation using this method displayed on: http://docs.joomla.org/Client-side_form_validation

<form method="post" id="checkoutForm" name="checkoutForm" action="<?php echo JRoute::_'index.php?option=com_virtuemart&view=cart'.$taskRoute,$this->useXHTML,$this->useSSL ); ?>" class="form-validate" onSubmit="return myValidate(this);>
.
.
.
<textarea class="required" name="customer_comment" cols="50" rows="4" ><?php echo $this->cart->customer_comment?></textarea>


But nothing happen when I clicked on 'Check out' or 'Confirm Order' button.
Sorry, I am still beginner :'(. It would be really grateful if you give me some more advice for this. Thank you very much!

David

Milbo

Maybe it is easier to create a shopperfield for that and ask for that in the address part.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

david.kwock

Milbo,

I solved it by calling another java script from the 'Check out' button in view.html.php in the Cart folder
and I call the 'Check out' java script in the other javascript in default.php:)

Cheers

David

disco_dancer

Hello David,
Can you please share how did you achieve this comment field validation?

Thanks

mpdeepan

Hello David

Can you please write how did you made this comment field validation?
Can you give code please?

Thanks
-Pradeepan-

david.kwock

Hey, this is what I have done. This is a required field validation for my order timing validation (calendar).
You may use this method for your needs.  ;D

First file:\components\com_virtuemart\views\cart\view.html.php
This modification is to insert the Java form validation on the cart page instead of submitting the form straight away.
if (!VmConfig::get('use_as_catalog')) {
//$checkout_link_html = '<a class="vm-button-correct" href="javascript:document.checkoutForm.submit();" ><span>' . $text . '</span></a>'; -- original code
$checkout_link_html = '<a class="vm-button-correct" href="javascript:myValidate(this);" ><span>' . $text . '</span></a>';//replaced code
} else {
$checkout_link_html = '';
}
$this->assignRef('checkout_link_html', $checkout_link_html);
}



2nd file:\html\com_virtuemart\cart\default.php - this is a template override file

Insert this java script and replace the 'ordertiming' as you want. It would be 'comment' for you.
<script language="javascript">
function myValidate(f) {
    var ot = document.getElementById('ordertiming');

//document.checkoutForm.submit();
   if (ot.value=="") {
      alert('Please Select the Order Timing');
     
   }
   else {
      document.checkoutForm.submit();
   }
   
}


Hope this helps you guys. cheers

mpdeepan


enserk

Quote from: david.kwock on October 04, 2012, 05:50:39 AM
Hey, this is what I have done. This is a required field validation for my order timing validation (calendar).
You may use this method for your needs.  ;D

First file:\components\com_virtuemart\views\cart\view.html.php
This modification is to insert the Java form validation on the cart page instead of submitting the form straight away.
if (!VmConfig::get('use_as_catalog')) {
//$checkout_link_html = '<a class="vm-button-correct" href="javascript:document.checkoutForm.submit();" ><span>' . $text . '</span></a>'; -- original code
$checkout_link_html = '<a class="vm-button-correct" href="javascript:myValidate(this);" ><span>' . $text . '</span></a>';//replaced code
} else {
$checkout_link_html = '';
}
$this->assignRef('checkout_link_html', $checkout_link_html);
}



2nd file:\html\com_virtuemart\cart\default.php - this is a template override file

Insert this java script and replace the 'ordertiming' as you want. It would be 'comment' for you.
<script language="javascript">
function myValidate(f) {
    var ot = document.getElementById('ordertiming');

//document.checkoutForm.submit();
   if (ot.value=="") {
      alert('Please Select the Order Timing');
     
   }
   else {
      document.checkoutForm.submit();
   }
   
}


Hope this helps you guys. cheers
Hi David,

it doesnt work ... what can make worn?