We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

placeholder mobile phone function

Dear Friends,

Sorry for my questions, I am newbie and I would like to change a code in the gsm area for registration. The original code is limiting gsm number entry max 11. I would like to remove this limitation and put only name of indication to allow people to put as (+country code) (operator code) (phone number)

Here is the part of gsm area..waiting for your help..

Regards,

<div class="input-group"><span class="input-group-addon"><span class="input-icon i-mobile"></span><span class="input-text"><?= $langsub->('Mobile'); ?>*</span></span> <input type="text" name="gsm" required class="form-control input-lg phone" placeholder="<?= $langsub->('Mobile'); ?>">

edited Feb '16

In the code you posted there is no limitation (it is plain HTML). It is either in your PHP (form/controller) or javascript. Can you provide that code and we will try to help?



878

Hi Thanks..

could you provide me an email, so that I can send the codes..

edited Feb '16

No need to send on email, post your code here. Just the part of your code from form/controller. Click on HELP button above comment form to see how you can format your code. The idea is to help other forum users with the same problem.



878

index.volt file...

<?php / Proje : Tarih : 26.02.2015 Dosya : index.volt Yazar : Not : /

use Phalcon\Tag;

$security = new \Modules\Frontend\Controllers\Security();

?> <section id="content"> <div id="breadcrumb-container"> <div class="container"> <ul class="breadcrumb"> <li><?= Tag::linkTo('', $lang->('Home')); ?></li> <li class="active"><?= $lang->('Register'); ?></li> </ul> </div> </div> <div class="container"> <div class="row"> <div class="col-md-12"> <header class="content-title"> <h1 class="title"><?= $lang->_('Register'); ?></h1>

                <p class="title-desc"><?= $lang_sub->_('Register_Text', ['giris' => $url . '/Giris']); ?></p>
            </header>
            <div class="xs-margin"></div>
            <div id="result"></div>
            <?php echo Tag::form(["Uye-Ol/Register", 'method' => 'post', 'id' => 'register-form', 'class' => 'ajaxform validateform']); ?>
            <?
                echo $security->createCSRF();
            ?>
            <div class="row">
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <fieldset>
                        <h2 class="sub-title"><?= $lang_sub->_('Personal_Details'); ?></h2>

                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-user"></span><span
                                    class="input-text"><?= $lang_sub->_('Username'); ?>&#42;</span></span>
                            <input type="text" name="username" required minlength="3" class="form-control input-lg"
                                   placeholder="<?= $lang_sub->_('Username'); ?>" data-rule-alphanumeric="true">
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-profile"></span><span
                                    class="input-text"><?= $lang_sub->_('Name'); ?>&#42;</span></span>
                            <input type="text" name="ad" required minlength="2" class="form-control input-lg"
                                   placeholder="<?= $lang_sub->_('Name'); ?>">
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-profile"></span><span
                                    class="input-text"><?= $lang_sub->_('Last_Name'); ?>&#42;</span></span>
                            <input type="text" name="soyad" required minlength="2" class="form-control input-lg"
                                   placeholder="<?= $lang_sub->_('Last_Name'); ?>">
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-envelop"></span><span
                                    class="input-text"><?= $lang_sub->_('Email'); ?>&#42;</span></span>
                            <input type="email" name="email" required class="form-control input-lg"
                                   placeholder="<?= $lang_sub->_('Email'); ?>">
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-mobile"></span><span
                                    class="input-text"><?= $lang_sub->_('Mobile'); ?>&#42;</span></span>
                            <input type="text" name="gsm" required class="form-control input-lg phone"
                                   placeholder="<?= $lang_sub->_('Mobile'); ?>">
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-calendar"></span><span
                                    class="input-text"><?= $lang_sub->_('Date_Of_Birth'); ?></span></span>

                            <div class="large-selectbox clearfix">
                                <div class="row">
                                    <div class="col-md-4 col-xs-12 select_valid"><select id="gun" name="gun"
                                                                                         class="selectbox" required>
                                            <option value=""><?= $lang->_('Please_Select'); ?></option>
                                            <? foreach ($awy->getDays() as $data) { ?>
                                                <option value="<?= $data->data; ?>"><?= $data->data; ?></option>
                                            <? } ?>
                                        </select></div>
                                    <div class="col-md-4 col-xs-12 select_valid"><select id="ay" name="ay"
                                                                                         class="selectbox" required>
                                            <option value=""><?= $lang->_('Please_Select'); ?></option>
                                            <? foreach ($awy->getMonths() as $data) { ?>
                                                <option value="<?= $data->key; ?>"><?= $data->data; ?></option>
                                            <? } ?>
                                        </select></div>
                                    <div class="col-md-4 col-xs-12 select_valid"><select id="yil" name="yil"
                                                                                         class="selectbox" required>
                                            <option value=""><?= $lang->_('Please_Select'); ?></option>
                                            <? foreach ($awy->getYears(80) as $data) { ?>
                                                <option value="<?= $data->data; ?>"><?= $data->data; ?></option>
                                            <? } ?>
                                        </select></div>
                                </div>
                            </div>
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-male"></span><span
                                    class="input-text"><?= $lang_sub->_('Gender'); ?>&#42;</span></span>
                            <input type="checkbox" data-on-color="info" data-size="large"
                                   data-label-text="<?= $lang->_('Change'); ?>" data-off-color="info"
                                   data-on-text="<?= $lang_sub->_('Male'); ?>"
                                   data-off-text="<?= $lang_sub->_('Female'); ?>" name="cinsiyet" class="switch"
                                   checked>
                        </div>
                    </fieldset>
                    <fieldset class="half-margin">
                        <label>
                            <div class="input-group custom-checkbox">
                                <input type="checkbox" name="kurallar"> <span class="checbox-container"><i
                                        class="fa fa-check"></i></span> <?= $lang_sub->_('Accept_Rules'); ?></div>
                        </label>
                    </fieldset>
                </div>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <fieldset>
                        <h2 class="sub-title"><?= $lang_sub->_('Password'); ?></h2>

                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-key-2"></span><span
                                    class="input-text"><?= $lang_sub->_('Password_1'); ?>&#42;</span></span>
                            <input type="password" name="sifre" id="sifre" required minlength='6'
                                   class="form-control input-lg" placeholder="<?= $lang_sub->_('Password_1'); ?>"
                                   autocomplete="off">
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-key-2"></span><span
                                    class="input-text"><?= $lang_sub->_('Password_2'); ?>&#42;</span></span>
                            <input type="password" name="sifre2" equalto="#sifre" required minlength='6'
                                   class="form-control input-lg" placeholder="<?= $lang_sub->_('Password_2'); ?>"
                                   autocomplete="off">
                        </div>
                    </fieldset>
                    <fieldset>
                        <h2 class="sub-title"><?= $lang_sub->_('Address_Details'); ?></h2>

                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-direction"></span><span
                                    class="input-text"><?= $lang_sub->_('Address'); ?>&#42;</span></span>
                            <input type="text" name="adres" required minlength="20" class="form-control input-lg"
                                   placeholder="<?= $lang_sub->_('Address'); ?>">
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-location-4"></span><span
                                    class="input-text"><?= $lang_sub->_('Country'); ?>&#42;</span></span>

                            <div class="large-selectbox clearfix">
                                <select id="ulke" name="ulke" class="selectbox" required>
                                    <option value=""><?= $lang->_('Please_Select'); ?></option>
                                    <? foreach ($awy->GetRegion('ulke') as $data) { ?>
                                        <option
                                            value="<?= $data->kod; ?>"<? if ($data->kod == $conf->country) { ?> selected<? } ?>><?= $data->ulke; ?></option>
                                    <? } ?>
                                </select>
                            </div>
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-location-4"></span><span
                                    class="input-text"><?= $lang_sub->_('City'); ?>&#42;</span></span>

                            <div class="large-selectbox clearfix">
                                <select id="il" name="il" class="selectbox" required>
                                    <option value=""><?= $lang->_('Please_Select'); ?></option>
                                    <? foreach ($awy->GetRegion('il', $conf->country) as $data) { ?>
                                        <option value="<?= $data->id; ?>"><?= $data->ad; ?></option>
                                    <? } ?>
                                </select>
                            </div>
                        </div>
                        <div class="input-group"><span class="input-group-addon"><span
                                    class="input-icon i-location-4"></span><span
                                    class="input-text"><?= $lang_sub->_('County'); ?>&#42;</span></span>

                            <div class="large-selectbox clearfix">
                                <select id="ilce" name="ilce" class="selectbox" required>
                                    <option value=""><?= $lang->_('Please_Select'); ?></option>
                                </select>
                            </div>
                        </div>
                        <div class="input-group captcha-group"><span class="input-group-addon"><span
                                    class="input-icon i-shield-4"></span><span
                                    class="input-text"><?= $lang->_('Security_Code'); ?>&#42;</span></span>
                            <input type="text" name="kod" required class="form-control input-lg security_code"
                                   placeholder="<?= $lang->_('Security_Code'); ?>">
                            <a href="javascript:refreshCaptcha('<?= $security->getCaptchaLink(true); ?>');"><i
                                    class="i-loop-3 refresh-captcha"></i></a>
                            <img id="Captcha" src="<?= $security->getCaptchaLink(); ?>"
                                 alt="<?= $lang->_('Security_Code'); ?>" title="<?= $lang->_('Security_Code'); ?>">
                        </div>
                    </fieldset>
                    <input type="submit" value="<?= $lang_sub->_('Create_Account'); ?>"
                           class="btn btn-custom md-margin pull-right">
                </div>
            </div>
        </div>
        </form>
    </div>
