How do I pass form data from a HTML page to a PHP page?
-
Heres a basic HTML page with email and password fields: http://joinalpha.com/input.html I want to pass the email and password data to this form: https://joinalpha.com/launch/signup.php/taster On submission the URL shows as: https://joinalpha.com/launch/signup.php/taster?signup_email_address=dhugal%4076uk.com&signup_password=pass123 but doesn't auto populate BTW I've used javascript and HTML code found here: http://www.irt.org/articles/js063/source.htm
-
Answer:
So, at the moment you've got the following as your basic HTML: <form id="transparent_redirect_form" name="transparent_redirect_form" action="https://joinalpha.com/launch/signup.php/taster"> <table> <tbody> <tr> <td>Email</td> <td> <input type="text" id="signup_email_address" name="signup_email_address"> </td> </tr> <tr> <td>Password</td> <td> <input type="password" id="signup_password" name="signup_password"> </td> </tr> </tbody> </table> <input type="SUBMIT"> </form> This is fine, but getting the passwords in the URL (GET) is very, very, VERY insecure. You'd be much better off (and you should by default) to send them via POST. To do that all you have to do is add method="POST" to the <form> element. Next, I'm assuming you want the data to then auto-populate the form. This won't happen automatically. You'll have to do it yourself. I'm not sure how good you are with PHP or what you're doing server-side (and I shouldn't), but you'll have to make the values of the form fields the values that you passed to the page via the previous form. I'd do something like this*: <?php /*Other code*/ ?> <form id="transparent_redirect_form" name="transparent_redirect_form" action="https://joinalpha.com/launch/signup.php/taster"> <table> <tbody> <tr> <td>Email</td> <td> <input type="text" id="signup_email_address" name="signup_email_address" value="<?php echo $_POST['signup_email_address']; ?>"> </td> </tr> <tr> <td>Password</td> <td> <input type="password" id="signup_password" name="signup_password" value="<?php echo $_POST['signup_password']; ?>"> </td> </tr> </tbody> </table> <input type="SUBMIT"> </form> <?php /*other code*/ ?> *Note that this is actually the basic form you provided, but you'd still do the same to the other form, just that you've got many more fields in the form. Note that all the PHP code is doing is getting the $_POST['']; global variable and finding the value for the part of the array called "signup_email_address". It does the same for the password.
Thomas Foster at Quora Visit the source
Other answers
Okay, so I looked at the irt.org page, but the other website you put wouldn't go through, it couldn't find the domain, but I will try to answer to the best of my abilites. Objective (from my understanding): Have an HTML form (form.html) and pass data to a PHP page (submitForm.php) and do something with that data. Let's start with the form: <form action="submitForm.php" method="post"> You had the method using "Get," and as mentioned is a bad way to do it (See the "http://thedailywtf.com/articles/The_Spider_of_Doom" article) so were gonna use Post in this example <input name="email" type="text"> <input name="password" type="password"> <input type="submit" value="Sumbit"> </form> And to make life a bit better let's look at it all in one: <!DOCTYPE html> <html> <head> <title>My Webpage Form</title> </head> <body> <form action="submitForm.php" type="post"> <input name="email" type="text"> <input name="password" type="password"> <input type="submit" value="Sumbit"> </form> </body> </html> Okay our form is setup, let's just clarify a few points: 1. To change it to a Get method, just change the method to get from post 2. To add more <input>'s just add them with the rest, remember syntax is <input name="whatisthis" type="text">, to see different types of input types, see http://www.w3schools.com/tags/att_input_type.asp Okay, now submitForm.php: Lets start simple: <?php //Variables $email = $_POST['email']; $password = $_POST['password']; /* In simple terms, we are using the name="" attribute from the <input> tags to define the php variables, to change this to a get method, change POST to GET (case sensitive) and to add new ones use the syntax, $var = $_POST['inputname']; */ //Okay now we have our Variables! //Next is up to you, below I added a code to insert into a MYSQL database //Connect to DB $con=mysqli_connect("DB_HOST","DB_USER","DB_PASS","DB_DB"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }; //Insert Values $sql = "INSERT INTO TABLE_NAME(email, password) VALUES ($email, $password)"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { //Change this to for a custom error message echo "Error: " . $sql . "<br>" . $conn->error; } //Another example might be mail to the owner $msg = "Your account email is: " + $email + " and password is: " + $password"; mail("$email","Account Info",$msg); ?> It really depends on what you're attempting to do with the data, feel free to comment below if this isn't what you need. Good luck!
Benjamin S. Sommer
Related Q & A:
- How do I display all categories on a page with a corresponding image?Best solution by Magento
- How can I pass global variables into a function?Best solution by Stack Overflow
- How can I apply a filter on a page?Best solution by Stack Overflow
- How do I delete my old Yahoo page after I made a new page?Best solution by answers.yahoo.com
- How do I add a photo to a Wikipedia page?Best solution by en.wikipedia.org
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.