Wordpress search form not passing get variables - wordpress

I have an issue where I am creating a simple custom search form in Wordpress 3.4 sitting in a template file.
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>">
<input type="text" value="" name="s" id="s" />
<input type="hidden" name="search-type" value="vacancies" />
<input name="submit" type="submit" value="Go" />
</form>
Upon submitting it hits a search.php file where further processing takes place.
<?php print_r($_GET); ?>
The problem is that I cannot access the get variables in search.php. I can echo here so I know I'm definitely hitting search.php but my get array is empty every time.
Any ideas would be a big help. I feel I may be making a rookie mistake...

I was having this problem too. The theme I am using (Roots) does some fancy rewriting of the search page URLs. So, searching for "french holiday" will be site.com/search/french+holiday instead of site.com/?s=french+holiday.
If you can't see the variable in the URL, you won't be able to access it using $_GET.
I changed back to the standard URLs and can now access my $_GET values.
Hope that helps.

Related

get_permalink() don't work as form action attribute

Trying to make sign up form using Wordpress.
The register -page is "page-register". So the link is supposed to point to itself.
This worked earlier without WP and with MAMP but can't get this work with wordpress and LocalWP.
<form action="<?php echo get_permalink('register'); ?>" method="post">
This go to 404 page. The permalink works as hyperlink but not as the form action attribute.
I also tried site_url() and get_page_link().
Solved. The problem was not in the form action, but in the form input name. So I changed this:
<input type="text" name="name">
to this:
<input type="text" name="uname">

Wordpress search form by category not working?

Objective
I am trying to create different search forms for two different landing pages. Thus, users who end up on landing page A will only be able to search for products with categories Man and Book. Users landing on page B will only be able to search for products with categories Beast and Funny.
Here is my example setup in WooCommerce.
What I have tried
Based on this link, I have tried the following search function for page A.
<form role="search" method="get" id="searchform" action="https://test.com/">
<div>
<label for="s">Search for (Man and Book):</label>
<input type="text" value="" name="s" id="s" />
<input type="hidden" value="1" name="sentence" />
<input type="hidden" value="product" name="post_type" />
<input type="hidden" value="product_cat" name="man,book" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
Problem
If I key in GetAllX into the search form, I expect to see GetAllX (Copy 2) only. Instead, I see GetAllX (Copy 2) and GetAllX.
Also, when I key in test, I expect to see Test product 2 only. Instead, I see both Test product 2 and Test Product.
Questions
Why is WordPress behaving like this? Can someone help me out with this, please?
If there is an easier way to create search forms for different product categories based on landing pages, please do let me know.
Found the error. It was in this line:
<input type="hidden" value="product_cat" name="man,book" />
It should be instead:
<input type="hidden" value="man,book" name="product_cat" />
There was a typo in the article I linked to.

How to pass custom amount with Bitpay hosted checkout form?

I am looking to integrate BitPay for processing bitcoin payments on one of my sites.
Their hosted checkout form (similar to PayPal checkout form) is easy to integrate however I don't know how I can pass order amount with the form so that the same checkout button can be used for different orders (payments).
Here's their page regarding hosted checkout: https://bitpay.com/help-hosted-checkout
Bitpay has clearly stated that we can pass different order amount but they have not provided any field for this on the above mentioned page. I have contacted them and they will reply in 3 days but since I need to integrate this at the earliest, I hope somebody here can help me fast.
Thanks.
I was also looking for help with a bitpay button for a project and found this question (and another one like it), so coming back to answer in case it can help others in the future: If you got your bitpay button code from the payment button option on bitpay, your code might look something like this:
<form action="https://test.bitpay.com/checkout" method="post">
<input type="hidden" name="action" value="checkout" />
<input type="hidden" name="posData" value="" />
<input type="hidden" name="price" value="<?php echo $price_var;?>" />
<input type="hidden" name="data" value="...(your data value)..." />
<input name="checkout" type="submit" value="Checkout" class="form-button-submit button"/>
</form>
Having the line of code with 'name="price"' allows you to set a global variable (potentially your shopping cart total) as an order amount. Hope this helps!

