Rodrigo Gomes Posted August 17, 2017 Share Posted August 17, 2017 Hello guys, I would like to turn the Address 2 into a required field. There is no way to do this by the administrative panel, is there any other solution? Some PHP code that I can insert or modify. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 17, 2017 Share Posted August 17, 2017 exactly what/how would depend on your orderform template, but if we assume it's standard_cart, then one quick way to do it would be to change in checkout.tpl.. <input type="text" name="address2" id="inputAddress2" class="field" placeholder="{$LANG.orderForm.streetAddress2}" value="{$clientsdetails.address2}"{if $loggedin} readonly="readonly"{/if}> to... <input type="text" name="address2" id="inputAddress2" class="field" placeholder="{$LANG.orderForm.streetAddress2}" value="{$clientsdetails.address2}"{if $loggedin} readonly="readonly"{else}required{/if}> it would probably fail in IE9, but then again, I imagine a lot of WHMCS features would fail in IE9 ! 0 Quote Link to comment Share on other sites More sharing options...
Rodrigo Gomes Posted August 17, 2017 Author Share Posted August 17, 2017 Hello brian, It worked. Thanks for your reply! 0 Quote Link to comment Share on other sites More sharing options...
Rodrigo Gomes Posted August 17, 2017 Author Share Posted August 17, 2017 Hello brian, Inspired by your answer, I created the JS code below. An easy way to make that field required without having to edit the theme. $(document).ready(function(){ if(document.getElementById("address2") !== null){ document.getElementById("address2").required = true; } }) 0 Quote Link to comment Share on other sites More sharing options...
Rodrigo Gomes Posted August 17, 2017 Author Share Posted August 17, 2017 Hello, I also made a hook in php to force "address2" to be a required field. This way it is safer and works for any area where this address is inserted or modified. function hook_validation_account($vars) { if (!$vars['address2']) { $error[] = "You did not enter 'Address 2'"; } if($error){ return $error; } } add_hook("ClientDetailsValidation",1,"hook_validation_account"); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 18, 2017 Share Posted August 18, 2017 well done for posting the alternate solutions! 0 Quote Link to comment Share on other sites More sharing options...
Rodrigo Gomes Posted August 18, 2017 Author Share Posted August 18, 2017 Thank you Brian! But unfortunately I have a problem. My php script works perfectly in the client area, but in the administrative panel, the error appears but the modification is done anyway. I think this is a bug from WHMCS itself. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 18, 2017 Share Posted August 18, 2017 using the hook? perhaps check if the admin is logged in, and only if they're not, run the hook. 0 Quote Link to comment Share on other sites More sharing options...
Rodrigo Gomes Posted August 18, 2017 Author Share Posted August 18, 2017 using the hook? perhaps check if the admin is logged in, and only if they're not, run the hook. Hello brian, What if I want run the hook even with an admin? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 19, 2017 Share Posted August 19, 2017 i'm not sure why you would need to force an admin to enter address2... what error are you seeing in the admin area, and what are you doing to create it ?? 0 Quote Link to comment Share on other sites More sharing options...
Rodrigo Gomes Posted August 19, 2017 Author Share Posted August 19, 2017 Hi brian, For tax reasons here in my country, I need certain fields to be required. I'm using this hook for other things too, like checking the personal identification number here from Brazil (CPF). And these required fields need to be filled out. And this is required even for admin. I'm seeing the error of my own hook, the one I set in "$error[]". But although the error appears, the modification is performed anyway. And I do not want even the administrator to be able to set an invalid CPF. Or leave "Address 2" blank. Thank you! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.