Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:21:06+00:00 2026-05-24T16:21:06+00:00

<form method=post action= id=infoform> <label for=first> First Name</label> <input type=text name=first id=first class=field validate[required]>

  • 0
<form method="post" action="" id="infoform">
<label for="first">
    First Name</label>
<input type="text" name="first" id="first" class="field validate[required]">
</br>
<label for="surname">
    Last Name</label>
<input type="text" name="surname" id="surname" class="field validate[required]"> </br>
    <label for="email">
        Email</label>
    <input type="text" name="email" id="email" class=" field email validate[required,custom[email]]">
        </br>
        <div class="radios">
            <input id="test2" checked="checked" type="radio" name="message" value="register" />
        Register for Updates</input>
    <input id="test1" type="radio" name="message" value="msgs" />
    Send a Message</input>
</div>
<div class="msg">
    <label for="message" id="messagelabel">
        Message</label>
    <textarea type="text" name="message" id="message"></textarea>
</div>
<input id="submit" type="submit" value=""><div class="test3">
    <a class="sbmt">Register</a></div>
    <div class="test4">
        <a class="sbmt">Send</a></div>
</input>
</form>

If the radio box ‘test1’ is checked, then the div msg appears. This is then sent via ajax to an email php script:

<?php
    $EmailTo = "matt@explosivetitles.com";
    $adminSubject = "Civitas Message";

    $firstName = Trim(stripslashes($_POST['first']));
    $Surname = Trim(stripslashes($_POST['surname'])); 
    $Email = Trim(stripslashes($_POST['email'])); 
    $Message = Trim(stripslashes($_POST['message'])); 

    $adminheaders = 'From: "Civitas website" <info@civitas.com>';

    $adminBody .= "First Name: ";
    $adminBody .= $firstName;
    $adminBody .= "\n";
    $adminBody .= "Surname: ";
    $adminBody .= $Surname;
    $adminBody .= "\n";
    $adminBody .= "Email: ";
    $adminBody .= $Email;
    $adminBody .= "\n";
    $adminBody .= "Message: ";
    $adminBody .= $Message;
    $adminBody .= "\n";


    $adminMail = mail($EmailTo, $adminSubject, $adminBody, $adminheaders);


    if ($adminMail){
        echo "true";
    }
    else{
      echo "false";
    }
?>

However I only want the “message” part of the email to be sent if the message box is showing. How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:21:08+00:00Added an answer on May 24, 2026 at 4:21 pm

    PHP does not look at the id of an element, instead, when a POST or GET method is sent, it looks at the name attribute. In the code you have written, you have two input elements, textarea and the radio input with the same name, “message”. When both are sent, the $_POST variable becomes an array and uses the name attribute as an index for the value submitted, and PHP arrays cannot have duplicate indexes, therefore to over come this problem you rename one. For your radio input I suggest the name attribute be set to type.

    <?php
        $send           = "matt@explosivetitles.com";
        $subject        = "Civitas Message";
        $details        = array (
            "first"     => @$_POST["first"],
            "surname"   => @$_POST["surname"],
            "email"     => @$_POST["email"],
            "message"   => @$_POST["message"]
        );
        foreach ($details as $index => $value) {
            $details[$index] = trim ( stripslashes ($value));
        }
        if (@$_POST["type"] == "register") {
            // Whatever happens when they select "register"
        } else if (@$_POST["type"] == "msgs") {
            $header     = "From 'Civitas website' <info@civitas.com>";
            $body       = $details["first"] . " " . $details["surname"] . " "
                        . "<" . $details["email"] . ">"
                        . "Message: \n"
                        . $details["message"];
    
            $mail       = mail ($send, $subject, $body, $header);
            if ($mail) {
                return true;
            } else {
                return false;
            }
        }
    ?>
    

    Also, your code hurts my eyes, so I rewrote it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<form id=login_frm method=post action = /login/user_auth/> <fieldset> <legend>Login:</legend> <label for=id_email>Email</label> <input type=text name=email id=id_email
<form method = post action = <?php echo $_SERVER['PHP_SELF']; ?> /> Username:<input type =
Getting variable from form: <form method = 'POST' action = ''> <input type =
I do have a search form. <form method=get id=searchform action=<?php bloginfo('siteurl');?>> <div class=search_bx1><input type=text
<form action=/Villa/Add method=post> <table> <tr> <td> Name: </td> <td> <%= Html.TextBox(name) %> <%= Html.ValidationMessage(Name)
I have a form and the method is set to post on the action
Here is the form submission part var form=document.forms[mainForm]; form.setAttribute(action,url_action); form.setAttribute(method,post); form.setAttribute(enctype,multipart/form-data); form.setAttribute(encoding,multipart/form-data); form.submit(); Now
I need to read the result of a form which uses POST action type
I have a simple form where there is a list: <form method =post action
I am having problems getting my form to Post to my Save method in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.