Analytic funnelling, tracking two URLs with different parameters, both being triggered as the same URL.

I want to be able to track goals but I need to know whether they came from a page with a social media parameter or a digital marketing parameter in the URL.
I currently have subscription form which returns a URL with a specific parameter depending on which page we're on. We're using wordpress.
<?php if(is_page( 'internet-marketing-software')): ?>
<div class="free-trial" style="display:none;">
<div class="sign-up-button" style="/* display:none; */">
<form name="signup" id="signup" action="http://dmtrk.net/signup.ashx" method="post" onsubmit="return validate_signup(this)">
<input type="hidden" name="addressbookid" value="1922561">
<input type="hidden" name="userid" value="52978">
<input type="hidden" name="ReturnURL" value="http://test-site.com/?signup=false&step2=true&digital-marketing=true&form=form-banner">
<input id="input" type="text" name="Email" placeholder="name#email.com">
<input type="hidden" id="double" name="double" value="double">
<input id="submit" class="banner" type="Submit" name="Submit" value="sign up">
</form>
</div>
<div class='trial-desc'>
<p>Interested? <span>Start 30 day FREE trial now!</span>
</p>
</div>
</div>
<?php endif; ?>
I load a similar piece of code in the header this time with the condition
if(is_page( 'social-media'))
and which returns the url
http://test-site.com/?signup=false&step2=true&social-media=true&form=form-banner.
I so depending on the page each user gets taken to either the social-media or digital-marketing page.
When this URL us triggered a double opt-in email is sent with a link taking them to the true goal page http://test-site.com/?signup=true.
In Google Analytics I have set up two goals with the funnelling capability turned on.
I currently have the destination setup as:
RegEx /?signup=true
Funnelling On
Step &digital-marketing=true
And then for social:
RegEx /?signup=true
Funnelling On
Step &social-media=true
Looking at my reports each time a goal is triggered, no matter which URL was used they both register as a goal.
I'm not sure what I'm doing wrong, is there something I'm overlooking with Analytics and URL parameters?
To follow up on the comments (I cannot comment) - You should mark the previous page (coming from digital marketing or social) as "required step" to make sure that the goal will register in one of the paths, and not both. See the button on the right.

Wordpress- Two forms in contact us page

I have two forms in wordpress contact us page.
One form use simple mail() and the other uses mail() with attachment.
I have to process these forms in a single page.
I'm using inner.php (wordpress) to process forms.
I can process multiple forms from different pages, but I'm unable to process forms from the same page. How can I do this.
Any help will be appreciated. Thanks in advance...
I know that the way most people treat multiple forms on one page is to have each form post to another PHP file where the form is validated, its information is entered into a database or an email is sent off. So you usually have something like this:
<form name="contactform" method="post" action="sendmail.php">
blah blah blah
</form>
<form name="mailinglist" method="post" action="join.php">
blah blah blah
</form>
That work great, but why would you create all those extra files when you can just have the form post to the same file and create multiple functions to process your multiple forms.
The solution is very simple and super efficient.
First, lets create some forms.
<form name="mailinglist" method="post">
<input type="text" name="email" />
<input type="submit" name="mailing-submit" value="Join Our Mailing List" />
</form>
<form name="contactus" method="post">
<input type="text" name="email" />
<input type="text" name="subjet" />
<textarea name="message"></textarea>
<input type="submit" name="contact-submit" value="Send Email" />
</form>
Now lets put some PHP code before the tag to have different processes for each form.
<?php
if (!empty($_POST['mailing-submit'])) {
//do something here;
}
if (!empty($_POST['contact-submit'])) {
//do something here;
}
?>
Now all you need to do is create your processes within those two “if” statements and each form will be dealt with accordingly when it it filled and submitted.
This will help you.

Resources