Contact-Form 7 reloads page instead of doing AJAX - php

I am having my first go at converting a HTML template to a custom WP theme, so far everything is working out quite well and it's a very nice learning process..
I am using Advanced Custom Fields with Advanced Custom Fields: Contact Form 7 plugin. And set it to display in the following way:
<?php echo do_shortcode( '[contact-form-7 id="135" title="contactform"]' ); ?>
Everything is displaying the way it should, however when I press submit (if filled) it seems to reload the page while adding the following to the URL:
/?_wpcf7=135&_wpcf7_version=5.1.6&_wpcf7_locale=da_DK&_wpcf7_unit_tag=wpcf7-f135-o1&_wpcf7_container_post=0&your-name&your-email&your-phone
If it's not filled it just reloads the page.
This indicates that something doesn't work the way it should, since CF7 normally comes with error (if not filled) or a success message (if filled).
Hope someone can figure this one out.
UPDATE
I managed to it from reloading, the reason was that the php statement was wrapped in
<form></form>
However now it doesn't submit, I am only left with a loading icon which turns around. I looked into what the error might be and got the following:
Error
UPDATE - PROBLEM IS MAYBE FIXED
So after looking up solutions I found out that having permalinks settings on postname instead of normal caused the error. I am running a local install however I am not sure how it will react when it comes lives. Anyone who has a solution or knows whats causing this?

Related

Use formvalidation on entire form after page reload from submit

I'm coding some basic validation (mainly for aesthetic purposes, will do the main stuff in PHP) with formvalidation, and I've noticed a big problem in that once I hit submit, if it goes back to the same page, all the fields are no longer validated. I've tried a couple of lines of code from googling the problem, but none seemed to work.
Here is one line that seems to run on the datepicker alright when you use it, but if I just stick it out in the option for the document ready function (I just use trial and error with jquery), it does nothing.
$('#main_form').formValidation('revalidateField', 'pcn');
From here I tried this:
$('#main_form').validate().form();
But for some reason the entire validation breaks when I use that.
Here is a jsfiddle using the jquery code I'm using, what I basically want is it to instantly say that the field is required when you hit run.
Alternatively, can I set it to default to a certain message? That way I have PHP validate it on page load.
Finally got it working after a lot of trial and error. It turned out to be quite a simple fix, but needed to be in the correct place.
Add this line below all the validation code:
$('#form_id').formValidation('validate');
I'm hiding it behind if(isset($_POST['submit'])), so it'll revalidate the form on submit, but not validate when you first load.

Woocommerce showing "NULL" when completing orders manually

I've recently found that since I've installed this plugin (http://codecanyon.net/item/license-manager-for-woocommerce/5089794) whenever I try to manually change the status of an order (switching from processing to completed or the other way back) it loads a blank page when it just shows: NULL.
The strange thing is that if I back to the Order page and reload it, the status changes.
Another hint may be for example that the url when I arrive at the blank page with the "NULL" written in it, is something like this:
wp-admin/edit.php?s=&post_status=all&post_type=shop_order&_wpnonce=2d037c85cf&_wp_http_referer=%2Fwp-admin%2Fedit.php%3Fpost_type%3Dshop_order&action=mark_processing&m=0&_customer_user=&paged=1&mode=list&post%5B%5D=1117&action2=-1
What I can see there (and I might be wrong), is that after the _wpnonce appears a redirect with wrong values :S
Anything could help me? I'm kinda lost and I can't figure out where does this error comes from or make it right.
If I disable the plugin, everythings goes alright.
Greetings!

How can I capture a form textarea value in WordPress and insert into mysql?

I see all sorts of people asking this but no solid answers. I want to take text from a textarea form where users can enter their bio and then insert it into the bio field in mysql. This might be fairly easy normally, but alas, it seems nearly impossible with WordPress. I have to use the "Php for posts and pages" plugin and for some reason, the php script I have cannot be found (404 error) no matter where I place it. Then I thought I would try to just make the form and php all on one WordPress page, but it apparently can't be done like on a normal php web page. Anyone have any experience doing this? Any approaches that are known to work?
You can make form using normal php and insert it into mysql.
You can do this by making page template in wordpress.
http://codex.wordpress.org/Page_Templates
I've went through the same process! :)
My solution was:
Installing a PHP insertor plugin (specifically this). It's lot easier than creating a template.
I used it like this (inserted into the post's source):
[insert_php] include('myphpfile.php'); [/insert_php]
Then the included PHP's contents will be processed and printed out inside the page's body (the article's main part), so you don't have to create the html, head and body tags.
Then came the problem with posting form data to a page like this. This was because some of my form's fields kinda conflicted with WP's variables.
Some of the conflicting field names I've noticed: info, name
Just have a look at your form' field names and replace them to something else, and everything will be fine! :)
PS.: It's possible to put the form and the form data "receiver" in the same PHP script. I've done so and it worked in this scenario.
PS. 2: Optionally, you can disable the annoying auto-paragraph-insertor wpautop stock WP plugin, as it's affecting the included PHP's output. There is a per-post wpautop disabler plugin: Toggle wpautop

WordPress $_POST variables disappear completely on form submission

I have created a page template in WordPress to display a form with action="". Very simply, it will not post any of the form data upon submission. I have tried var_dump($_POST) but it just gives me array(0) {} every single time. I've tried examples provided by some websites for creating a form, but I can't reproduce the same results.
I have thoroughly search for answers to this problem but nothing seems to work. It must be something internal or very advanced. I just want to know why my form data won't post and where it might be going.
Check your data using a non-WP page, meaning put a php file in web-root, and have the form action point to it, such as ...action="/formtest.php", and on that page:
<?php
var_dump($_POST);
?>
This will test if you really aren't getting the POST vars. Then, since you'll 99% likely find they ARE being posted, the likely trouble is that your page IS being redirected somewhere by the theme as mentioned elsewhere (e.g. my theme includes a hook on 'template_redirect'...).
If you are theme savvy and just looking for a quick fix- at the expense of losing it on theme upgrade- you can create an exception just for your temp.php page, but the way that many developers handle it is via Plugins, or handle your form via Ajax. Many others have encountered this same issue, and so, either tacking on code to a Plugin, or performing in-page Ajax (since you are submitting to SELF anyway...).
This page will give you a leg-up on WP Ajax, it's a reputable and well written doc.

wordpress meta box\custom fields validation

I am trying to validate custom meta box fields. On the server side I tried to use "return false" on the "save_post" action, but WP disregards it (apparently the save_post is called after the post is already inserted to the DB).
I then resorted to JQuery on the client-side, but using "return false" froze the page, and it stopped responding, as if I was using an infinite loop.
the code is plain and simple:
$("#post").submit(function(){
if ($("input[name='post_title']").val()==='') {return false;};
});
Any ideas? Maybe built-in WP functionality?
The WordPress SE site has some good stuff on this topic..
Server side validation is obviously preferable.. can't rely on javascript.
This topic has a good discussion on how WP lets you handle errors.
I haven't tried implementing anything like this on meta boxes, so I can't say for sure it'll solve your problem, but hopefully it will put you on the right track.

Categories