Jump to content

form processing fields


riceandfish

Recommended Posts

This might have been asked before but can't seem to find it. If you got the link would be glad to check it out. Well heres where I am having trouble understanding. I am taking classes at school right now and very very new to php world. I hope I'll like it.

 

I have a form.

<form action="/process.php" method="post">
  <label>name
  <input type="text" name="name" id="name" />
  </label>
  <p>
    <label>last name
    <input type="text" name="lastname" id="lastname" />
    </label>
  </p>
  <p>
    <label>phone
    <input type="text" name="phone" id="phone" />
    </label>
  </p>
  <p>
    <label>Email
    <input type="text" name="email" id="email" />
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>

 

Trying to process the above form to output all of the fields ask into an email using php. I had been tweaking on this but I can't get it to work! Here is my php code located in my process.php file.

<?php
$to      = '[email protected]';
$name = 'the subject';
$lastname = 'last name';
$phone = 'the number';
$email = 'email';

mail($to, $name, $lastname, $phone, $email);
?>

 

 

Question!!!

 

1. how can I make the name, last name, phone and email variables to output it in the email what the user had entered into the text box and not the default value?

 

Its been 3 weeks of me reading books over and over again plus some video tutorials but can't seem to understand! Please help:(

 

 

Link to comment
https://forums.phpfreaks.com/topic/121307-form-processing-fields/
Share on other sites

form method = post,

you have to pickup whats in the forms, you have the forms already filled in

 

$name = $_POST['name']; // make the ['here'] the same as your input field name

$lastname = $_POST['lastname'];

$phone = $_POST['phone'];

 

etc ..

 

then ...

 

$body = "name: $name"; // I put these all in body

$body .= "lastname: $lastname";

$body .= "phone: $phone";

 

etc..

 

mail($to, $subject, $body);

Oh, so you basically use the either _POST or get to output the value. Then you get those values, store them in variable $body and then append the variable $body as one of the parameters of mail(). I see what you mean but this wont seem to work on a message field. Thank you so much. I can start solving homework:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.