How Show Success Message After form submit in wordpress? - wordpress

How Show Success Message After form submit in word press ? This code is used for review submission .I need to show success message(Your review has been successfully submitted) after submit my review.My html code :
<div class="container">
<div class="row">
<div class="reviews">
<?php
if (is_user_logged_in()) {
?>
<h2>REVIEWS ON <?php echo get_the_title(); ?> </h2>
<div class="message-box">
<form method="post">
<div class="rating">
<div class="rating-inner">
<div id="rateYo1"></div><p>Rate the store</p>
</div>
</div>
<textarea class="review_message" name="message_review" id="message" placeholder="Type your review here..." required></textarea>
<button class="review_submit_button" name="review_submit" value="Submit Review">Submit Review</button>
<input type="hidden" id="data-rating" name="data-rating" >
</form>
</div>
<?php }?>
</div>
</div>
</div>
<?php
$img = showImage();
$user_avatar=$img[0]->mem_photo;
if (isset($_POST['review_submit'])) {
$review_content = $_POST['message_review'];
$data_rating = $_POST['data-rating'];
$shop_id = get_the_ID();
add_user_review($review_content, $data_rating, $shop_id, $user_avatar);
}
?>
Function code:
function add_user_review($review,$data_rating,$shop_id,$user_avatar){
global $wpdb;
$current_user=wp_get_current_user();
$current_user_id=$current_user->ID;
$username=$current_user->display_name;
$user_email=$current_user->user_email;
$review_date= date("m/d/Y");
$in=$wpdb->insert("wp_user_reviews" ,array(
"review_content"=>$review,
"review_rating"=>$data_rating,
"wp_user_id"=>$current_user_id,
"user_name"=>$username,
"product_id"=>$shop_id,
"review_date"=>$review_date,
"user_email"=>$user_email,
"user_avatar"=>$user_avatar,
));
}
please help.Thanks :)

Change your if condition to this
if (isset($_POST['review_submit'])) {
$review_content = $_POST['message_review'];
$data_rating = $_POST['data-rating'];
$shop_id = get_the_ID();
if(add_user_review($review_content, $data_rating, $shop_id, $user_avatar)){
echo "<script>alert('success')</script>";
} else {
echo "<script>alert('fail to insert')</script>";
}
}
or you can write this in functions.php aswell
<script>
$( ".review_submit_button" ).click(function() {
alert( "success" );
});
</script>
This is always work for :)

Related

How can i use this code for specific woocommerce category id

How can i use this code for showing progress bar in product page? i want a condition i dont want to show this to only specific product id instead i want to show this in specific woocommerce categories here is the code
function wapf_before_wrapper($product) {
$product_ids = array(123,987,630);
if( ! in_array($product->get_id(), $product_ids) ) return;
?>
<div class="wapf-progress">
<div class="wapf-progress-bar"></div>
<div class="wapf-progress-steps"></div>
</div>
<?php
}
add_action('wapf_before_product_totals', 'wapf_before_product_totals');
function wapf_before_product_totals($product) {
$product_ids = array(123,987,630);
if( ! in_array($product->get_id(), $product_ids) ) return;
?>
<div class="wapf_step_buttons">
<button class="button wapf_btn_prev" style="display:none"><?php _e('Previous','sw-wapf'); ?></button>
<button class="button wapf_btn_next"><?php _e('Next','sw-wapf'); ?></button>
</div>
<?php
}````

How to position output of gravity forms dynamic output?

