data forward to search page instead of form action page - php

I have a newsletter form which forward the data to newsletter.php but search.php page open when click on submit my form html code is:
<form action="../newsletter.php" method="post">
<input type="text" class="field" placeholder="Your Name" name="name" />
<input type="text" class="field" placeholder="Email" name="email" />
<div class="form-buttons"><input type="submit" value="Submit" class="submit-btn" />
</div> </form>

You can check if your entire file don't have another declaration. Maybe you have another form opened, and this newsletter form is inside of the other one. This will always submit the parent form.
Look for a

Check if there is a redirect to search.php on your newsletter.php page.

Related

PHP Form Redirect to error link

Using HTML form with action = "www.google.com", but it redirect to link including localhost/www.google.com . My example code is for your reference. Please anyone help me.
My Forms as follows :
<form method="POST" action="www.google.com">
<p>
<label for="name">Name:</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">Email:</label>
<input type="email" name="email" id="email">
</p>
<p>
<label for="comments">Comments:</label>
<textarea name="comments" id="comments"></textarea>
</p>
<p>
<input type="submit" name="send" id="send" value="Send Comments">
</p>
</form>
But, the file when click send button, it redirects to
" http://localhost/basic/www.google.com" error page. Can any one suggest me to resolve the issue.
It is not allowed to send POST request directly to google.com. Why do you want to do this? In the action argument you should have own script which can process request from your form.
Replace your form action
From
action="www.google.com"
To actual link
action="https://www.google.com"

Form data not staying consistent, resetting after submit

This is hard to explain so bear with me.
I'm building a page that consists of multiple forms that are all submitted with one submit button at the bottom like so:
<form action="" method="post">
<input type="text" name="name1" value="<?$variable1;?>" placeholder="Type here...">
<form action="" method="post">
<input type="text" name="name2" value="<?$variable2;?>" placeholder="Type here...">
<form action="" method="post">
<input type="text" name="name3" value="<?$variable3;?>" placeholder="Type here...">
<form action="" method="post">
<input type="text" name="name4" value="<?$variable4;?>" placeholder="Type here...">
<input type="submit" name="submit" value="Submit">
</form>
Each of these forms asks the user for data, which then echos to a text box so that they can copy/paste the output.
Now, suppose the user fills out the data for one of these forms only and clicks on the submit button. Naturally, the data they entered would go to the text box. What I need however is that when the user then decides to fill out the rest of the forms, the data that was originally echoed is still in the text box, preferrably as well as the answer they put in the form (however not essential).
What I'm finding at the moment is that the form resets after clicking submit, so even though the user has submitted one part of the form, when they go to fill out the rest and click submit again, only the other 3 are echoed and the first one is omitted.
I hope this makes sense. Any idea on how one would go about this?
EDIT: Nearly got it with the following:
if (isset($_POST['submit'])) {
if (isset($_SESSION['test1'])) {
$_SESSION['test1']=$_SESSION['test1'];
}
else {
$_SESSION['test1'] = $_POST['test1'];
}
}
However the variable now doesn't change when we enter something new into the form field...
<form action="" method="post">
<input type="text" name="name1" value="<?$variable1;?>" placeholder="Type here...">
<input type="text" name="name2" value="<?$variable2;?>" placeholder="Type here...">
<input type="text" name="name3" value="<?$variable3;?>" placeholder="Type here...">
<input type="text" name="name4" value="<?$variable4;?>" placeholder="Type here...">
<input type="submit" name="submit" value="Submit">
</form>
Call only once. One submit button is for 1 form. Please try this. It should work
You need <?= $variable1; ?> etc. Otherwise it doesn't output anything.

PHP Form to redirect with form results

I have a form that when they submit it, it stores the info in the database. I need to be able to get the form data to come up on redirect page.
It does not need to fetch the database as I would love to do this PHP style. So lets say they enter there name and city. When they click submit it redirects them to a thank-you page with the results from the form on that page.
In a form, you have each element have a name, lets say name="username", in the php, yould get the value of this as either a get, or a post response, depending on the method of the form.
HTML Form
<form action="process.php" method="get">
<input name="username" type="text"></input>
<input type="submit" value="Submit"></input>
</form>
or
<form action="process.php" method="post">
<input name="username" type="text"></input>
<input type="submit" value="Submit"></input>
</form>
process.php
$someusername = $_GET['username'];
$someusername = $_POST['username'];
Form page:
<form action="thanks.php" method="post"><input type="text" name="myname" placeholder="Name" /><input type="text" name="mycity" placeholder="City" /><input type="submit" value="submit"></form>
PHP Page
print "Thanks, ".$_POST['myname']." who lives in ".$_POST['mycity']."!";

How to submit a form to destination url as destination site

I need to submit a form with action is:"http://www.destination.com/hotelbooking" as "http://www.destination.com" but I do not own that site.
My site is http://www.mysite.com, after the submitting, url in my browser is "http://www.mysite.com/bookingstatus" instead of "http://www.destination.com/bookingstatus".
I guess that the site force me to submit my form from a browser because if I use curl, it doesn't worked(but I need to do that with php).(*My edit)
How can I solve this problem?
This is my form:
<form name="booking" method="post" action="https://www.destination.com/hotelbooking" >
<input name="roomsnum" type="text">
<input name="adultnum" type="text">
<input name="childnum" type="text">
<input name="infannum" type="text">
<input name="roomsize" type="text">
<input name="submit" type="submit" value="booking">
</form>
Thanks a lot

Why can't Code Igniter detect that my form is being submitted via POST?

I have a form in a Code Igniter view in my jQuery Mobile application.
<form action="<?= BASE_PAGE_URL ?>settings" method="post" id="settingsForm">
<div data-role="fieldcontain">
<label for="firstName">First Name</label>
<input type="text" name="firstName" id="firstName" value="" placeholder="First Name" />
</div>
<div data-role="fieldcontain">
<label for="lastName">Last Name</label>
<input type="text" name="lastName" id="lastName" value="" placeholder="Last Name" />
</div>
<input type="hidden" name="purpose" value="register" />
<input type="submit" name="submit" value="Register" />
</form>
However, when I write this code into the controller method that the URL specified by action leads to:
echo ($_SERVER['REQUEST_METHOD'] == 'POST') ? "yay" : "nay";
"nay" is written to the page when I hit the submit button. How come Code Igniter cannot tell that I am submitting a post request?
If you want to determine if you have POST data or if request was a POST, use post() method from the input class
$this->input->post(index);
//returns FALSE if no POST data
//returns the POST array if there is data (hence, a POST)
//returns a specific data from the array if you provide "index"
It can be cause of register_globals. Use
if($_POST)
OR CI input class
$this->input->post('var');
I wonder if your form is returning a post request as you expect, but that something is redirecting immediately afterwards, which you're seeing as a GET? Try putting a temporary exit() immediately into the form-handling action; I suspect that will come out as POST.

Categories