Wordpress- Two forms in contact us page - wordpress

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.

Related

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.

Send HTTP POST to another website from my site

I am trying to send http post request from my site to another site
This is the detail i have the action page i have but its not below
POST COMMENT;
name=user&pass=password&form_build_id=form-od3MFMsKIL_5vCQtPmiv0AVf0tFwBuWj6iW7eP2-8&form_id=user_login_block&op=Log+in
Then on my site
I placed a html code:
<form action="http://sitename.com" method="post">
<input name="user" pass="pass" form_build_id="form-od3MFMsKIL_5vCQtPmiv0AVf0tFwBuWj6iW7eP2-8" form_id="user_login_block&op=Log+in" />
<input type="submit" />
</form>
Then when i send submit it goes to the login page but it doesnt fill in the user and pass.
Can someone tell me what im doing wrong.
You're misusing <input> tags.
You need to have a separate <input> tag for each value in the POST:
<input name="name" value="user" />
...

Wordpress search form not passing get variables

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.

Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?

I found this article on MSDN talking about Cross-page posting.
I never worked with Page.PreviousPage. But I think its interesting.
Do you use it? Is it a good pratice, or a bad idea?
What do you think about?
Thanks.
The cross page posting is a helper to post some data to a different page and still have the asp.net code behind functionality.
Why is this exist ? because asp.net have a limitation of one and only form per page. But actually to an html page you can have many forms and many different post to different pages.
So to give a tool to that case, is let you set a second page to post the data, and you setup this on the Button (and not by placing second form), and from there is solve this issue, to post the data to a different page.
For example... with out asp.net and with simple html on a page you can do that.
<body>
<form method="post" action="samepage.html">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
<form method="post" action="page_b.html">
email for news letter: <input type="text" name="email" />
<input type="submit" value="Submit" />
</form>
</body>
To solve a situation like this, and because asp.net not allow two forms at the same page, gives this option.
<body>
<form id="form1" runat="server">
Username: <asp:TextBox runat="server" ID="Name" />
<asp:Button runat="server"/>
email for news letter: <asp:TextBox runat="server" ID="email" />
<asp:Button runat="server" PostBackUrl="page_b.aspx" />
</form>
</body>
In the second case, you have one form, but you set the PostBackUrl to a different page, and from there asp.net still handle the data on code behind direct on a second page (with out redirect).
I hope this example gives you and an idea where to really use the previous page. Also what is more usually is the Redirect, how ever there are case that you need to have the result to a different page. So its per case if you use it or not.

Posting data to ASP.NET application

I have an application into which I wish to allow users to enter login details for their own websites. One of authentication methods is 'forms'. The way I had envisaged it working, is the users entering the method & action of their login form, and the name/value for each credential item, e.g. one for username, one for password. My application would then post this data in order to simulate a login, get the returned authentication cookie and be able to work on their site as if logged in.
In principle, this sounded like a reasonable kind of thing to do. However, as I'm sure you're aware, ASP.NET has a lot of inputs, and also hidden ones, e.g. __VIEWSTATE, which are all always posted back to the server whenever the ASP.NET form is submitted e.g. when a real user logs in. When my app tries to login however, it doesn't have the full list of inputs on that page, and their values, e.g. the always changing __VIEWSTATE.
My question: is there a way to post data to an ASPX page, posting only certain inputs, and excluding others, e.g. __VIEWSTATE?
If the page were, say, PHP it would probably look like this:
Ex. 1:
...
<div id="header">
<form action="search.php" action="POST">
<div id="search">
<input type="text" name="query" id="SearchQueryText" value="Search query" />
<input type="button" name=submit" id="SearchSubmitButton" value="Search!" />
</div>
</form>
<form action="login.php" action="POST">
<input type="text" name="uname" id="Username" value="Username" />
<input type="text" name="passwd" id="Password" value="Password" />
<input type="button" name=submit" id="LoginSubmitButton" value="Login" />
</form>
...
</div>
...
in ASP.NET Web Forms, however, through the use of server controls, it'd probably look like:
Ex. 2:
...
<body>
<form name="AspNetForm" method="post" action="/Products/SomethingOrOther.aspx" id="Form" enctype="multipart/form-data">
<div id="header">
<div id="search">
<input type="text id="ctl00$SearchComponent$SearchBox" name="ctl00$SearchComponent$SearchBox" value="Search query" />
<input type="submit" id="ctl00$SearchComponent$SearchSubmit" name="ctl00$SearchComponent$SearchSubmit" value="Search!">
</div>
<div id="login">
<input type="text id="ctl00$LoginComponent$Username" name="ctl00$LoginComponent$Username" value="Username" />
<input type="text" id="ctl00$LoginComponent$Password" name="ctl00$LoginComponent$Password" value="Password">
<input type="submit" id="ctl00$LoginComponent$LoginSubmit" name="ctl00$LoginComponent$LoginSubmit" value="Login">
</div>
</div>
...
</form>
</body>
...
With example 1, submitting the login form is a simple case of POSTing uname=something&passwd=somethingelse to login.php, however, in ASP.NET, because all inputs are wrapped in a 'global' <form>, to submit the login inputs, you have to submit the global form, and therefore all the inputs.
So what I'm after, is a way to submit only certain inputs in that global form, e.g. not __VIEWSTATE, which we can't know without probing the page beforehand.
You can use AJAX to post back the values to a specific page. In general, Web Forms is designed to post back all data on the page when you trigger a server side event. You then choose which elements/values to use in your code. If you don't want to use view state on a element, you can disable it (e.g. EnableViewState=False).
You can use asp.net page same as asp classic.
In html action you can put the aspx page from and then you have to take that.
then you can use request object of asp.net to retrive data from form. Same you can create a html form in string and put that via putting it into panel control.
Then you can asp.net button as submit button.

Resources