I'm simply trying to use the value from a Gravity Forms dynamically populated URL parameter as the ID for getting a custom field from Advanced Custom Fields. Using it like this returns the result within the of the content.
What is the best way to hook this such that it appears below the form. I've tried inserting the filter into the page template itself to no avail.
<?php
add_filter('gform_field_value_subclass', 'my_custom_population_function');
function my_custom_population_function($value)
{
$repair = get_field('repair', $value);
$report = get_field('report', $value);
if ($repair && $report) : ?>
<section class="rrr">
<div class="row">
<div class="repair">
<div class="r-wrap">
<h2 class="bracket-heading"><span>Step 2:</span>Report</h2>
<?php echo $repair ?>
</div>
</div>
<div class="recognize">
<div class="r-wrap">
<h2 class="bracket-heading"><span>Step 1:</span>Immediate Action Steps</h2>
<?php echo $report; ?>
</div>
</div>
</div>
</section>
<?php endif;
} ?>
I actually realized that something didn't feel right after looking over the first 20 pages of Google and not seeing a reference to this use case. The filters in Gravity Forms are more suited towards dynamic population of other fields, not to set context for the site as a whole. At least that's what it appears.
I found the better solution to be using query_vars.
In functions.php, I made it so that the URL parameter called subclass can be queried from Wordpress itself.
<?php
// add `author_more` to query vars
add_filter( 'init', 'add_subclass_query_var' );
function add_subclass_query_var()
{
global $wp;
$wp->add_query_var( 'subclass' );
}
?>
And then in my page template file, I grab that value that I need to set the ID of the field from the URL using get_query_var().
The rest is pretty straightforward and just prints the field values out where I need them.
<?php
$value = get_query_var('subclass');
$repair = get_field('repair', $value);
$report = get_field('report', $value);
if ($repair && $report) : ?>
<section class="rrr">
<div class="row">
<div class="repair">
<div class="r-wrap">
<h2 class="bracket-heading"><span>Step 2:</span>Report</h2>
<?php echo $repair ?>
</div>
</div>
<div class="recognize">
<div class="r-wrap">
<h2 class="bracket-heading"><span>Step 1:</span>Immediate Action Steps</h2>
<?php echo $report; ?>
</div>
</div>
</div>
</section>
<?php else:
echo "No Results Found"
?>
<?php endif; ?>
https://codex.wordpress.org/WordPress_Query_Vars

Using a Shortcode within a Shortcode

A client is using WPBakery and a form is being pulled into the description attribute of a shortcode. Ordinarily you would pull the form by its shortcode but the boiler plate demo has the form being pulled with a string beginning with a hashtag.
E-8_JTVCbWM0d3BfZm9ybSUyMGlkJTNEJTIyNDc0JTIyJTVE
[trx_sc_title title_style="accent" title_align="left" link_style="default" title="Stay Tuned for Our Updates" subtitle="newsletter signup" description="#E-8_JTVCbWM0d3BfZm9ybSUyMGlkJTNEJTIyNDc0JTIyJTVE"]
is equivalent to:
[trx_sc_title title_style="accent" title_align="left" link_style="default" title="Stay Tuned for Our Updates" subtitle="newsletter signup" description="[mc4wp_form id="474"]"]
I need to pull a different form from ninjaforms( [ninja_form id=3] ) instead of the mailchimp form in the example. How do I convert the shortcode in the same manner they did?
Thanks in advance for any insight as to what is going on here.
use two shortcodes. so that it won't be complicated.
function kp_shortcode1($atts, $content = null)
{
ob_start();
?>
<div class="sc1-section">
<?php echo do_shortcode($content); ?>
</div>
<?php
$output = ob_get_clean();
return $output;
}
add_shortcode('kp_shortcode1', 'kp_shortcode1');
function kp_shortcode2($atts, $content = null)
{
ob_start();
?>
<div class="sc2-section">
<h1>shortcode 2 content</h1>
</div>
<?php
$output = ob_get_clean();
return $output;
}
add_shortcode('kp_shortcode2', 'kp_shortcode2');
Inside the wordpress backend use
[kp_shortcode1]
[kp_shortcode2]
[kp_shortcode2]
[kp_shortcode2]
[/kp_shortcode1]
Output would be :
<div class="sc1-section">
<div class="sc2-section">
<h1>shortcode 2 content</h1>
</div>
<div class="sc2-section">
<h1>shortcode 2 content</h1>
</div>
<div class="sc2-section">
<h1>shortcode 2 content</h1>
</div>
</div>

Wordpress - Nested shortcodes rendering

