Arco_Pelago
Arco_Pelago

Reputation: 325

How to get data from a form?

I have a form for a website where people can make orders. I have a form with the correct inputs and a submit button. The thing is, i don't really know what ways there are for me to get that info that the user has typed in. Should it create a txt file or should the info be sent to me via email? In that case how? I haven't used php at all and would like to avoid it for now if possible...

This is the form

HTML

<form id="TheForm">
            <div id="Row">
                <input type="text" id="Name" placeholder="*Förnamn" required>
                <input type="text" id="Surname" placeholder="*Efternamn" required>
            </div>      
            <div id="Row">
                <input type="email" id="FirstEmail" placeholder="*e-postadress" autocomplete="on" required>
                <input type="email" id="SecondEmail" placeholder="*Verifiera e-postadress" autocomplete="off" required>
            </div>
            <div id="Row">
                <input type="text" id="Town" placeholder="*Ort" required>
            </div>  
            <div id="Row">
                <input type="text" id="Address" placeholder="*Adress" required>
            </div>
            <div id="Row">
                <input type="text" id="PostCode" placeholder="*Postnummer" required>
            </div>
            <div id="Row">
                <input type="text" id="MobileNumber"  placeholder="*Mobilnummer" required>
                <input type="text" id="TelephoneNumber" placeholder="Telefonnummer">
            </div>
            <textarea id="Comment" placeholder="Förslag på hur vi skulle kunna förbättra oss!"></textarea>
            <input type="submit" id="Submit" value="Skicka">
        </form>

ps. The placeholders are in swedish so don't worry about that ;)

Upvotes: 0

Views: 129

Answers (3)

XD face me
XD face me

Reputation: 588

For as far as I know is PHP by far the best for communicating between a server and a client (when using a form for example). You could indeed maybe use javascript for making a txt file and mailing it but that would be a bit of overkill i think. Cheers!

Upvotes: 0

Lohardt
Lohardt

Reputation: 1045

php is by far the easiest way

first off, add a name attribute to all your html input fields like this:

<input name="surname" type="text" id="Surname" placeholder="*Efternamn" required>`

also add metode & action to your form:

<form action="some_php_file.php" metode="POST" id="TheForm">

then in your php you can do like this:

<?PHP

//get data from html, using the post metode
$name = $_POST['name'];
$surname = $_POST['surname'];

//specify a txt file
$file = 'people.txt';

// Open the file to get existing content
$current = file_get_contents($file);

// Append a new person to the file    
$current .= $name." ".$surname.PHP_EOL;

// Write the contents back to the file
file_put_contents($file, $current);
?>

This is a very simple example, just to get you startet. By the way, PHP_EOL is a linebreak

Upvotes: 1

meda
meda

Reputation: 45490

Don't get intimidated by PHP it's so many ressource out there to help you if you decide to chose it then you can use either POST or GET:

POST

HTML:

<form id="TheForm" action="data.php" method="POST">
<input type="text" id="Surname" placeholder="*Efternamn" required>

PHP:

$surname = $_POST["Surname"];
echo $surname;


GET

HTML:

<form id="TheForm" action="data.php" method="GET">
<input type="text" id="Surname" placeholder="*Efternamn" required>

PHP:

$surname = $_GET["Surname"];
echo $surname;

Upvotes: 2

Related Questions