I want to update my database with the ids of characters, but when I drop them into the slot, it doesn't update the rows I want it to update. My question is can you point me in the right direction of how I can code this properly or fix my errors?
function updateTeam(){
var team = '', slot = [];
if($('input[name=s0]').val()!=""){
slot.push($('input[name=s0]').val());
}
if($('input[name=s1]').val()!=""){
slot.push($('input[name=s1]').val());
}
if($('input[name=s2]').val()!=""){
slot.push($('input[name=s2]').val());
}
$.each(slot, function(i,e){
if(i == 0) team = e;
else team = team + ',' + e;
});
$.ajax({
url : _path + "/core/ajax.php",
type : 'POST',
data : { f: 'setTeam', i: team},
dataType : 'json',
success : function(data) {
if(data.error){
errorMessage('Error: ' + data.error, data.error, data.error);
}
}
});
}
Php
function clean($content) {
$content = mysql_real_escape_string(htmlspecialchars($content));
return $content;
}
//Update the user team.
if (isset($_POST['f']) && $_POST['f'] == 'updateTeam') {
if (isset($_POST['s0'])) {
$cid1 = $secure->clean($_POST['s0']);
} else {
$cid1 = '1';
}
if (isset($_POST['s1'])) {
$cid2 = $secure->clean($_POST['s1']);
} else {
$cid2 = '2';
}
if (isset($_POST['s2'])) {
$cid1 = $secure->clean($_POST['s2']);
} else {
$cid1 = '3';
}
$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");
}
When i inspect the element with Google Chrome it says i:1,5,2. Show how would I update my rows so that the 1 in "i"= $cid1, the 5=$cid2, and the 2= cid3, is my php code wrong?
Html:
<div id="droppable_slots" class="current_team">
<div class="slot 1">1</div>
<input type="hidden" name="s0" value="10">
<div class="slot 2">2</div>
<input type="hidden" name="s1" value="7">
<div class="slot 3">3</div>
<input type="hidden" name="s2" value="3">
</div>
Since you are sending a csv with a the key of i, you need to get your values from $_POST['i'] by exploding on the ,. So your code could be updated to something like-
//Update the user team.
if (isset($_POST['f']) && $_POST['f'] == 'updateTeam') {
//Explode the i post
if (isset($_POST['i'])) {
$vals = explode("," , $_POST['i'] );
}
if (isset($vals[0])) {
$cid1 = $secure->clean($vals[0]);
} else {
$cid1 = '1';
}
if (isset($vals[1])) {
$cid2 = $secure->clean($vals[1]);
} else {
$cid2 = '2';
}
if (isset($vals[2])) {
$cid1 = $secure->clean($vals[2]);
} else {
$cid1 = '3';
}
$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");
}
Related
I have a form. I would like to get the input information and send it to the database via 'update_user_meta', however $_POST['this-user'] is giving a blank entry in the database.
The '$user_id' and '$meta_key' are posting to the database but the '$meta_value' is blank.
When I console log $_POST through ajax I get a blank entry in console. When I run .val() in jQuery I also get a blank entry not undefined or NULL.
I have tried having the data section of the code be
data: {
'action': 'hide_this',
'this-user': this-user,
'hidebtn2': hidebtn2
},
However a dash can't be in function i.e 'function doAjaxRequest4(hidebtn2,this-user)' is not allowed.
Insight is appreciated.
PHP
add_action('wp_ajax_hide_this', 'hide_this_by_id');
add_action('wp_ajax_nopriv_hide_this', 'hide_this_by_id');
function hide_this_by_id()
{
global $wpdb;
$labelID4 = 0;
$postdVlaue2 = $_POST['hidebtn2'];
$this_user = $_POST['this-user'];
$alredyclick3 = 0;
$not_loggedin = 0;
$userlvlMeta2 = 0;
if (is_user_logged_in()) {
$member_id = SwpmMemberUtils::get_logged_in_members_id();
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d";
$userData = $wpdb->get_row($wpdb->prepare($query, $member_id));
$membership_levels = $userData->membership_level;
$labelID4 = $membership_levels;
} else {
$not_loggedin = 1;
}
if ($labelID4 == 10 ) {
$userlvlMeta2 = 1;
$alredyclick3 = get_user_meta($member_id, 'hidden-info', true);
if (empty($alredyclick3) && $postdVlaue2 == 1) {
update_user_meta($member_id, 'hidden-info', $postdVlaue2);
update_user_meta($member_id, 'this-user', $this_user);
$alredyclick3 = 1;
}
}
if ($alredyclick3 == 1) {
$this_hide2 = 1;
} else {
$this_hide2 = 0;
}
if ($userlvlMeta2 == 1) {
$this_Meta2 = 1;
} else {
$this_Meta2 = 0;
}
$return4 = array(
'hIdethis2' => $this_hide2,
'userlvlMeta2' => $this_Meta2,
'userlvlNolog' => $not_loggedin,
'levelid4' => $labelID4,
'test' =>$this_user
);
echo json_encode($return4);
die();
}
jQuery
function doAjaxRequest4(hidebtn2,getthisInfo) {
var getthisInfo = jQuery('.this-user > input').val();
console.log(getthisInfo);
jQuery.ajax({
url: ajax_sib_front_object.ajax_url,
data: {
'action': 'hide_this',
'this-user': getthisInfo,
'hidebtn2': hidebtn2
},
dataType: 'JSON',
type: "post",
success: function (data) {
console.log(data.test);
var input = jQuery('.this-user > input');
var input2 = jQuery('.this-number > input');
var is_name = input.length > 3;
var is_name2 = input2.length > 3;
if (!data.thisdisc2 == 1 && data.userlvlMeta2 == 1) {
jQuery("#this_col_1").addClass("enable_this");
} else if (data.thisdisc2 == 1 && is_name && is_name2 ) {
jQuery("#this_col_1").removeClass("enable_this");
jQuery("#this_col_2").addClass("enable_this");
}
}
});
}
Function Called by
if ($('body').is('.page-id-9999') || $('body').is('.page-id-1111')) {
var thisbtn = document.querySelector('#this_verf_form > div > .wpcf7');
thisbtn.addEventListener('wpcf7submit', function (event) {
var status = event.detail.status;
console.log(status);
if (status === 'mail_sent') {
jQuery('#this_submtID').val("Submitted");
}
setTimeout(function () {
doAjaxRequest4(1);
}, 3500);
}, false);
}
HTML
<div role="form" class="wpcf7" id="wpcf7-f9999-p9999-o1" lang="en-US" dir="ltr">
<div class="screen-reader-response"><p role="status" aria-live="polite" aria-atomic="true"></p> <ul></ul></div>
<form action="/mysite/#wpcf7-f9999-p9999-o1" method="post" class="wpcf7-form init" novalidate="novalidate" data-status="init">
<div class="vc_row" id="this_row">
<div class="vc_col-sm-5">
<span class="wpcf7-form-control-wrap this-user"><input type="text" name="this-user" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" placeholder="placeholder"></span>
</div>
<input type="submit" value="Submit" class="wpcf7-form-control has-spinner wpcf7-submit" id="sub_id">
</div>
I have a filter by alphabet within a WordPress website that I would like to filter when the letter is selected without the user having to select the letter and then the search button. However it only seems to work after the 3rd click and that is if you click quickly. The filter itself is a customisation for an existing WordPress directory theme, here is a link to the directory: https://staging.pata.org.uk/item/. How can I get the click to trigger on the first click of a letter rather than the third?
This is the jquery:
<script type="text/javascript">
jQuery(document).ready(function(){
// filter type actions
// checkbox
jQuery('.advanced-filters-wrap-letter ul li.filter-checkbox-letter').on('click', function(e){
jQuery(this).toggleClass('filter-enabled');
var $input = jQuery(this).find('input');
if($input.is(':checked')){
$input.removeAttr('checked');
} else {
$input.attr('checked', true);
}
// filter submit actions
jQuery('.filter-container').on('click', function(e){
e.preventDefault();
// build new query
var addToFilter = "";
var filterString = "";
var filterCheck = 0;
// &filters=id;id;id
jQuery('.advanced-filters-wrap ul li').each(function(){
var $inputOne = jQuery(this).find('input');
if($inputOne.is(':checked')){
addToFilter = $inputOne.val() + " ";
filterCheck += 1;
}
});
jQuery('.advanced-filters-wrap-letter ul li').each(function(){
var $input = jQuery(this).find('input');
if($input.is(':checked')){
filterString = filterString + $input.val() + " " + addToFilter;
filterCheck += 1;
}
});
filterString = filterString.trim().replace(new RegExp(' ', 'g'), ";");
var pathName = window.location.pathname;
/* remove page parameter from url */
pathName = pathName.replace(new RegExp("page\/[0-9]*\/", 'g'), "");
/* remove page parameter from url */
var baseUrl = window.location.protocol+"//"+window.location.host+pathName;
var eParams = window.location.search.replace("?", "").split('&');
var nParams = {};
jQuery.each(eParams, function(index, value){
var val = value.split("=");
if(typeof val[1] == "undefined"){
nParams[val[0]] = "";
} else {
nParams[val[0]] = decodeURIComponent(val[1]);
}
});
var query = jQuery.extend({}, nParams, { filters: filterString });
if(filterCheck == 0){
delete query.filters;
}
delete query.paged;
delete query.count;
// remove empty keys
jQuery.each(query, function(k, v){
if(!k){
delete query[k];
}
});
var queryString = jQuery.param(query);
window.location.href = baseUrl + "?" + queryString;
});
});
});
</script>
and this is the rest of the code
<?php
// &filters=id;id;id;id
$themeOptions = aitOptions()->getOptionsByType('theme');
$advancedFiltersOptions = (object)$themeOptions['itemAdvancedFilters'];
if($advancedFiltersOptions->enabled){
$filters_avalaible = get_terms('ait-items_filters', array('hide_empty' => false));
$filters_enabled = array();
if(isset($_REQUEST['filters']) && !empty($_REQUEST['filters'])){
$filters_enabled = explode(";",$_REQUEST['filters']);
}
if($query->max_num_pages != 1){
// check if there will be pagination
$item_query_args = $query->query_vars; // populate new variable ... dont modify original query
$item_query_args['nopaging'] = true;
$item_query = new WP_Query($item_query_args);
} else {
$item_query = $query;
}
$item_filters = array();
foreach($item_query->posts as $post){
$post_meta = get_post_meta( $post->ID, '_ait-item_filters-options');
if(!empty($post_meta)){
$post_filters = $post_meta[0]['filters'];
foreach ($post_filters as $id) {
$filter = get_term($id, 'ait-items_filters', "OBJECT");
if(!empty($filter)){
array_push($item_filters, $filter);
}
}
}
}
$unique_filters = array_map("unserialize", array_unique(array_map("serialize", $item_filters)));
$filters_avalaible = $unique_filters;
usort($filters_avalaible, function($a, $b){
return strcmp($a->slug, $b->slug);
});
?>
<?php
if(is_array($filters_avalaible) && count($filters_avalaible) > 0){
?>
<div class="advanced-filters-wrap-letter">
<div class="advanced-filters-container">
<div class="content">
<h3>Alphabetical</h3>
<ul class="advanced-filters columns-<?php echo $advancedFiltersOptions->filterColumns ?>">
<?php
$array=array("A", "B", "C", "D", "E", "F","G","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$letters = array();
foreach($filters_avalaible as $filter){
if(in_array($filter->name,$array)) {
array_push($letters, $filter);
}
}
?>
<?php
foreach($letters as $letter)
{
if(!empty($letter))
{
$filter_options = get_option( "ait-items_filters_category_".$letter->term_id );
$filter_type = isset($filter_options['type']) ? $filter_options['type'] : 'checkbox';
$is_enabled = in_array($letter->term_id, $filters_enabled);
$li_class = "";
$in_checked = "";
if($is_enabled){
$li_class = "filter-enabled";
$in_checked = "checked";
}
switch($filter_type){
case 'checkbox':
/*$imageClass = !empty($filter_options['icon']) ? 'has-image' : '';*/
$imageClass = 'has-image';
$image = !empty($filter_options['icon']) ? '<i class="fa '.$filter_options['icon'].'"></i>' : '<i class="fa fa-dot-circle-o"></i>';
echo '<li class="filter-container filter-checkbox-letter '.$li_class.' '.$imageClass.' "><input type="checkbox" name="'.$letter->slug.'" value="'.$letter->term_id.'" '.$in_checked.'> <span class="filter-name">'.$letter->name.'</span></li>';
break;
default:
echo '<li class="filter-container filter-unsupported">'.__('Unsupported filter', 'ait-advanced-filters').'</li>';
break;
}
}}}?>
</ul>
</div>
</div>
<div class="advanced-filters-actions">
<?php _e('Search', 'ait') ?>
Back
</div>
</div>
<?php
}
I have an issue with JQuery and Ajax. Sometimes my code works just fine, sometimes it just will not. Other times I need to press a down arrow once in order to make the up arrows work, which is strange enough...
In IE or in Firefox, the lack of response happens more rarely than it does in Chrome.
The website in question is here:
http://www.dungeoncrawler.com/kickstarter_2013/calculator/
If you need to login, try:
ID: webmaster#geoste.ca
Pass: 123456789
Here is an example of my code:
Javascript JQuery function : first either chnQuantUp or chnQuantDn is called, and then the data gets passed to doCrtUpd which does the actual JQuery call.
function doCrtUpd(crtID,itmAmt,itmStrID)
{
// Call AJAX to update cart quantities
if (crtID)
{
$.ajax({
type: 'POST',
url: 'inc-kspldgman.php',
data: {cartordrnum: crtID,itmamt: itmAmt,storeitmkey: itmStrID, doaction: "UPDITM"},
async: true,
success: function (d)
{
reLoadDivs();
},
error: function (d)
{
alert(d);
}
});
}
}
function chnQuantUp(frmEle,frmEleID,crtID,itmStrID)
{
tmpvar2 = frmEle + frmEleID;
tmpvar1 = eval("document.frmStrItms."+ tmpvar2 +".value");
if (isNaN(tmpvar1))
{
tmpvar1 = 1;
}
else
{
tmpvar1 = parseInt(tmpvar1);
tmpvar1++;
}
eval("document.frmStrItms."+ tmpvar2 +".value = " + tmpvar1);
doCrtUpd(crtID,tmpvar1,itmStrID);
}
function chnQuantDn(frmEle,frmEleID,crtID,itmStrID)
{
tmpvar2 = frmEle + frmEleID;
tmpvar1 = eval("document.frmStrItms."+ tmpvar2 +".value");
if (isNaN(tmpvar1))
{
tmpvar1 = 0;
}
else
{
tmpvar1 = parseInt(tmpvar1);
}
tmpvar1--;
if (tmpvar1 < 0)
{
tmpvar1 = 0;
}
eval("document.frmStrItms."+ tmpvar2 +".value = " + tmpvar1);
doCrtUpd(crtID,tmpvar1,itmStrID);
}
Example of my HTML, one of the store items:
<div name="frmEle14" id="frmEle14" class="item" style=" background-image: url(./gallery/calc_ID_84.png);">
<div class="item_name">GREENKNEE, PPM</div>
<div class="item_count_5">
<div align="center">
<img src="images/calc_arrow_up_lw.jpg" border="0" class="arrow_btn1" /><br />
<input type="text" name="frmeleamt14" id="frmeleamt14" class="count_box" value="0" size="3" maxlength="3" onkeyup="javascript:doManChng('0',document.frmStrItms.frmeleamt14.value,'38','frmeleamt14');" /><br />
<input type="hidden" name="frmelesku14" id="frmelesku14" value="GVN-DCM-0005-CHAMP-PPM" />
<input type="hidden" name="frmelesalecode14" id="frmelesalecode14" value="NONE" />
<input type="hidden" name="frmeleitmkey14" id="frmeleitmkey14" value="38" />
<input type="hidden" name="frmgvnlinekey14" id="frmgvnlinekey14" value="0" />
<img src="images/calc_arrow_down_lw.jpg" border="0" class="arrow_btn2" />
<input type="hidden" name="frmelepicnme14" id="frmelepicnme14" value="calc_ID_84.png" />
</div>
</div>
<div class="item_price">$3.00</div>
</div>
And the PHP code that handles the actual addition to the database:
if ($cartordrnum)
{
// Start UPDATE
if ($doaction == "UPDITM")
{
$rspns = "";
// Get store item's data that we need, such as price per unit
$sql = "SELECT item_unitprice,salecode FROM store_items WHERE itemkey = ".$storeitmkey.";";
$getitmdata1 = mysqli_query($conn,$sql);
$getitmdata = mysqli_fetch_array($getitmdata1);
$itemunitprice = $getitmdata['item_unitprice'];
settype($itemunitprice,"float");
$salecode = $getitmdata['salecode'];
settype($salecode,"string");
$getitmdata = null;
$getitmdata1 = null;
// Do new item total if it has not already been calculated via salecode
if ($itmttl == 0)
{
$itmttl = ($itmamt * $itemunitprice);
}
$gvnlinekey = 0;
$dbitmamt = 0;
$sql = "SELECT lineitmkey, linequant FROM gvn_lineitems WHERE storeitmkey = ".$storeitmkey." AND code_note IS NULL ORDER BY lineitmkey DESC LIMIT 0,1;";
$chklineitm1 = mysqli_query($conn,$sql);
if (mysqli_num_rows($chklineitm1))
{
$chklineitm = mysqli_fetch_array($chklineitm1);
$gvnlinekey = $chklineitm['lineitmkey'];
settype($gvnlinekey,"integer");
$dbitmamt = $chklineitm['linequant'];
settype($dbitmamt,"integer");
}
$chklineitm = null;
if ($gvnlinekey)
{
if ($itmamt)
{
// Check if amounts have changed.
if ($dbitmamt != $itmamt)
{
// We have a change, so do an update.
// Do DB update
$sql = "UPDATE gvn_lineitems SET linequant = ".$itmamt.", linesubttl = ".$itmttl.", linettl = ".$itmttl." WHERE lineitmkey = ".$gvnlinekey.";";
if (mysqli_query($conn,$sql))
{
$rspns = "UPDATED";
}
}
}
else
{
// Delete the lineitem because it has a zero or negative amount
$sql = "DELETE FROM gvn_lineitems WHERE lineitmkey = ".$gvnlinekey." AND code_note IS NULL;";
if (!mysqli_query($conn,$sql))
{
$rspns = "DELETED1";
}
}
}
else
{
// Insert new line item
if ($itmamt > 0)
{
$sql = "INSERT INTO gvn_lineitems (ordrnumkey,storeitmkey,linequant,linesubttl,linettl) VALUES (".$cartordrnum.",".$storeitmkey.",".$itmamt.",".$itmttl.",".$itmttl.");";
if (mysqli_query($conn,$sql))
{
$rspns = "ADDED";
}
}
else
{
// Delete the lineitem because it has a zero or negative amount
$sql = "DELETE FROM gvn_lineitems WHERE storeitmkey = ".$storeitmkey." AND code_note IS NULL;";
if(mysqli_query($conn,$sql))
{
$rspns = "DELETED2";
}
}
}
$chklineitm1 = null;
//echo $rspns;
}
I have multiple dynamic textboxes where users input license plate no. I'm trying to retrieve the id corresponding to the license plate # inputted by the user from the database but I'm unable to get it. I want to store the license plate #'s id that's already in the database to a different table and not the license plate no itself, but It always returns null.
Thanks in advance.
search.js
function firetruckAddingTextBoxes() {
var NumOfText = $("#NumOfTextBoxes2").val();
$('.NewlyCreatedSelectBoxes2').empty();
var txtBox = "";
for (i = 0; i < NumOfText; i++) {
txtBox += '<input type="text" name="firetruck[]" class="search" placeholder="License Plate No" required/><br>';
}
$('.NewlyCreatedSelectBoxes2').append(txtBox);
$(".NewlyCreatedSelectBoxes2").on("keyup", ".search", function () {
var search_term = $(this).val();
$('#search_results2').html('Searching database...');
if (search_term !== '') {
$.post('php/firetruck_search.php', { search_term: search_term }, function (data) {
$('#search_results2').html(data);
});
} else {
$('#search_results2').html('Not Found');
}
});
return false;
}
search.php
<?php
require('connectdb.php');
if(isset($_POST['search_term']))
{
$search_term = mysql_real_escape_string(htmlentities($_POST['search_term']));
if(!empty($search_term))
{
$search = mysql_query("SELECT `fireTruckID`, `licensePlateNo` FROM `firetruckinfo` WHERE `licensePlateNo` LIKE '%$search_term%'");
$result_count = mysql_num_rows($search);
$suffix = ($result_count != 1) ? 's' : '';
echo '<p>Your search for ', $search_term, ' returned ', $result_count, ' result', $suffix, '</p>';
while($results_row = mysql_fetch_assoc($search))
{
echo '<p>', $results_row['licensePlateNo'], '</p>';
}
}
}
?>
occurrence.php
$firetrucks = $_POST['firetruck'];
foreach($firetrucks as $firetruck):
$vehicleID = mysql_query("SELECT `fireTruckID` FROM `firetruckinfo` WHERE `licensePlateNo`='$firetruck'");
$row2 = mysql_fetch_assoc($vehicleID);
$query3 = "INSERT INTO `truckonscene`(`FireTruckInfo_fireTruckID`, `IncidenceOfFire_incidentID`)
VALUES(
'".mysql_real_escape_string($row2['fireTruckID'])."',
'".mysql_real_escape_string($incidentid)."')";
mysql_query($query3) or die(mysql_error());
endforeach;
got this function to validate two fields from a changing password form and it's doesn't seem to work at IE8. FF, Opera, Safari and Chrome work.
function chk_form_pw()
{
if(document.getElementById('new_passwd').value == '')
{
alert("<?php _e('Please enter New Password') ?>");
document.getElementById('new_passwd').focus();
return false;
}
if(document.getElementById('new_passwd').value.length < 5 )
{
alert("<?php _e('Please enter New Password minimum 5 chars') ?>");
document.getElementById('new_passwd').focus();
return false;
}
if(document.getElementById('cnew_passwd').value == '')
{
alert("<?php _e('Please enter Confirm New Password') ?>");
document.getElementById('cnew_passwd').focus();
return false;
}
if(document.getElementById('cnew_passwd').value.length < 5 )
{
alert("<?php _e('Please enter Confirm New Password minimum 5 chars') ?>");
document.getElementById('cnew_passwd').focus();
return false;
}
if(document.getElementById('new_passwd').value != document.getElementById('cnew_passwd').value)
{
alert("<?php _e('New Password and Confirm New Password should be same') ?>");
document.getElementById('cnew_passwd').focus();
return false;
}
}
This is the form:
<form name="registerform" id="registerform" action="<?php echo get_option( 'siteurl' ).'/?page=account&chagepw=1'; ?>" method="post">
<p><label><?php _e('New Password'); ?> <span class="indicates">*</span></label></p>
<p><input type="password" name="new_passwd" id="new_passwd" class="lostpass_textfield" /></p>
<p><label><?php _e('Confirm New Password'); ?> <span class="indicates">*</span></label></p>
<p><input type="password" name="cnew_passwd" id="cnew_passwd" class="lostpass_textfield" /></p>
<p><input type="submit" name="Update" onclick="return chk_form_pw();" value="<?php _e('Update Password') ?>" class="btn grey"/></p>
</form>
And here is the chagepw=1 thing:
<?php
if($_POST)
{
if($_REQUEST['chagepw'])
{
$new_passwd = $_POST['new_passwd'];
if($new_passwd)
{
$user_id = $current_user->data->ID;
wp_set_password($new_passwd, $user_id);
$message1 = "Password Changed successfully.You need to sign back in.";
}
}else
{
$user_id = $userInfo['ID'];
$user_add1 = $_POST['user_add1'];
$user_add2 = $_POST['user_add2'];
$user_city = $_POST['user_city'];
$user_state = $_POST['user_state'];
$user_country = $_POST['user_country'];
$user_postalcode = $_POST['user_postalcode'];
$buser_add1 = $_POST['buser_add1'];
$buser_add2 = $_POST['buser_add2'];
$buser_city = $_POST['buser_city'];
$buser_state = $_POST['buser_state'];
$buser_country = $_POST['buser_country'];
$buser_postalcode = $_POST['buser_postalcode'];
$user_address_info = array(
"user_add1" => $user_add1,
"user_add2" => $user_add2,
"user_city" => $user_city,
"user_state" => $user_state,
"user_country" => $user_country,
"user_postalcode"=> $user_postalcode,
"buser_name" => $_POST['buser_fname'].' '.$_POST['buser_lname'],
"buser_add1" => $buser_add1,
"buser_add2" => $buser_add2,
"buser_city" => $buser_city,
"buser_state" => $buser_state,
"buser_country" => $buser_country,
"buser_postalcode"=> $buser_postalcode,
);
update_usermeta($user_id, 'user_address_info', serialize($user_address_info)); // User Address Information Here
$userName = $_POST['user_fname'].' '.$_POST['user_lname'];
$updateUsersql = "update $wpdb->users set user_nicename=\"$userName\", display_name=\"$userName\" where ID=\"$user_id\"";
$wpdb->query($updateUsersql);
$message = "Information Updated successfully.";
}
}
$userInfo = $General->getLoginUserInfo();
$user_address_info = unserialize(get_user_option('user_address_info', $user_id));
$user_add1 = $user_address_info['user_add1'];
$user_add2 = $user_address_info['user_add2'];
$user_city = $user_address_info['user_city'];
$user_state = $user_address_info['user_state'];
$user_country = $user_address_info['user_country'];
$user_postalcode = $user_address_info['user_postalcode'];
$display_name = $userInfo['display_name'];
$display_name_arr = explode(' ',$display_name);
$user_fname = $display_name_arr[0];
$user_lname = $display_name_arr[2];
$buser_add1 = $user_address_info['buser_add1'];
$buser_add2 = $user_address_info['buser_add2'];
$buser_city = $user_address_info['buser_city'];
$buser_state = $user_address_info['buser_state'];
$buser_country = $user_address_info['buser_country'];
$buser_postalcode = $user_address_info['buser_postalcode'];
$bdisplay_name = $user_address_info['buser_name'];
$display_name_arr = explode(' ',$bdisplay_name);
$buser_fname = $display_name_arr[0];
$buser_lname = $display_name_arr[2];
if($_SESSION['redirect_page'] == '')
{
$_SESSION['redirect_page'] = $_SERVER['HTTP_REFERER'];
}
if(strstr($_SESSION['redirect_page'],'page=checkout'))
{
$login_redirect_link = get_option( 'siteurl' ).'/?page=checkout';
}
?>
A smoother solution would be jQuery. There you can load a loading-animation, put color like red/green on wrong/correct and simplified print out text depending on what happening to the form.
Download jQuery from: http://docs.jquery.com/Downloading_jQuery
Then you insert it in the html code like this:
<script type="text/javascript" src="jquery.js">
</script>
Then you can have a valid.js like this:
$(document).ready(function () {
var validatefield = $('#validatefield');
$('#validatefield').keyup(function () {
var t = this;
if (this.value != this.lastValue) {
if (this.timer) clearTimeout(this.timer);
validatefield.html('<img src="images/Here_you_can_put_your_gif_animation"
alt="Loading..."
height="16" width="16"/>');
this.timer = setTimeout(function () {
$.ajax({
url: 'check_field.php',
data: 'action=check_field&field=' + encodeURIComponent(t.value),
dataType: 'json',
type: 'post',
success: function (j) {
if (j.ok) {
validatefield.html(j.msg);
}
else if ($("#validatefield").val() == "")
{
validatefield.html('');
}
else {
validatefield.html(j.msg);
}
}
});
}, 200);
this.lastValue = this.value;
}
});
});
Then in the check_field.php, have this;
echo json_encode(check_field($_POST['field']));
function check_field($field) {
$fieldSum = stripslashes(strip_tags(trim(htmlspecialchars($field))));
$response = array();
if (strlen($fieldSum) > 15) {
$response = array(
'ok' => false,
'msg' => "The field characters were over 15!");
}
else
{
$response = array(
'ok' => true,
'msg' => "Correct");
}
return $response;
}
The id #validatefield is an id inside the html code that you have to create in order to print things out.
Example:
<div id="validatefield">Here comes the text etc, from the valid.js</div>
Finally got it done using the JQuery script posted before:
http://code.google.com/p/form-validation-engine/downloads/list
It's been really easy to fit into my previous code and works flawlessly through every browser tested.
Thank you all for your help!