first of all I know which my problem is not at all related to the sage project but I know that your advanced wordpress knowledge can help me to get through that.
p.s. I've been creating my shortcodes upon sage scaffolding.
I built two shortcodes for nested using:
[outdoor]
[outdoor_item title="My title 1" color="orange"]<strong>The</strong> 1st Content[/outdoor]
[outdoor_item title="My title 2" color="blue"]<strong>The</strong> 2nd Content[/outdoor]
[outdoor_item title="My title 3" color="green"]<strong>The</strong> 3rd Content[/outdoor]
[outdoor_item title="My title 4" color="red"]<strong>The</strong> 4th Content[/outdoor]
[/outdoor]
After lots of hours searching something in stackoverflow and google I figured it out that I had to apply do_shortcode() in my RAW outdoor shortcontent content... something like this:
add_shortcode('outdoor', function($atts, $content, $tag) {
return '<div class="outdoor">' . do_shortcode($content) . '</div>';
});
and then my problem comes out... the function do_shortcode() renders ONLY my first outdoor_item and ignores every outdoor_item else. It outputs something like this:
<div class="outdoor">
<div class="outdoor-item" style="background-color: orange">
<h1>My title 1</h1>
<div class="outdoor-item-content">
<strong>The</strong> 1st Content
</div>
</div>
</div>
p.s. I've tried do_shortcode(), apply_filters('the_content', $content) and even call wp_reset_postdata() after each outdoor_item. What else could I try?
Recently I had similar issue.
I needed to wrap elements into the bootstrap table so the shortcode should be the following:
[table]
[fb_review href="" name="" date=""][/fb_review]
[fb_review href="" name="" date=""][/fb_review]
[fb_review href="" name="" date=""][/fb_review]
[fb_review href="" name="" date=""][/fb_review]
[fb_review href="" name="" date=""][/fb_review]
[/table]
and this should produce the following html:
<div class="row">
<div class="col-md-6"><div class="fb-review">Some content</div></div>
<div class="col-md-6"><div class="fb-review">Some content</div></div>
</div>
<div class="row">
<div class="col-md-6"><div class="fb-review">Some content</div></div>
<div class="col-md-6"><div class="fb-review">Some content</div></div>
</div>
<div class="row">
<div class="col-md-6"><div class="fb-review">Some content</div></div>
</div>
I looked for different ways how to handle this but then decided to parse the $content string by myself
here is the part of functions.php:
//this function just wraps the compiled nested shortcode elements
function responsive_table($attrs, $items = []) {
if (count($items) > 0) {
$result = '';
$counter = 0;
foreach ($items as $item) {
if (!($counter % 2)) {
$result .= '<div class="row">';
}
$result .= '<div class="col-md-6">' . $item . '</div>';
if ($counter % 2) {
$result .= '</div>';
}
$counter++;
}
if ($counter % 2) {
$result .= '</div>';
}
return $result;
} else {
return '';
}
}
// this function parses the content, fetches internal shortcodes, compiles them and passes to responsive_table
function responsive_table_for($attrs, $content=null) {
if ($content != null && $content != '') {
$content_matches = [];
preg_match_all('/\[.+?\[.+?\]/', $content, $content_matches); // TODO: this doesn't support nested shortcodes
$content_array = [];
foreach ($content_matches[0] as $item) {
$content_array[] = do_shortcode($item);
}
return responsive_table($attrs, $content_array);
} else {
return '';
}
}
add_shortcode('table', 'responsive_table_for');
Maybe this way is not the best but it works for me.

Add custom field for skype

For my website I use Advance Custom Field for Wordpress and now i'd like to create a custom field for skype call.
I create a custom field text for "skype" and I add this on my single.php
<?php if ( get_post_meta( get_the_ID(), 'skype', true ) ) : ?>
<p><span class="list">
<?php _e( 'Skype: '); ?>
</span>
<?php the_field('skype'); ?>
</p><?php endif; ?>
I try to add this
<a href="skype: yourskypeid?call">
<img src="http://cdn.dev.skype.com/uri/callbutton_32px.png"
alt="Skype Me™!" style="border: none;margin: 32px; vertical-align: -41px">
</a><br />
Get Skype and call me for free.<br />
to have a skype button to call but it doesn't work.
Can you help me please?
<script type="text/javascript" src="http://www.skypeassets.com/i/scom/js/skype-uri.js"></script>
<div id="SkypeButton_Call_prince_1">
<script type="text/javascript">
Skype.ui({
"name": "call",
"element": "SkypeButton_Call_YOURSKYPENAME_1",
"participants": ["YOURSKYPENAME"],
"imageSize": 32
});
</script>
</div>
For more See here Skype Call Button
also this should work..
Call Yourskypeid

Resources