How update custom field checkbox ACF in user profile from front page - php

I made a group of fields of type Checkbox to be able to select several options using ACF | Advanced Custom Fields, these fields are added to the profile of the user in the WP dashboard, I want to edit them from the front end using a custom form.
Fields created:
Fields in user profile:
Form in front page
I need when you select any option / checkbox on the page of the frontpage that is saved and also updated in the user's profile.
The code that I have in the from template is this:
account_page.php
<form id="your-profile" class="nice" action="<?php echo the_permalink() ?>" method="POST" />
<div>
<p>Please check the email newsletters you wish to receive.<br>Unchecking a box will unsubscribe you from future emails.</p>
</div>
<fieldset>
<input name="_wp_http_referer" value="<?php echo home_url('account') ?>" type="hidden">
<input name="from" value="profile" type="hidden">
<input name="action" value="update" type="hidden">
<input name="user_id" id="user_id" value="<?php echo $current_user->ID ?>" type="hidden">
<input name="checkuser_id" value="<?php echo get_current_user_id(); ?>" type="hidden">
<input name="nickname" value="<?php echo $current_user->user_email ?>" type="hidden">
<input name="user_email" value="<?php echo $current_user->user_email ?>" type="hidden">
<input name="phone" value="<?php echo $current_user->phone; ?>" type="hidden">
<input name="first_name" value="<?php echo $current_user->first_name ?>" type="hidden">
<input name="last_name" value="<?php echo $current_user->last_name ?>" type="hidden">
<input name="address" value="<?php echo $current_user->address ?>" type="hidden">
<input name="address2" value="<?php echo $current_user->address2 ?>" type="hidden">
<input name="city" value="<?php echo $current_user->city; ?>" type="hidden">
<input name="state" value="<?php echo $current_user->state; ?>" type="hidden">
<input name="zip_code" value="<?php echo $current_user->zip_code; ?>" type="hidden">
<input name="country" value="<?php echo $current_user->country; ?>" type="hidden">
<?php
//Get all items from newslwtter
$newsletter = get_field('newsletter_preferences', $current_user);
$id = get_the_ID();
$field = get_field_objects($current_user);
$field_name = $field["newsletter_preferences"]["name"];
if( $field ){
foreach ( $field["newsletter_preferences"]['choices'] as $key => $value) {
if ( in_array( $key, $newsletter ) ) {
$checked = 'checked';
}else{
$checked = '';
}
echo '<p class="field"><input type="checkbox" '.$checked.' name="'.$field_name.'" value="'.$key.'">'.$value.'</p>';
}
}
?>
</fieldset>
<div>
<input class="btn btn-primary" name="Update E-mail Preferences" value="Update E-mail Preferences" type="submit">
<?php wp_nonce_field( 'update-user' ) ?>
<input name="action" type="hidden" id="action" value="update-user">
</div>
</form>
And in the functions.php
function update_extra_profile_fields($user_id) {
if ( isset( $_POST['newsletter_preferences'] ) )
update_user_meta( $user_id, 'newsletter_preferences',
$_POST['newsletter_preferences'] );
}
add_action('personal_options_update','update_extra_profile_fields');
But don't work, dont save anything, help me please. Thank you

Solved creating :
function update_extra_profile_fields($user_id) {
if ( isset( $_POST['state'] ) )
$state = update_user_meta( $user_id, 'state', $_POST['state'] );
.
.
.
//all fields to save
}
add_action('personal_options_update', __NAMESPACE__ . '\\update_extra_profile_fields');

Related

how do i integration of payumoney payment gateway using isset function in php?

