2017-04-01 18 views
0

私はPHPでデータベースを使用してカスタムフォームを作成しています。私はワードプレスでそのフォームを統合したい。このため私は1つのテンプレート(customform.php)を作成し、ページに追加します。私のPHPコードはスムーズにxamppで実行されますが、wordpressでは実行されません。データベースが埋め込まれたphpフォーム

私はWordPressにコードを統合するのを助けてください。

/*CustomForm php*/ 
<?php /* Template Name: CustomForm */ ?> 
<?php require_once("conn.php");?> 

<?php get_header(); ?> 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> 

<div id="content" class="full-width"> 
    <?php while (have_posts()) : the_post(); ?> 
     <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

<body> 
    <form name="course_information" id="course_information" method="post" action="course_information_action.php" > 
    <div> 
    <h1 class="heading">Product Details</h1> 
    <h3>Product Type</h3> 
    <?php 
     $sql = "select id,course from course_master"; 
     $result = mysqli_query($con,$sql); 
     $selectbox = ''; 

     $selectbox .= '<select id="course_master" name="course_master" class="select_style"><option value="0"> -- select --</option>'; 
     while($data = mysqli_fetch_assoc($result)) 
     { 
      $selectbox .= "<option value=".$data['id'].">".$data['course']."</option>"; 
     } 
     $selectbox .= '</select>'; 
     echo $selectbox; 
    ?> 

    <h3>Product</h3> 

    <div><select class="select_style" id="course_details" name="course_details" > 
     <option value="0"> -- select --</option> 
    </select></div> 


    <p></p> 
    <div id="ex_data"> 
    <input type="checkbox" name="check" id="check" value="" /> I need a product demonstration, installation assistance and for other queries at no additional cost</div> 

    <p></p> 
    <div id="after_check"> 
    <div><textarea rows="5" cols="50" name="requirements" id="requirements" placeholder="Please provide your requirement here"></textarea></div> 

    <h3>Address</h3> 
    <div><textarea rows="5" cols="50" name="address" id="address" placeholder="Please provide your address for visit purpose"></textarea></div> 
    </div> 
    <span id="key_val"> 
    <h3>Please enter existing serial for extend subscription: </h3> 
    <div><input type="text" name="key" id="key" value="" /></div> 
    </span> 


    <h3>No. of licenses<span class="star_require">*</span> : </h3> 
    <div><input type="text" name="licenses" id="licenses" value="" required /></div> 

    <h3>Sub Total : </h3> 
    <span id="sub_total"></span> 
    <div><input type="hidden" name="price" id="hidden_subtotal" value="" /></div> 

    <div><input class="form_btn" type="submit" id="continue_first" value="continue" /></div> 
    </div> 

    <div id="contact_details"> 
    h1 class="heading">Contact Details</h1> 
    <h3>Email Address<span class="star_require">*</span>:</h3> 
    <div><input type="text" id="email" name="email" value="" required /></div> 

    <h3>Mobile <span class="star_require">*</span>: </h3> 
    <div><input type="text" id="mobile" name="mobile" value="" maxlength="10" required /></div> 


    <div><input class="form_btn" type="submit" id="continue" value="continue" /></div> 
    </div> 

    <div id="billing_details"> 
    h1 class="heading">Billing Details</h1> 
    <h3>Your Name/Organisation Name<span class="star_require">*</span>:</h3> 
    <div><input type="text" id="name" name="name" value="" required /></div> 

    <h3>Your Area PIN code <span class="star_require">*</span>: </h3> 
    <div><input type="text" id="pincode" name="pincode" value="" maxlength="10" required /></div> 


    <div><input class="form_btn" type="submit" id="submit" value="submit" /></div> 

    </div> 
</form>   


     </div> 
    <?php endwhile; ?> 
</div> 
<?php get_footer(); 


/*contact form.js*/ 

