How to pass data between wordpress pages - wordpress

I am new to wordpress and i want to transfer data from one page to another in wordpress. I used php to post my form data to a wordpress page. My code is:
<form method='post' action='http://www.example.com/www/create_website/'>
.....
<input type ='submit' value = 'OK'/>
</form>
But every time i clicked the submit button i got error page not found. Why it is so because link is loading the page in browser but not working for form post. How can i solve the issue???

Having spent about a day figuring out how to do this, I thought it might be helpful to others in the stackoverflow community.
GOAL: To take the results from a form field and use it on another page.
In this example, my client wanted users to be able to fill in any amount in a text field to make a Paypal payment. I'm using S2Member plugin to create buttons and hook up the Paypal payments, but they did not offer this functionality --only buttons with hard wired amounts.
You can see this in action here:
http://virginiabloom.com/?page_id=250 . But it is LIVE. If you start a paypal payment, it WILL deduct money from your account. Which will make Virginia very happy.
HOW I SOLVED IT:
First, I created a form just for this field.
Enter Other Payment Amount $
Next, I found a very simple plugin on stackoverflow and adapted it to my needs:
<?php
/*
Plugin name: redirect on post
Desciption:
http://stackoverflow.com/questions/13686245/how-to-create-a-custom-url-based-on-dropdown-in-wordpress-form-submission
I-changed-dropdown-to-field-input
*/
function redirect_on_submit() {
// check if the post is set
if (isset($_POST['amount']) && ! empty ($_POST['amount']))
{
header( "Location: yourUrl.com/?
page_id=542&amount=" . $_POST['amount'] );
}
}
add_action('init', redirect_on_submit);
NOTE: Change the page URL and ID information in the header to point to the Wordpress page you want to send the information to.
If you don't know how to manually install a plugin, its very simple.
Save the snippet as a .php file. Open up your hosting account and find the plugins folder (its in the wp-content folder) Copy the file into the folder.
Go back to Wordpress and look at your plugins. You should see it there. If its not activated, the activate it.
I installed another plugin:
Allow PHP in Posts and Pages (Version 3.0.4)
After installing it, the plugin will appear on the Wordpress menu.
Open it and you can use their snippet maker that will put php into your post inside a short code.
Configuration:
Show the snippet not found message: yes (for debugging)
Use the old (pre.2.2 code: no
Use the advanced filter method: yes
Remove all plugin data on install: no
You should see the code snippet box appear at the bottom of the page.
My snippet was simple. I just wanted to echo the "amount" parameter from the page url. So it looked like this:
echo $_GET['amount']?>
Note that you have to put the ending php tag, but not the beginning tag.
Now, you just use the shortcode [php function=1] on the page wherever you want to get this parameter.
Here's what it looks like on MY results page.
<h2>Payment of $ [php function=1]</h2>
<strong><em>Click Paypal button to start payment or cancel.</em></strong>
[s2Member-PayPal-Button sp="1" ids="xxx" exp="24" desc="Payment" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="yoururl.com"
ra="[php function=1]" image="default" output="button" /]
To make sure that users can only enter in decimal numbers, I used jQuery validation on the form. There are other ways to do it, but this was very simple. Just put this code on the page with the form which I've included below.
<form id="myform" action="http://virginiabloom.com/?page_id=542" method="post"><span style="font-size:1.5em;">Enter Other Payment Amount $</span><input id="amount" class="left" name="amount" type="text" /><input type="submit" value="Submit" /></form>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
$( "#myform" ).validate({
rules: {
amount: {
required: false,
number: true
}
}
});
</script>
That's it! I hope this helps somebody.

If you need to go to one of your WordPress page, please don't put the direct link in action.
Instead of that put the below php code.
<form method='post' action='<?php bloginfo('url'); ?>/your-page-name/' >
If you wants to go to a particular file inside your template directory put the below code
<form method='post' action='<?php bloginfo('template_url'); ?>/your-page.php' >
Check this WordPress codex page for more about bloginfo.
<?php bloginfo('url'); ?>
will generate the base site url.

Related

Woocommerce move notices on account login page

Woocommerce outpuits a number of error/info notices on multiple pages. Normally this is handles by <? wc_print_notices() ?>, and so is nice and easy to reposition within a custom template. However, on the woocommerce account login page (form-login.php), there is no reference to <? wc_print_notices() ?> and therefore I cannot reposition. How are they automatically being output, and is there a way to overide them?
error, success and notice html file exist in templates/notices and include by some function, filter and action. for example woocommerce_before_customer_login_form action for login form.

Issue with Wordpress Contact Form 7 Plugin - Dynamic Text Extension

I use the Contact Form 7 plugin for contact forms on our site. I am using this on a WP installation with multiple sites. We have employment application forms on each site, and to identify the site when we do a REST call to our webapp, I would like to include the site_id (or blog_id, I'm unclear on which is the right name) so it can be used to reference the WP site in the other app. I installed the Dynamic Text Extension for this particular task, and this is my first attempt, based on the help docs, to add a hidden field with the blog_id:
[dynamichidden blog_id id:blog_id "CF7_bloginfo value='blog_id'"]
and end up with this:
<input name="dynamichidden-927" value="Elite Trade Painting Calgary" size="40" class="wpcf7-form-control wpcf7dtx-dynamictext wpcf7-dynamichidden" id="blog_id" aria-invalid="false" data-hasqtip="true" type="hidden">
I should note that no matter what I put in the tag, the same value comes up. I know I am editing the right form because if I delete the tag, it disappears completely – but no matter what I change, it always has the wrong value.
https://elitetradepainting.com/calgary/employment-opportunities/
My mistake was looking at the wrong page and thinking that bloginfo() returns the blog id - it doesn't. The DTX developer answered my question in WP forums and advised me to use a shortcode, so I wrote a callback that uses get_current_blog_id:
in functions.php:
function get_blog_id_callback() {
return get_current_blog_id();
}
add_shortcode('get_blog_id', 'get_blog_id_callback');
Then the snippet for the control in the Edit Contact Form page is as simple as:
[dynamichidden blog_id "get_blog_id"]

Wordpress static Form on any page - Plugin, Widget or Shortcode?

I am frankly new to wordpress but programm in PHP.
Task:
I have a form (don't wanna use a form plugin) and want to include this form on either 1. Sidebar or 2. within content of any Page except one (Contact-page).
I want to programm the Widget, Shortcode or Plugin bymyself. I don't need a tutorial how to programm this.
Question:
What do you advise me to use: a shortcode, plugin, widget or a "hack" in the template (f.e. if ($page!=="contact"){...}
The answer should consider
Ease and flexibility of use
Short time to develop
Speed of Rendering
Thanks for advise of experienced Wordpress Users/Developpers.
PS: the form is very simple maybe there is even another fast way you know how to do this.
Try This
1)first to fall you make a page templates of contact page.(make copy of page.php than only change the name of templates)
2)than that template in you make your custom form.
3)that page template you apply in your contact page.
Make a template-myForm.php file, and populate it with following:
<?php
/**
* Template for displaying search forms for My Web Site
*
*/
?>
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<!-- your form content-->
</form>
Add to site <?php get_template_part( 'template', 'myForm' ); ?> where you want a custom search form. I used it for search form, so it was easy to make it into widget also. I used separate template file for site search, and searcform.php for search widget. If you are aiming at different kind of form tag, you have to create that a Widget.
It is a class Your_Widget extends WP_Widget, which for you can find tutorials on your own, or just check out PHP code file: wp-includes/class-wp-widget.php in your Wordpress copy and extend it. Me personally use tutorials. I find it more simple.
So, to summ up, you would have two copies of your form - one to show as a template part, and an another one for sidebar or other registered widget area. If it is identicall in both versions, using this solution you would have to remember to keep changing it in two places (which is again simpler than hard-coding).
For me beeing not a native English speaker and just a part time Wordpress coder, this is what I offer. More integrated and PHP-programming-friendly solution, find in Wordpress forums, here on stackoverflow and Wordpress.org site.
I also am aware this is not exactly what you are looking for - not using shortcode. I hope this will kick you off into Wordpress world, and you will find how to offer a custom form to your users!
Good luck!

Wordpress E-mail before displaying content

So, I have a lot of posts with custom content. Some of this content is hidden, for example prices. I want the prices to be visible after the user submits an e-mailaddress. But it has to be remembered via cookies.
I first tried to make user registrations with e-mailaddress only, but that's not what I want and is not very safe.
Then I wanted to try Email Before Download plugin, but that's not gonna work either. That gives me 1 link or 1 text per contactform (it uses contactform 7).
Is there a plugin for this?
Edit Maybe it's a better idea to use Sessions. I now have:
<input type="email" placeholder="E-mailadres" name="email" />
Then I made a session:
<?php
if(isset($_POST['email'])){
$_SESSION['user_email_set'] = true;
}
if(isset($_SESSION['user_email_set']) && $_SESSION['user_email_set']){
echo "Sessions made :)";
}
?>
But, when I refresh the page or go to another page, the sessions is lost. What did I do wrong?

Wordpress' Contact Form 7 returns 404 but works on homepage

I've installed Contact Form 7 (v 3.1.1) into Wordpress (v 3.3.1). It works fine on the homepage (which is a static Page called 'Home') but on any other page it does nothing and the console says:
POST http://trademarkshop.ca/contact/ 404 (Not Found)
I'm using do_shortcode to call it from both theme files:
<?php echo do_shortcode('[contact-form-7 id="212" title="Contact form"]'); ?>
I have wp_footer() in the footer and wp_head() in the header. I have no other plugins installed. I've even checked for if(is_home()) restrictions. I also tried re-directing other pages to use the Home page template file, but still gives a 404 error.
I've never had this problem before. Any ideas would be very appreciated!
have you tried changing your permalinks to something else,
then save,
then change it back to /%postname%/
could be its not creating the htaccess file in the wp root,
hence your permalinks arent working,
Marty
use this code
<?php echo do_shortcode( '[contact-form-7 id="7" title="Contact"]' ); ?>
His problem is caused by a combination of two misconfigurations. First, AJAX JavaScript is not functioning on your contact form. Due to this problem, your contact form needlessly redirects after submission. Second, your contact form uses unavailable words in the names of input fields. This issue confuses WordPress, resulting in the 404 (“Not Found”) error.
https://contactform7.com/faq/my-contact-form-always-redirects-to-404-error-page-after-submission/
Change your Contact form 7 field names. Because some names already using by wordpress may be is conflicting.
Example:
name to username
Sometime that happen cause the code (id) in de form (When you try editing the error message on the left side there is a short html like code on witch there is an id) is not the same as the one when you go to dashboard>contact and the short code entry of the table. You need to change the first one to match the second one

Resources