Search code examples
phpjquerymailer

How to add preformatted text on text fields by clicking a button from another page


newbie here. Using php. So I have a button. When clicked will go to a contact page that I have already done. But I need to automatically put text into a text field for the message. All one has to do is click send as it is already formatted for them. How do I make the button automatically add text into the textfield(s)? I now realize it probably needs an onlick event or anything similar on the button that will post values on some text fields on the contact page being called. I hope I have given a better description of my problem. thanks guys.

Say this is my button:

<input type="submit" name="button" id="button" value="Submit" />

on submit will go to contact page and fill in the values of some textfields I need preformatted.

here's my sample mailer script.

<?php 
//print_r($_POST);
if(isset($_POST['_save'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $company = $_POST['company'];
    $message = $_POST['message'];
    $subject = $_POST['subject'];

    if (empty($name) || empty($email) || empty($subject) || empty($message)) {
        if (empty($name))
            $error['name'] = "Please enter your Full Name";
        if (empty($email))
            $error['email'] = "Please enter a valid Email Address";
        if (empty($company))
            $error['company'] = "Please enter Your Company Name";
        if (empty($subject))
            $error['subject'] = "Please Write a Subject";

    }
    else { //if not empty

        $headers="From: {$email}\r\nReply-To: {$email}"; //create headers for email
        $content="Name: ".$name."\r\n\r\nCompany: ".$company."\r\n\r\nSubject: ".$subject."\r\n\r\nMessage: ".$message;
        mail('[email protected]',$subject,$content,$headers); //mail the message;
        $success = "Thank you! You're email has been sent.";
        #done;
    }
}
?>

Solution

  • I am not sure but if i understand correctly your requirement. then probably you want this.

    1. You are at x page and page x has page has a button.
    2. When you click a button you go to contact page.
    3. You may passing some data using get or post method, you want to display that message on textarea of contact page.

    If i am right and above scenario is correct then you can do like this:

    <textarea name="message"><?php echo $_request['message']; ?></textarea>
    

    $_request can get both post or get data.

    thanks