Showing posts with label Word Press. Show all posts
Showing posts with label Word Press. Show all posts

Wednesday, February 11, 2015

Display submitted form data after redirecting to another page

http://support.themecatcher.net/quform-wordpress/guides/customization/display-submitted-form-data-after-redirecting-to-another-page


The submitted form data will be lost after redirecting, so we’ll use PHP sessions to save the data so that we can access it on the next page.

Step 1

Add the following code to the file wp-content/themes/YOUR_THEME/functions.php.
1
2
34
5
function mytheme_save_form_data($form)
{
    $_SESSION['iphorm_2'] = $form->getValues();}
add_action('iphorm_post_process_2', 'mytheme_save_form_data');
  • On lines 3 and 5, change the number 2 to your form ID

Step 2

We need to execute PHP code to print the saved variables on the page we redirect to. One way to be able to do this is to create a Page Template. To do this, copy the “page.php” file from your theme and call it template-thank-you.php
At the top of the file template-thank-you.php, after the opening PHP tag, add the comment below to register the page template with WordPress.
1
2
3
/**
 * Template Name: Thank You
 */
Remove the “loop” code from the file (see the Sample template-thank-you.php section below) and write your message HTML instead. You can print the submitted form data using the code below.
1
<?php echo $_SESSION['iphorm_2']['iphorm_2_1']; ?>
  • Replace iphorm_2_1 with the unique element ID of the element that you want to print the value for.
To print another value you can use the same code, just change the unique element ID.
Note: some form elements are not able to be printed directly as they return an array, see the Getting form values guide for the data types of all elements. You may need a PHP developer if you get stuck.

Step 3

Create or edit a page inside WordPress to be your destination page, on the right hand side at the Page Attributes box, for Template choose Thank You and save the page.

Step 4

Set up the form to redirect to this page by going to Form Builder → Settings → General → Successful submit options, at On successful submitchoose Redirect to another page, at Redirect to choose Page and select the destination page created in Step 3.

Sample template-thank-you.php

The following file was created by following the above guide on the TwentyTwelve theme, it will possibly not work with your theme, but it will show you how to modify the file. If you compare this to the default page.php file of the TwentyTwelve theme, you’ll be able to figure out what code to change.
<?php
/**
 * Template Name: Thank You
 */

get_header(); ?>

 <div id="primary" class="site-content">
  <div id="content" role="main">

   Thank you <?php echo $_SESSION['iphorm_2']['iphorm_2_1']; ?>, your message has been sent!

  </div><!-- #content -->
 </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Still having trouble? Head over to the forums.

Tuesday, February 3, 2015

Using the PHP Session in WordPress

WordPress and Sessions

The WordPress platform is totally stateless and provides no support for the use of sessions outside of the cookie that keeps a user logged in.  This is a very good policy and helps keep your blog light and responsive.  Unfortunately there are times that a session might be convenient to hold some data between requests.  If you search online and in the WordPress forums you will find a lot of discussion of this and a few ideas that point in the correct direction.  
The best of these is Frank Verhoeven’s blog Post on this topic which is short and sweet and contains the basic idea.  The comments on this are the real gold.  What I’m providing here is a summary of the facts I’ve found in those comments and much other online study and experimentation.

Getting access to the session if you are not writing a plugin or theme

The simplest way to get access to the session is to add the following lines to wp-config.php before the call to wp-settings:
if (!session_id())
    session_start();
This is what Frank suggested and it works well if you want to get the session for some of your own code and register_globals isn’t set.

What about register_globals?

You’ll hear a lot of talk about the deprecated PHP option register_globals in php.ini and WordPress’s attempts to defeat its use with the wp_unregister_globals function in load.php. WordPress is correct in doing this, so don’t just comment out wp_unregister_globals.
If register_globals is set WordPress will clear all the globals that it are set. Calling session_start will set the $_SESSION global, so if you call it before wp-settiings is run and register_globals is set you will lose your session variables. In most cases this isn’t a problem, but your hosting provider may have turned that option on and you can’t turn it off.
If that’s the case, you can’t put the session_start in wp-config.php. You will need to put it in your code before you need the session. And if you put it elsewhere be sure to remove it from wp-config.php or you will lose your session.

But of course It’s a plugin that needs a session

You can’t put your session_start in wp-config.php if you are intending to distribute your code to others, since you have no access to it and your users might have register_globals set.  In that case you need to hook into an action that takes place after WordPress is loaded but before your code needs the session.  
You can hook into the “init” action, to do that you would add some code like this to your plugin or your theme’s functions.php:
add_action('init', 'myStartSession', 1);
function myStartSession() {
    if(!session_id()) {
        session_start();
    }
}
This code starts the session early in the initialization process, the 1 is the priority to cause this to run before other initialization. The session will be available once this has run.

One last piece in the puzzle

But it’s still missing a crucial piece.  The data stored in the session doesn’t go away when the user logs out or logs into a different account. For that you need to destroy the session.  And of course that requires a couple more hooks.  This results in the following code to start and destroy the session:
add_action('init', 'myStartSession', 1);
add_action('wp_logout', 'myEndSession');
add_action('wp_login', 'myEndSession');

function myStartSession() {
    if(!session_id()) {
        session_start();
    }
}

function myEndSession() {
    session_destroy ();
}

Now the session is yours to use as you wish in your code

To save some data into the session
$_SESSION['myKey'] = "Some data I need later";
And to get that data out at a later time
if(isset($_SESSION['myKey'])) {
    $value = $_SESSION['myKey'];
} else {
    $value = '';
}
I hope this is of help to others who have faced this problem.

Wednesday, January 28, 2015

Word Press

About Word Press


Nice themes:

http://templatesnext.org/ispirit/landing/themes/

http://www.templatemonster.com/demo/53983.html

http://www.inkthemes.com/free-responsive-and-beautiful-wordpress-themes/

http://demo.themovation.com/?theme=pursuit

http://demo.themovation.com/eatery/

http://themeforest.net/item/simply-business-html-small-business-template/full_screen_preview/85300

http://kairaweb.com/themes/

http://demo.themeton.com/ammo/home/demo-2/

http://www.templatemonster.com/demo/44519.html

http://themeforest.net/item/tour-package-wordpress-traveltour-theme/5360508

http://demo.ufothemes.com/bonanza/

http://themeforest.net/item/tour-package-wordpress-traveltour-theme/5360508


http://www.willowcreekcarecenter.org/

http://binarycoders.com/es/portfolio/

http://freelancewp.com/wordpress-theme/agt-noname-ajax-wordpress-template/

http://themeforest.net/item/onevent-special-event-wordpress-theme/full_screen_preview/10227533

http://themeforest.net/item/awesome-one-page-business-portfolio-wordpress-theme/3831389

http://demo.puriwp.com/themes/?theme=Awesome

http://demo.agtheme.com/wpnoname/
$45.00

http://d5creation.com/theme/corporate/
$59.99

http://themeforest.net/category/wordpress/corporate


http://anpsthemes.com/constructo/
$53.00


http://www.deluxetemplates.net/

http://newbloggerthemes.com/faber-blogger-template/


http://silvermapleweb.com/using-the-php-session-in-wordpress/