// JavaScript Document 
$(document).ready(function(){ 
     $("#key_val").hide(); 
     $("div#ex_data").hide(); 
     $("div#after_check").hide(); 
     $no = $("#licenses").val(); 

     $("#licenses").keypress(function (e) { 
      //if the letter is not digit then display error and don't type anything 
      if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {    
         return false; 
      } 
      }); 


     $("#course_master").change(function(){ 
      var cid = $(this).val();    
      if(cid == 2) 
      { 
       $("#key_val").show(); 
       $('#licenses').attr('disabled', 'disabled'); 
       $("div#ex_data").css("display","none"); 
      } 
      else{ 
       $("#key_val").hide(); 
       $("div#ex_data").show(1000); 
       $("#licenses").removeAttr("disabled"); 
      } 
      $.ajax({ 
       type:"POST", 
       url:"get_course_details.php", 
       data:"cid="+cid, 
       success:function(msg) 
       {     
        $("#course_details").html(msg); 
       } 
      }); 

     }); 

     $("#course_details").change(function(){ 
      var id = $(this).val(); 
      $.ajax({ 
       type:"POST", 
       url:"get_course_info.php", 
       data:"id="+id, 
       success:function(msg) 
       {     
        $("#hidden_subtotal").val(msg); 
        if($no == '') 
        { 
         var total = msg * 1; 
         $("#sub_total").text(total); 
        } 
        else 
        { 
         var total = msg * $no; 
         $("#sub_total").text(total); 
        } 
       } 
      });    
     }); 

     $("#check").click(function(){ 
      if($(this).is(":checked")){ 
       $("div#after_check").show(1000); 
       $("div#after_check #address").attr("required","true"); 
       $("div#after_check h3").append("<span class='star_require'>*</span>"); 
      } 
      else 
      { 
       $("div#after_check").hide(1000); 
       $("div#after_check #address").attr("required","false"); 
      } 
     }); 



     $("#key").blur(function(){   
      var key = $("#key").val(); 
      $.ajax({ 
       type:"POST", 
       url:"validate_key.php", 
       data:"key="+key, 
       success:function(msg) 
       {     
        if(msg ==1) 
        { 
         $("#licenses").removeAttr("disabled"); 
        } 
        else 
        { 
         $('#licenses').attr('disabled', 'disabled'); 
        } 
       } 
      }); 

     }); 

     $("#licenses").blur(function(){   
      var subtotal = $("#hidden_subtotal").val(); 
      if(!isNaN(subtotal) && subtotal != '' && subtotal != 0) 
      { 
       subtotal = subtotal * $("#licenses").val(); 
       $("#sub_total").text(subtotal); 
      } 

     }); 

     $("#continue_first").click(function(){ 
      $("div#contact_details").css("display","block"); 

     }); 
     $("#continue").click(function(){ 
      $("div#billing_details").css("display","block"); 

     }); 

     $("#submit").click(function(){ 
      var email = $("#email").val(); 
      var mobile = $("#mobile").val(); 
      var pincode = $("#pincode").val(); 
      if(!isValidEmailAddress(email)) { 
       alert("invalid email address!"); return false; 
      } 
      else if(isNaN(mobile) || (mobile.length < 10)) 
      { 
       alert("invalid mobile no!"); return false; 
      } 
      else if(isNaN(pincode)) 
      { 
       alert("Invalid Pincode!");return false; 
      } 
      else{ 
       alert("success"); 
       $("#course_information").submit(); 
       return true; 
      } 

     }); 

    }); 



    //if(!isValidEmailAddress(emailaddress)) { /* do stuff here */ } 

    function isValidEmailAddress(emailAddress) { 
    var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i; 
    return pattern.test(emailAddress); 
}; 

答えて

0

まずはWordPressから統合するために、設定ファイルを作成してインクルードする必要はありません。あなたが使用しているテーマでテンプレートを作成し、wordpress adminでページを作成し、このテンプレートを呼び出します。

関連する問題