[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Making address2 field required in PrestaShop

Posted on 2013-11-21
17
Medium Priority
?
1,528 Views
Last Modified: 2013-11-25
We're using PrestaShop 1.5.4.1. We need to make address2 field "required" like address1, so that users cannot submit the address form if they don't fill the address2 field. I don't mean putting asterisk* to its label inside its .tpl file, I mean making it really required.
0
Comment
Question by:sbayrak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
17 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39667701
SSCCE -- What have you tried so far?  Please show us the code you're using, thanks.
0
 
LVL 1

Author Comment

by:sbayrak
ID: 39667936
I only edited the relevant address2 label inside /themes/mytheme/address.tpl and added
an asteriks * by using <sup>*</sup> so far, nothing else...

                {if $field_name eq 'address2'}
                <p class="required text">
                        <label for="address2">{l s='Address (Line 2)'} <sup>*</sup></label>
                        <input type="text" id="address2" name="address2" value="{if isset($smarty.post.address2)}{$smarty.post.addre
ss2}{else}{if isset($address->address2)}{$address->address2}{/if}{/if}" />
                </p>
                {/if}

thanks in advance.
0
 
LVL 26

Expert Comment

by:lenamtl
ID: 39669686
What is the code of address one?

You have to add validation field
* will only display it, this will not validate the field.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:sbayrak
ID: 39670950
Well I can't see a validation in address1 field also, at least in address.tpl file.
They're both almost identical. Somewhere else, there should be a separate function to control the validation doings I think...


                {if $field_name eq 'address1'}
                <p class="required text">
                        <label for="address1">{l s='Address'} <sup>*</sup></label>
                        <input type="text" id="address1" name="address1" value="{if isset($smarty.post.address1)}{$smarty.post.addre
ss1}{else}{if isset($address->address1)}{$address->address1}{/if}{/if}" />
                </p>
                {/if}
                {if $field_name eq 'address2'}
                <p class="required text">
                        <label for="address2">{l s='Address (Line 2)'} <sup>*</sup></label>
                        <input type="text" id="address2" name="address2" value="{if isset($smarty.post.address2)}{$smarty.post.addre
ss2}{else}{if isset($address->address2)}{$address->address2}{/if}{/if}" />
                </p>
                {/if}

Open in new window

0
 
LVL 26

Expert Comment

by:lenamtl
ID: 39671348
The address validation is located in classes/Validate.php
You can duplicate the class and add a new variable name $address2
I have not tested I'm not sure if it's will work ok.
Backup your files prior trying this modification.

add this class to
classes/Validate.php

   /**
    * Check for a postal address2 validity
    *
    * @param string $address2 Address2 to validate
    * @return boolean Validity is ok or not
    */

    static public function isAddress($address2)
    {
        return empty($address2) OR preg_match('/^[^!<>?=+@{}_$%]*$/ui', $address2);
    }

 

Open in new window


and change your new code in address.tpl for this
 {if $field_name eq 'address2'}
                <p class="required text">
                        <label for="address2">{l s='Address (Line 2)'} <sup>*</sup></label>
                        <input type="text" id="address2" name="address2" value="{if isset($smarty.post.address2)}{$smarty.post.addre
ss2}{else}{if isset($address2->address2)}{$address2->address2}{/if}{/if}" />
                </p>
                {/if}

Open in new window

0
 
LVL 1

Author Comment

by:sbayrak
ID: 39672034
Adding your code to classes/Validate.php causes WSOD (white screen of death). I tried some different variations of it, but the result didn't change, all WSOD. I think your logic is right but somehow it does not work within classes/Validate.php. I changed static < > public order, OR with || and etc., it didn't work...
0
 
LVL 26

Expert Comment

by:lenamtl
ID: 39672644
Have you also edited your address2 code line address.tpl ?
I will install it and make test tonight
0
 
LVL 26

Expert Comment

by:lenamtl
ID: 39672649
I think this is because the variable is not declared at the begining of code page.
Check for other occurrence of $address in the code.

Could you enable error display
http://www.php.net/manual/en/function.error-reporting.php
error_reporting(E_ALL);

I will try to install it and make test tonight
0
 
LVL 1

Author Comment

by:sbayrak
ID: 39673761
I refered the changes I did in address.tpl previously above;
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28300789.html#a39670950

Yes, as you said, it cannot be redeclared;
PHP Fatal error:  Cannot redeclare ValidateCore::isAddress() in classes/Validate.php on line 359

Actually there're no other occurrences of $address in Validate.php file.
Thank you.
0
 
LVL 26

Expert Comment

by:lenamtl
ID: 39674463
Ok we have to rename isAddress to isAddress2

static public function isAddress($address2)

in classes/Validate.php



So it should now be like this:
   
/**
    * Check for a postal address2 validity
    *
    * @param string $address2 Address2 to validate
    * @return boolean Validity is ok or not
    */

    static public function isAddress2($address2)
    {
        return empty($address2) OR preg_match('/^[^!<>?=+@{}_$%]*$/ui', $address2);
    }

Open in new window


Let me know if there are other occurrence of isAddress
0
 
LVL 1

Author Comment

by:sbayrak
ID: 39674587
Ok., now it doesn't end with WSOD. Site is working but address2 field can still be submitted empty. I mean it didn't become a required field.

Here is the latest version of funct. I derived from its working brother ($address);  

       /**
         * Check for a postal address validity
         * 
         * @param string $address2 Address to validate
         * @return boolean Validity is ok or not
         */
        public static function isAddress2($address2)
        {
                return empty($address2) || preg_match('/^[^!<>?=+@{}_$%]*$/u', $address2);
        }

Open in new window


And, there's no any other occurrence of isAddress.
Thanks
0
 
LVL 26

Expert Comment

by:lenamtl
ID: 39674638
Just for a test could you comment the derived function and replace it with the one I provided
0
 
LVL 1

Author Comment

by:sbayrak
ID: 39674721
Sure, I copied and pasted your code as is and nothing changed. No WSOD but field is still optional.
0
 
LVL 26

Expert Comment

by:lenamtl
ID: 39674775
ok thanks I will try to find out and get back to you asap
0
 
LVL 26

Accepted Solution

by:
lenamtl earned 2000 total points
ID: 39674808
Check
classess/address.php

find this line
  
 'address2' => array('type' => self::TYPE_STRING, '' => 'isAddress', 'size' => 128),

Open in new window


change it for

 
'address2' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress2', 'required' => true, 'size' => 128),
 

Open in new window

0
 
LVL 1

Author Comment

by:sbayrak
ID: 39674847
No, actually I didn't add anything to anywhere else different than I mentioned here up until now.
0
 
LVL 1

Author Closing Comment

by:sbayrak
ID: 39674901
It works now. Thank you so much for your efforts to resolve it.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for …
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question