Send form results to another page php mysql - php

Hello I have a form working properly using
php echo $_SERVER['PHP_SELF']
The results are shown on same page as form.
I need to be able to send the form data and results to another page (eg results.php) when the user submits the form.
How is this achieved?

Just point the form action to results.php
<form action="results.php">
<!--Inputs-->
</form>
Or if you need to do a redirection store $_GET at $_SESSION['parameters'] .

Here are some attributes of form tag <form> you need to set them..
<form action="controller.php" method="post">
<!--form elements-->
<input type="submit" name="submit" value="Submit Form" />
</form>
Here when ever the submit button clicked, it will submit the form to its action i.e. controller.php by post method (i.e. form elements' value won't display in query string).
Later you can access their value on controller.php by $_REQUEST['element_name'] or $_POST['element_name'] or $_GET['element_name'] according to the form method type.

Related

php get data from another form using a different form

Is it possible to get data from another using a different form?
I don't want to use one form
<?php
echo $_POST['2'];
?>
<html>
<head>
</head>
<body>
<form method="post">
<input type="submit" name="submit" />
</form>
<form method="post">
<input type="text" name="2" />
</form>
</body>
</html>
No, that's not possible because browsers will only ever submit one form at a time (the one containing the clicked submit button, typically).
They can't possibly submit multiple forms at once because each form has its own action and method attribute which determines the request to send.
As #peter said, you can submit only one form at a time. But there are some workarounds for your needs.
Method 1
Post your form to a php script(say form_1_action.php) and then store the form input in a Session variable.
$_SESSION['form_data_1'] = $_POST;
Then you will be able to access it in different pages. Like,
$_SESSION['form_data_1']['field_name']
Method 2
Post your form to a php script(say form_1_action.php) and then store the form input in a PHP variable.
$formData1 = $_POST;
Then you can use the data from the first form in the second form (the second form should be on the same file form_1_action.php) like
<input name="name" value="{$formData1['field_name']"}>
You should pass the data from the first form in a hidden field on the second form if you need it on the form_2_action.php.
Method 3
Use Javascript to accomplish your requirements in a more userfriendly way.
try using jquery to Prevent the other form from submiting and try updating the value using event listening of the first form and update that input.
$( '#Submit' ).click( function ( event ) {
event.preventDefault();
var value = <?= $postedValue ?>;
$('input[name="input_name/2"]').val(value);
}

How to process 2 forms in a single html page using jquery and php

I have 2 forms in a single html page. The first form is for logging in and the other is for signing up.
The login form contains a submit button with a name="loginsubmit" attribute while the signup form contains a submit button with a name="signupbutton" attribute.
How can I detect which submit button was clicked with jQuery so that I can pass it off to PHP?
Try understanding this.
<form action="check_login.php" method="POST">
....// form elements
<input type="submit" name="login" value="LOGIN" />
</form>
<form action="register.php" method="POST">
....// form elements
<input type="submit" name="register" value="REGISTER" />
</form>
When you have 2 separate forms, change their action. As simple as that.
If flow comes to check_login.php, the click is on login button.If flows comes to register.php, then click is on register.
Note:
Suppose if the action of both the form is same, add the following code in form action file.
if(isset($_POST['login'])) {
// click is on login button
}
if(isset($_POST['register'])) {
// click is on register button
}

Submit button showing in GET URL

I'm having a problem with my HTML GET form that's connected to a PHP script, so, basically, when the action is done I see the SUBMIT button value in the URL, so it's like this http://url.com/?valueI=Want&submit=Submit+Value.
How do I stop that from happening?
Remove the name attribute from the submit element to prevent it from being passed in the query parameters.
See: Stop the 'submit' button value from being passed via GET?
This is the nature of GET requests. The submitted values, aka Query String, are shown as part of the URL after a ? suffixing the page URL.
If you don't want it to show up, use POST method, or make a script that submits using Ajax.
Now if the question is only about the text in the submit button being shown, if you don't want it to get submitted along with the rest of the form all you have to do is not give it a name.
<input type="submit" value="Send Form">
No name="..." in the tag.
you need to set the form method
<form action"/your/path" method="post">
...
</form>
You can use button tag to submit the value using GET method.
<button type="submit">Submit</button>
do something like:
<form action="myfile.php" method="get">
(your form elements here)
<input type="submit" value="Submit" />
</form>

form action attribute set to?

When is the need to set from action attribute to ? like this
<head>
<title></title>
</head>
<body>
<form action="?" method="post">
<div>
<label for="joketext">Type your joke here:</label>
<textarea id="joketext" name="joketext" rows="3" cols="40"></textarea>
</div>
<div><input type="submit" value="Add"/></div>
</form>
</body>
The need for setting the form action is so that the form can be submitted to whatever action you dictate, if you leave the action blank then the form will submit to itself (the same page it is on)
If you had a form handler which was not visible but handled all the processing, then you could define the handler address (url) in the form action or even send the data to another page if you so choose.
And wherever you sent it to, a form handler or itself or another page, that would take care of the data and deal with accordingly, as you so choose.
If you use:
<form action="myform.php" method="post">
Then the form redirects to myform.php And in this file there is the code that checks the form.
If you use:
<form action="myform.php?check" method="post">
Then the form redirects to myform.php but it also adds check to the $_GET array.
So you can write a piece of code that only works if there is a check element in your $_GET array.
if(isset($_GET['check']))
{
// your code here
}
In PHP every element after ? is a member of the $_GET array
For example: http://www.example.com?product_id=1&product_name=acme means that the $_GET array currenty has two elements:
product_id
product_name
I guess the below link should help.
http://www.w3schools.com/tags/att_form_action.asp
It allows you to specify where you want to post your form data
when you want form data to be stored, you can set it to a php file and save the data to a database, text file, or xml.

How to Submit two values with only one submit button?

Hey im making a website were you can send other users emails.
My problem is when I go and submit it doesn't submit both values?
my Form has a text box where the user wants to send the email and another is a text area which is the message.
and i don't want 2 submit buttons
Have a look at http://www.w3.org/TR/html401/interact/forms.html#h-17.1 on how to create forms.
Your inputs need unique name attributes.
Example:
<form>
<input type="text" name="recipient_address" />
<textarea name="message_body"></textarea>
<!-- no real need for a name on the submit button -->
<input type="submit" value="Send Message" />
</form>
any value that you want to send to the server make sure it is in the form tag. When the user clicks your "submit" button all of the data in the form is sent off along with the page request. You can have as many items as you want in the form.
<html>
<head>
/*... your code here
...*/
</head>
<body>
<form name='sampleForm' action='sample.htm' onsubmit='ValidatethisForm()' method="post" enctype="multipart/form-data">
<input type='text' name='formElem1'>
<textarea name='formElem2'></textarea>
<input type = 'submit' value='submit'>
</form>
</body>
</html>
In the validate function once u finish your validations use "return true" to proceed. You can submit multiple form elements as long as they have different name attributes and the are within your form tag.
By far the best I have found is here
Happy Coding
Check your input and add a unique name attribute.

Categories