简体   繁体   中英

Remove and add new HTML-Tags

Is there a way in PHP or Javascript to delete html tags and add new ones?

For example:
I have a contact form. If the user enters the correct values and clicks on "send", then all HTML tags for the contact form should be deleted, so that the contact form disappears. After that, for example, a div-tag should be inserted with the text "Your mail was sent successfully. I will get back to you soon. Thanks a lot".

So, this code:

......

<form action="php/test.php" method="post" novalidate="">
 <div class="row">
   <div class="column width-5 offset">
        <input type="text" name="lname" class="form-lname form-element large" placeholder="Name" tabindex="1">
     </div>
  <div class="column width-5 offset">
   <input type="email" name="email" class="form-email form-element large" placeholder="E-Mail-*" tabindex="2" required="">
     </div>
</div>
  </form>
......

is to be changed to this code after you click on "send".
<div>Your mail was sent successfully. I will get back to you soon. Thanks a lot<div>

Is it possible with php or javascript to replace the html tags? Or is there a better way to do it?

You have several options here ( I would recommend second option).

If you want to stay on same page and hide it with javascript:

<p>If you click on the "Hide" button, I will disappear.</p>

 $(document).ready(function(){
  $("#hide").click(function(){
    $("p").hide();
  });
  $("#show").click(function(){
    $("p").show();
  });
});

Second option is PHP. You should make a new page with message:

Your mail was sent successfully. I will get back to you soon. Thanks a lot...

You just need to change header('Location: success.php'); after inserting your query.

hope this was helpful. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM