Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

how can I add an action to my code in order to send message using javascript

this is a simple html form and am trying to link it with javascript code so that the user can be able to send a message to contact my client.

      <div class="container">

        <div class="form">

          <div id="sendmessage">Your message has been sent. Thank you!</div>

          <div id="errormessage"></div>

          <form action="" method="post" role="form" class="contactForm">

            <div class="form-row">

              <div class="form-group col-md-6">

 <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
                <div class="validation"></div>
              </div>
              <div class="form-group col-md-6">
                <input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
                <div class="validation"></div>
              </div>
            </div>
            <div class="form-group">
          <input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />

          <div class="validation"></div>

            </div>
            <div class="form-group">
         

 <textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
              <div class="validation"></div>
            </div>
            <div class="text-center"><button type="submit">Send Message</button></div>
          </form>
        </div>

      </div>

I don't know if I should use php for that or javascript, or if there is any library that can help me to simplify my work

question from:https://stackoverflow.com/questions/66054077/how-can-i-add-an-action-to-my-code-in-order-to-send-message-using-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use both PHP or JavaScript to sending data to the server. If you use PHP, then you should specify form action, if you leave it empty, your data will be sent to the current page. Also, you can send data by javascript or other related libraries like jQuery. In this case you can use XMLHttpRequest or ajax


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...