I have tried to integration of payumoney payment gateway. I have a page cart.php and i have done following code for the same:
if(isset($_POST['image-pay']){
$MERCHANT_KEY = "rjQUPktU";
$SALT = "e5iIg1jwi8";
$PAYU_BASE_URL = "https://test.payu.in";
$action = '';
$key = $MERCHANT_KEY;
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$productinfo = 'photos';
$firstname = $_POST['firstname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$success_url = 'http://example.com/checkout/final-success.php';
$failure_url = 'http://example.com/checkout/failure.php';
$cancel_url = 'http://example.com/checkout/cancel.php';
$service_provider = "payu_paisa";
$hash = '';
$hasTemp = $key."|".$txnid."|".$amount."|".$productinfo."|".$firstname."|".$email."|||||||||||".$SALT;
$hash = strtolower(hash('sha512', $hasTemp));
$action = $PAYU_BASE_URL . '/_payment';
}
<form action="<?php echo $action; ?>" method="post" name="payuForm" id="jps_payuform">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY; ?>" />
<input type="hidden" name="hash" value="<?php echo $hash; ?>"/>
<input type="hidden" name="hash_temp" value="<?php echo $hasTemp; ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid; ?>" />
<input type="hidden" name="amount" value="<?php echo $amount; ?>" />
<input type="hidden" name="surl" value="<?php echo $success_url; ?>" size="64" />
<input type="hidden" name="furl" value="<?php echo $failure_url; ?>" size="64" />
<input type ="hidden" name="curl" value="<?php echo $cancel_url; ?>" />
<input type="hidden" name="service_provider" value="<?php echo $service_provider; ?>" size="64" />
<input type="hidden" name="productinfo" value="<?php echo $productinfo; ?>" />
<input type="hidden" name="udf1" value="<?php echo $numberPics; ?>" />
<h3 class="att_heading" style="text-align: center;">Your Personal Details</h3>
<label><span class="required_jps_field">*</span> Mandatory Parameters</b></label>
<label><span class="required_jps_field">*</span> Name: </label>
<input name="firstname" class="form-control" value="<?php echo $firstname; ?>" required />
<label><span class="required_jps_field">*</span> Email:</label>
<input name="email" id="email" class="form-control" value="<?php echo $email; ?>" required />
<label><span class="required_jps_field">*</span> Phone: </label>
<input name="phone" class="form-control" value="<?php echo $phone; ?>" required />
<input type="submit" class="btn btn-info" name="image-pay" value="Process" />
</form>
It's working fine but problem is when i use isset($_POST['image-pay']) function then i have to click twice on submit button and then it redirect payumoney page and if i remove this (isset($_POST['image-pay']) function then submit button works in single click but then it does not pass name, email and phone to payumoney.
Please help and tell me where am i doing wrong?

trim textfield value and set it for radio button value in the seem screen before submit

i want to get the textfield value and assign it for the radio button value
my code is working but not from the first time
after the first submit it will work perfectly
how do i make it work from the first page load
here is my code
<input type="text" name="optionAtxt" value="<?php echo #$_POST['optionAtxt'] ?>" />​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ <input type="radio" name="option" required value="<?php echo #$_POST['optionAtxt'] ?>">
<input type="text" name="optionBtxt" value="<?php echo #$_POST['optionBtxt'] ?>" />​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ <input type="radio" name="option" value="<?php echo #$_POST['optionBtxt'] ?>">
<input type="text" name="optionCtxt" value="<?php echo #$_POST['optionCtxt'] ?>"/>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ <input type="radio" name="option" value="<?php echo #$_POST['optionCtxt'] ?>">
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="submitted" value="1" />
<?php
if (isset($_POST['submitted'])) {
$selected = trim($_POST['option']);
echo $selected;
}?>

Joomla 1.5 with Virtuemart 1.1.9

I want add changing on category page, I customize page websitelink.com/components\com_virtuemart\themes\default\templates\browse\browse_3.php
I add code
<div class="addtocart_buttonList">
<?php
$button_lbl = $VM_LANG->_('PHPSHOP_CART_ADD_TO');
$button_cls = 'addtocart_button';
if( CHECK_STOCK == '1' && ( $product_in_stock < 1 ) ) {
$button_lbl = $VM_LANG->_('VM_CART_NOTIFY');
$button_cls = 'notify_button';
$notify = true;
} else {
$notify = false;
}
?>
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
<input type="hidden" name="category_id" value="<?php echo #$_REQUEST['category_id'] ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
<input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="func" value="cartadd" />
<input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="set_price[]" value="" />
<input type="hidden" name="adjust_price[]" value="" />
<input type="hidden" name="master_product[]" value="" />
</form>
</div>
After adding this line add to cart button appear on list items, but than i click on add to cart button error will come
Please enter a valid quatity for this item
How i can solve this?
You need to specify a quantity as an input field, hidden or otherwise. We only wanted the customer to be able to order one of an item, so added this code:
<input type="hidden" value="1" name="quantity">
Having that named input field satisifed the Virtuemart validation.

Wordpress registration redirect priority

I have asked this question but posted it incorrectly.
The following code redirects people to a custom page:
function possibly_redirect(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
wp_redirect('https://www.mydomain.co.za/custom-page/');
exit();
}
}
I have added a custom login plugin but don't want it to pop up on registration negating the custom page. Is there a way to make the initial redirect happen first and prevent the registration form from loading?
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
<?php _e('Username'); ?>:
<input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" tabindex="101" />
<?php _e('Your Email'); ?>:
<input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" tabindex="102" />
<?php _e('Your pwd'); ?>:
<input type="text" name="user_pass" value="<?php echo esc_attr(stripslashes($user_pass)); ?>" size="25" id="user_pass" tabindex="103" />
<?php do_action('register_form'); ?>
<input type="submit" name="user-submit" value="<?php _e('Sign up!'); ?>" class="user-submit" tabindex="104" />
<?php $register = $_GET['register']; if($register == true) { echo '<p>Check your email for the password!</p>'; } ?>
<input type="hidden" name="redirect_to" value="<?php bloginfo('url') ?>?register=true" />
<input type="hidden" name="user-cookie" value="1" />
</form>

How to implement Paybox deferred payment?

How do I integrate paybox system to handle deferred payment?
I learned that PBX_DIFF parameter is used to mention no. of days to delay the transaction. Thats exactly what I wanted. But there seems no working code for php with deferred payment for Paybox.
The following code is working fine without mentioning the deferred payment parameter (PBX_DIFF). But when I add that parameter, its not working
<form name="paybox_frm" id="paybox_frm" method="GET" action="<?php echo $payboxUrl;?>">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?PHP echo $MONTANT;?>">
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?PHP echo $REFERENCE;?>">
<input type="hidden" name="PBX_PORTEUR" value="<?PHP echo $PORTEUR;?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR;?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH;?>">
<input type="hidden" name="PBX_TIME" value="<?PHP echo $datetime;?>">
<input type="hidden" name="PBX_HMAC" value="<?PHP echo $pbx_hmac;?>">
<!-- Code added for return url-->
<input type="hidden" name="PBX_REFUSE" value="<?PHP echo $PBX_REFUSE;?>" />
<input type="hidden" name="PBX_ANNULE" value="<?PHP echo $PBX_ANNULE;?>" />
<input type="hidden" name="PBX_EFFECTUE" value="<?PHP echo $PBX_EFFECTUE;?>" />
<input type="hidden" name="PBX_LANGUE" value="<?PHP echo $PBX_LANGUE;?>" />
Any help greatly appreciated. Thanks in advance.
<section class="rl-box">
<div class="container padd-xs-0">
<div class="content-section1">
<div class="left-cont col-md-12 col-sm-12"
<div class="container-fluid">
<?php
$PBX_SITE = "1999888";
$PBX_RANG = "32";
$PBX_IDENTIFIANT = "your identifiant id";
$secretKeyTest = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$PBX_PORTEUR = "your-email";
$PAYBOX_DOMAIN_SERVER = "tpeweb.paybox.com";
$dateTime = date("c");
$PBX_TOTAL = 4000; //$_POST["PBX_TOTAL"]; // Amount
$PBX_DEVISE = 978;
//$PBX_CMD = $_POST["PBX_CMD"]."|".$_POST["user"]."|".$_POST["typed"]."|".$_POST["period"]."|".$_POST["id"]; // order ID no.
$PBX_CMD = 1; // order ID no.
$PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E";
$PBX_HASH = "SHA512";
$PBX_TIME = $dateTime;
//$PBX_EFFECTUE = "http://www.leader-underwriting.eu/payment/payment.php";
$msg = "PBX_SITE=$PBX_SITE" .
"&PBX_RANG=$PBX_RANG" .
"&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" .
"&PBX_TOTAL=$PBX_TOTAL" .
"&PBX_DEVISE=$PBX_DEVISE" .
"&PBX_CMD=$PBX_CMD" .
"&PBX_PORTEUR=$PBX_PORTEUR" .
"&PBX_RETOUR=$PBX_RETOUR" .
"&PBX_HASH=$PBX_HASH" .
"&PBX_TIME=$PBX_TIME";
$binKey = pack("H*", $secretKeyTest);
$hmac = strtoupper(hash_hmac('sha512', $msg, $binKey));
$cuu = str_replace(",", "", $ramount);
?>
<form method="POST" name="form_payment" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?php echo $PBX_TOTAL; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?php echo $PBX_CMD; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_PORTEUR" value="<?php echo $PBX_PORTEUR ?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR; ?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH; ?>">
<input type="hidden" name="PBX_TIME" value="<?php echo $PBX_TIME; ?>">
<input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>">
<button type="submit" class="btn btn-primary payment">
Payer
</button>
</form>
<center>
</center>
</div>
</div>
</div> <!-- .container-fluid -->
</div>
</div>
</div>
</section>

Categories