<script>
/* to populate list of value in dropdown via ajax */
function populateSectionsList(id)
{
var idval = id;
var setOptTemp = "<option value='%d'>%s</option>";
var html = "<option value=''>-- Select --</option>";
$.ajax({
type:'post',
url:'http://localhost/myproject/ajaxurl',
data:{'id':idval, 'action':edit},
error:function(){
alert('You have error. Please try again');
},
success:function(data){
var optionList = $.parseJSON(data);
$.each(optionList, function(i, optDetails){
html += setOptTemp.replace('%d', optDetails.id).replace('%s', optDetails.name);
});
$('#dropid').html(html).show();
}
});
}
</script>
//myprojet/ajaxurl.php
<?php
foreach($dropListArr as $value)
{
$dataArr[] = array('id' => $value['id'], 'name' => $value['textname']);
}
?>
Thursday, July 24, 2014
Populate/change list of value in dropdown/select box via ajax
Wednesday, July 23, 2014
Check Username exist - Ajax
<script>
$(document).ready(function() {
var isUnameExist = false;
//$("#frmregister").validate();
$("#frmregister").validate({
rules: {
username:{
required:true,
custom_usernameValidate:true
}
}
});
$.validator.addMethod('custom_usernameValidate', function(val) {
$.ajax({
type:'post',
url:"http://localhost/myproj/ajaxchecking.php",
data:{'username':val},
async:false,
success:function(data){
//console.log(data);
if(data == 'no')
isUnameExist = true;
else
isUnameExist = false;
}
});
return isUnameExist;
},"username already exist");
});
</script>
jQuery Validation
$(document).ready(function() {
$("#signupForm").validate({
rules: {
firstname: "required",
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
},
email: {
required: true,
email: true
},
agree: "required"
},
messages: {
firstname: "Please enter your firstname",
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
confirm_password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
email: "Please enter a valid email address",
agree: "Please accept our policy"
}
});
});
Wednesday, February 5, 2014
zend list page
public function listuserAction()
{
$db = Zend_Db_Table::getDefaultAdapter();
//$db = $this->_db;
$select = $db->select();
$select->from('user', array('*'));
$test = $db->fetchAll($select);
print_r($test); die;
}
-----------
login
<div><?php echo $this->fmessages; ?></div>
<form name="<?php echo $this->form->getAttrib('name'); ?>" id="<?php echo $this->form->getAttrib('id'); ?>" action="<?php echo $this->form->getAction(); ?>" method="<?php echo $this->form->getMethod(); ?>">
<ul>
<li>
<label>Username: <?php echo $this->form->user_name; ?></label>
</li>
<li>
<label>Password: <?php echo $this->form->password; ?></label>
</li>
<li>
<?php echo $this->form->login; ?>
</li>
</ul>
</form>
-----
public function init()
{
//Initialize action controller here
$this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
$registry = Zend_Registry::getInstance();
$this->_em = $registry->entitymanager;
if($this->_flashMessenger->getMessages())
{
$fmsgArr = $this->_flashMessenger->getMessages();
$this->fmsg = $fmsgArr[0];
}
$this->view->fmessages = $this->fmsg;
$this->request = Zend_Controller_Front::getInstance()->getRequest();
$this->contUrl = $this->request->getBaseUrl().'/'.$this->request->getModuleName().'/'.$this->request->getControllerName();
}
public function getUserMapperObj()
{
if(is_null($this->userObj))
{
$this->userObj = new User_Model_userRegisterMapper($this->_em);
}
return $this->userObj;
}
--------
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity())
{
$this->_redirect('/user/login');
}
Zend auth checking
public function authAction()
{
$request = $this->getRequest();
$registry = Zend_Registry::getInstance();
$auth = Zend_Auth::getInstance();
$DB = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($DB);
$authAdapter->setTableName('user')
->setIdentityColumn('user_name')
->setCredentialColumn('password');
// Set the input credential values
$uname = $request->getParam('user_name');
$paswd = $request->getParam('password');
$authAdapter->setIdentity($uname);
$authAdapter->setCredential(md5($paswd));
// Perform the authentication query, saving the result
$result = $auth->authenticate($authAdapter);
if($result->isValid())
{
$data = $authAdapter->getResultRowObject(null,'password');
$auth->getStorage()->write($data);
$this->_redirect('user/index/listuser');
}
else
{
$this->_flashMessenger->addMessage($this->view->translator('user_invalid_login'));
$this->_redirect('user/index/login');
}
}
zend db connection
resources.db.adapter = "PDO_MYSQL"
resources.db.isDefaultAdapter = true
resources.db.params.host = "localhost"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.dbname = "zend_learn"
----------
{
$form = new User_Form_loginForm();
$this->view->form = $form;
}
-----------
class User_Form_loginForm extends Zend_Form
{
public function init()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
$action = $request->getBaseUrl().'/'.$request->getModuleName().'/'.$request->getControllerName().'/auth';
$this->setMethod('post')
->setName('frmlogin')
->setAttrib('id', 'frmlogin')
->setAction($action);
$username = $this->createElement('text', 'user_name');
$username->setAttrib('class', 'required')
->setAttrib('minlength', 4)
->setAttrib('maxlength', 15)
//->addFilter(array('StripTags', 'StringTrim'))
->addFilter('StripTags')
->addFilter('StringTrim')
->setRequired(true);
$password = $this->createElement('password', 'password');
$password->setAttrib('class', 'required')
->setRequired(true);
$submit = $this->createElement('submit', 'login');
$this->addElements(array($username, $password, $submit));
}
}
Subscribe to:
Posts (Atom)