</div>
</div>

</section> <div class="modal fade" id="Rules" tabindex="-1" role="dialog" aria-labelledby="RulesLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only"><?= $lang->_('Close'); ?></span></button> <h4 class="modal-title" id="RulesLabel"><?= $langsub->('Rules'); ?></h4> </div> <div class="modal-body"> <? $content = \Modules\Frontend\Models\Pages::findFirst(8); $replaces = ['%site%' => $conf->nowww, '%url%' => $url, '%adres%' => $conf->adres, '%email%' => $conf->sitemail, '%telefon%' => $conf->telefon, '%mobil%' => $conf->mobil, '%fax%' => $conf->fax, '%yil%' => date('yil'),]; echo strtr($content->{'icerik' . $awy->getActiveLang()}, $replaces); ?> </div> <div class="modal-footer text-center"> <a href="javascript:void(0)" class="btn btn-custom" data-dismiss="modal"><?= $lang->('Close'); ?></a> </div> </div> </div> </div>

Uyeolkontroller.php

<?php / Proje : Tarih : 26.02.2015 Dosya : UyeOlController.php Yazar : Not : /

namespace Modules\Frontend\Controllers;

use Phalcon\Tag;

class UyeOlController extends ControllerBase
{

    public function indexAction()
    {
        $this->loadCustomTrans('register');
        $checker = new UserActions();
        if ($checker->checkSession() == true) {
            return $this->response->redirect($this->view->url, true);
        }
        $this->view->setVar('form', true);
        $this->view->setVar('validate', true);
        $this->view->setVar('mask', true);
        $this->view->setVar('switch', true);
    }

    public function existsUserCheck($column, $filter)
    {
        return (count(\Modules\Frontend\Models\Users::query()->where($column . " = '" . $filter . "'")->execute()) == 0 ? false : true);
    }

    public function RegisterAction()
    {
        $this->loadCustomTrans('register');
        $checker = new UserActions();
        if ($checker->checkSession() == true) {
            return $this->response->redirect($this->view->url, true);
        }
        $Security = new Security();
        $Error = new Error();
        $ip = $Security->getIP();

        if ($Security->checkCSRF() and $Security->checkPost() and $ip) {
            if (!$Security->checkCaptcha()) {
                echo $Error->Show($this->view->getVar('lang')->_('Captcha_Error'), 'danger', null, true);
            } else {
                $awy = new AWYFunctions();
                $Errors = null;
                $username = AWYFunctions::Protect($awy->NoSpaceAndSpecial($this->request->getPost('username')));
                $ad = AWYFunctions::Protect(ucfirst($this->request->getPost('ad')));
                $soyad = AWYFunctions::Protect(ucfirst($this->request->getPost('soyad')));
                $email = AWYFunctions::Protect($this->request->getPost('email'));
                $gsm = AWYFunctions::Protect(AWYFunctions::clearPhone($this->request->getPost('gsm')));
                $gun = AWYFunctions::Protect($this->request->getPost('gun'), 'int');
                $ay = AWYFunctions::Protect($this->request->getPost('ay'), 'int');
                $yil = AWYFunctions::Protect($this->request->getPost('yil'), 'int');
                $cinsiyet = (AWYFunctions::Protect($this->request->getPost('cinsiyet')) == 'on' ? 1 : 0);
                $kurallar = AWYFunctions::Protect($this->request->getPost('kurallar'));
                $sifre = AWYFunctions::Protect($this->request->getPost('sifre'));
                $sifre2 = AWYFunctions::Protect($this->request->getPost('sifre2'));
                $adres = AWYFunctions::Protect($this->request->getPost('adres'));
                $ulke = AWYFunctions::Protect($this->request->getPost('ulke'));
                $il = AWYFunctions::Protect($this->request->getPost('il', 'int'));
                $ilce = AWYFunctions::Protect($this->request->getPost('ilce', 'int'));
                if (strlen($username) < 3) {
                    $Errors[] = $this->view->lang->_('Field_Error_2', ['alan' => $this->view->lang_sub->_('Username'), 'minimum' => 3]);
                }
                if (strlen($ad) < 2) {
                    $Errors[] = $this->view->lang->_('Field_Error_2', ['alan' => $this->view->lang_sub->_('Name'), 'minimum' => 2]);
                }
                if (strlen($soyad) < 2) {
                    $Errors[] = $this->view->lang->_('Field_Error_2', ['alan' => $this->view->lang_sub->_('Last_Name'), 'minimum' => 2]);
                }
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                    $Errors[] = $this->view->lang->_('Field_Error_3');
                }
                if (strlen($gsm) != 11 or !ctype_digit($gsm)) {
                    $Errors[] = $this->view->lang->_('Field_Error_4');
                }
                if (strlen($gun) == 0 || strlen($gun) > 2) {
                    $Errors[] = $this->view->lang->_('Field_Error_5');
                }
                if (strlen($ay) == 0 || strlen($ay) > 2) {
                    $Errors[] = $this->view->lang->_('Field_Error_5');
                }
                if (strlen($yil) != 4) {
                    $Errors[] = $this->view->lang->_('Field_Error_5');
                }
                if (strlen($sifre) < 6) {
                    $Errors[] = $this->view->lang->_('Field_Error_2', ['alan' => $this->view->lang_sub->_('Password_1'), 'minimum' => 6]);
                }
                if ($sifre2 != $sifre) {
                    $Errors[] = $this->view->lang->_('Field_Error_6');
                }
                if (strlen($adres) < 20) {
                    $Errors[] = $this->view->lang->_('Field_Error_2', ['alan' => $this->view->lang_sub->_('Address'), 'minimum' => 20]);
                }
                if (strlen($ulke) != 2) {
                    $Errors[] = $this->view->lang->_('Field_Error_1', ['alan' => $this->view->lang_sub->_('Country')]);
                }
                if ($il == '') {
                    $Errors[] = $this->view->lang->_('Field_Error_1', ['alan' => $this->view->lang_sub->_('City')]);
                }
                if ($ilce == '') {
                    $Errors[] = $this->view->lang->_('Field_Error_1', ['alan' => $this->view->lang_sub->_('County')]);
                }
                if ($kurallar != 'on') {
                    $Errors[] = $this->view->lang->_('Field_Error_7');
                }
                if (self::existsUserCheck('username', $username)) {
                    $Errors[] = $this->view->lang_sub->_('Register_Error_2');
                }
                if (self::existsUserCheck('email', $email)) {
                    $Errors[] = $this->view->lang_sub->_('Register_Error_3');
                }
                if (self::existsUserCheck('gsm', $gsm)) {
                    $Errors[] = $this->view->lang_sub->_('Register_Error_4');
                }
                if (count($Errors) == 0) {
                    $users = new \Modules\Frontend\Models\Users();
                    $users->username = $username;
                    $users->ad = $ad;
                    $users->soyad = $soyad;
                    $users->email = $email;
                    $users->parola = md5($sifre);
                    $users->kayit_tarihi = date('Y-m-d');
                    $users->onay = ($this->view->conf->aktivasyon_turu == 0 ? '1' : 0);
                    $users->dogum = $gun . '-' . $ay . '-' . $yil;
                    $users->cinsiyet = $cinsiyet;
                    $users->gsm = $gsm;
                    $users->ulke = $ulke;
                    $users->il = $il;
                    $users->ilce = $ilce;
                    $users->adres = $adres;
                    $users->ip = $ip;
                    $users->point = $awy->getPointByType('register');
                    if ($this->view->conf->aktivasyon_turu == 1) {
                        $Code = Security::generateCode();
                        $users->sms_code = $Code;
                    }
                    if ($users->create() == false) {
                        echo $Error->Show($this->view->lang_sub->_('Register_Error_1'), 'danger', null, true);
                    } else {
                        $this->loadMailTrans();
                        if ($this->view->conf->aktivasyon_turu == 0) {
                            if ($this->Email->send($email, $ad, $soyad, $this->view->lang_mail->_('Register_Subject_1'), $this->view->lang_mail->_('Register', ['ad' => $ad, 'soyad' => $soyad, 'url' => $this->view->url]))) {
                                $this->session->set('LoggedIn', 1);
                                $this->session->set('LoggedUser', $users->id);
                                echo $Error->Show($this->view->lang_sub->_('Register_Success'), 'success', $this->view->url, true);
                            } else {
                                echo $Error->Show($this->view->lang->_('Mail_Not_Sent'), 'danger', null, true);
                            }
                        } elseif ($this->view->conf->aktivasyon_turu == 1) {
                            $Sms = new Sms();
                            $Sms->Send($users->gsm, $this->view->lang_sub->_('Activation_SMS', ['kod' => $Code]));
                            $return = $Error->Show($this->view->lang_sub->_('SMS_Sent'), 'success', null, true);
                            $return .= '<script>$(".activationvalidate").validate();$(".ajaxactivation").ajaxForm({target:"#result2"});</script><div id="result2"></div>';
                            $return .= Tag::form(["Uye-Ol/AktivasyonSMS", 'method' => 'post', 'id' => 'activation-form', 'class' => 'ajaxactivation activationvalidate']);
                            $return .= '<div class="input-group"><span class="input-group-addon"><span class="input-icon i-key-5"></span><span class="input-text">' . $this->view->lang_sub->_('Activation_Code') . '&#42;</span></span>
                            <input type="text" name="Sms_Kodu" autocomplete="off" required class="form-control input-lg" placeholder=' . $this->view->lang_sub->_('Activation_Code') . '">
                        </div>
                        <button class="btn btn-custom-2 center-block">' . $this->view->lang_sub->_('Activate_Account') . '</button></form><div class="md-margin"></div>';
                            echo $return;
                        } else {
                            if ($this->Email->send($email, $ad, $soyad, $this->view->lang_mail->_('Register_Subject'), $this->view->lang_mail->_('Register_2', ['ad' => $ad, 'soyad' => $soyad, 'url' => $this->view->url . '/Uye-Ol/Aktivasyon?Key=' . $Security->awyEnc($email)]))) {
                                echo $Error->Show($this->view->lang_sub->_('Register_Success_2'), 'success', $this->view->url, true,true);
                            } else {
                                echo $Error->Show($this->view->lang->_('Mail_Not_Sent'), 'danger', null, true);
                            }
                        }
                    }
                } else {
                    echo $Error->Show($Errors, 'danger', null, true);
                }
            }
        } else {
            return $this->response->redirect('');
        }
        $this->view->disable();
    }

    public function AktivasyonAction()
    {
        $Security = new Security();
        $Key = str_replace(' ', '+', AWYFunctions::Protect($this->request->getQuery('Key')));
        if ($Key != '') {
            $Key = trim($Security->awyEnc($Key, 1));
            $count = \Modules\Frontend\Models\Users::query()->where("onay = 0")->andWhere("email='" . $Key . "'")->execute();
            $Error = new Error();
            $return = '<section id="content"><div class="container">
    <div class="row">
        <div class="col-md-12"><div class="md-margin"></div>';
            if (count($count) == 0) {
                $return .= $Error->show($this->view->lang->_('Activation_Error'), 'danger', $this->view->url);
            } else {
                $this->loadMailTrans();
                $Users = \Modules\Frontend\Models\Users::findFirst("email = '" . $Key . "'");
                if ($this->Email->send($Users->email, $Users->ad, $Users->soyad, $this->view->lang_mail->_('Register_Subject_1'), $this->view->lang_mail->_('Register', ['ad' => $Users->ad, 'soyad' => $Users->soyad, 'url' => $this->view->url]))) {

                    $Users->onay = 1;
                    $Users->save();
                    $this->session->set('LoggedIn', 1);
                    $this->session->set('LoggedUser', $Users->id);
                    $return .= $Error->show($this->view->lang->_('Activation_Success'), 'success', $this->view->url . '/Giris');
                } else {
                    $return .= $Error->Show($this->view->lang->_('Mail_Not_Sent'), 'danger', null, true);
                }
            }
            $return .= '</div></div></div></section>';
            echo $return;
        } else {
            return $this->response->redirect($this->view->url, true);
        }
    }

    public function AktivasyonSMSAction()
    {
        $this->loadCustomTrans('register');
        $Key = AWYFunctions::Protect($this->request->getPost('Sms_Kodu'), 'int');
        if ($Key != '') {
            $count = \Modules\Frontend\Models\Users::query()->where("onay = 0")->andWhere("sms_code='" . $Key . "'")->execute();
            $Error = new Error();
            if (count($count) == 0) {
                echo $Error->show($this->view->lang_sub->_('Activation_Error'), 'danger', false, true);
            } else {
                $Users = \Modules\Frontend\Models\Users::findFirst("sms_code = '" . $Key . "'");
                $Users->onay = 1;
                $Users->save();
                $this->session->set('LoggedIn', 1);
                $this->session->set('LoggedUser', $Users->id);
                echo $Error->show($this->view->lang->_('Activation_Success'), 'success', $this->view->url, true);
            }
        } else {
            return $this->response->redirect($this->view->url, true);
        }
        $this->view->disable();
    }
}


878

I hope I put the right things..

edited Feb '16

Here is the portion of your code that validates phone field (in your RegisterAction):

  if (strlen($gsm) != 11 or !ctype_digit($gsm)) {
    $Errors[] = $this->view->lang->_('Field_Error_4');
  }
  // strlen($gsm) != 11
  // ^ this checks if phone is exact 11 characters long

  // !ctype_digit($gsm)
  // ^ this checks if phone is only numeric

You can replace it with something like:

    // check if phone is left empty
    if ($gms == '') {
        $Errors[] = 'Phone is required blabla';
    }

But all of that is just basic php, not much phalcon related. Phalcon has awesome forms/validation services. You can read more there: https://docs.phalcon.io/en/latest/reference/forms.html



878

thank you..