2015-10-20 115 views
-2

我想更改div的id intFrom。插入數據到數據庫中的內容後,我想要的代碼不只是呼應¡Enhorabuena!...如何更改PHP中的div內容?

但隨着¡Enhorabuena替代形式!我也許,我可以使用AJAX替換表單。

下面是代碼: HTML

<form method="post" action=""> 
    <div> 
    <select value="genero" name="genderselect" id="genero" required="required" autofocus="autofocus"> 
    <option value="none" selected>- Selecciona Género - </option> 
    <option value="Mujer">Mujer</option> 
    <option value="Hombre">Hombre</option> 
    </select> 
    <input type="text" id="name" name="name" value="" placeholder="Nombre completo" required="required" autofocus="autofocus" /> 
    <input type="email" id="email" name="email" value="" placeholder="Correo electrónico" required="required" /> 
    </div> 
    <div> 
    <div class="infForm img"> 
    <img src="http://www.miraqueguapa.com/Landings/General/img/biotherm.png" alt="Imagen Crema Aquasource Biotherm" class="biotherm"> 
    </div> 
    <div class="infForm text"> 
    <div class="legal"> 
    <input type="checkbox" id="cblegales" value="1" name="cblegales" required="required" autofocus="autofocus"> 
    <p>He leído y acepto la <a class="enlace_pp" href="http://www.miraqueguapa.com/content/5-privacidad-proteccion-datos" target="_blank">política de privacidad</a></p> 
    </div> 
    <input type="submit" value="ENVIAR DATOS" name="submit_form" style=" background-color: #DF2848;border: none;border-radius: 0px;color: white;width: 200px;float: right;padding-left: 50px;cursor: pointer;margin-top: -5px;" /> 
</div> 
</div> 
</form> 
</div> 

PHP

<?php 
    if (isset($_POST['submit_form'])) { 
         include 'connection.php'; 

         $name=$_POST["name"]; 
         $email=$_POST["email"]; 
         $gender=$_POST["genderselect"]; 

         if($gender=="none"){ 
          echo"</br>"; 
          echo"por favor selecciona nuestro género"; 
          $link = null; 
         } 
         else{ 

          $i=0; 
          $statement = $link->prepare("select email from webform where email = :email"); 
          $statement->execute(array(':email' => "$email")); 
          $row = $statement->fetchAll(); 
          foreach($row as $key) { 
           $i=$i+1; 
          } 
          if ($i !=0) { 
           echo" Este correo electrónico ya está registrado"; 
           $link = null; 
          } 
          else{ 

           $statement = $link->prepare("INSERT INTO webform(name, email, gender) 
           VALUES(:name, :email, :gender)"); 
           $statement->execute(array(
            "name" => "$name", 
            "email" => "$email", 
            "gender" => "$gender" 
           )); 
           $link = null; 

           echo"¡Enhorabuena!"."<br/>"; 
           echo"Tus datos se han enviado correctamente. A partir de ahora recibirás cada semana las últimas novedades y las mejores ofertas en Cosmética de las marcas más prestigiosas del mercado."; 

          }}} 
        ?> 
+0

什麼是您對這個代碼的問題說的嗎? –

+0

如何用¡Enhorabuena替換表格!代碼提交後的文本 –

回答

0

您需要添加簡單if else聲明。

if (isset($_POST['submit_form'])) { 
    // Your code after form get submitted. 
} 
else { 
    // Show default form. 
} 
0

只需加載你的HMTL代碼到您的PHP作爲一種「模板」與file_get_contents(__DIR__ . "Path/To/Your.html");在一個變量,並且做了一個簡單str_replace('id="your_element_id"', 'id="replace_id"', $template_variable);和回聲您的模板,如果你以後只想更換ID。

如果你想在表單中改變一些東西,這樣做,因爲我上面str_replace('tag_you_are_looking_for', 'should_be_replaced_with', $template_variable);