2011-07-01 4 views
0

私はこれを昨日掲載しました。あなたが返信してこれをもう一度見ていると謝ります!しかし、このフォームは現在全く機能していません。この問題を解決するための助けに感謝します。noob:ページ(2ページ)にerr_msgを表示

データをデータベースに送信するフォームがあり、検証が必要です。昨日は正しく検証されていましたが、今日はアクションページに正しく接続することさえできません。

ページフォーム/ W::ここでは、2つのページです

<?php 
    session_start(); 
    $form_field = array( 
           'First_Name'    => '', 
           'Last_Name'    => '', 
           'Business_Name'    => '', 
           'Phone_Number'    => '', 
           'Web_Address'    => '', 
           'Email_Address'    => '', 
           'How_selling_product'   => '', 
           'Where_did_you_hear_about_us' => '', 
          ); 
    foreach($form_field as $key => $value){$profiledata[$key]='';}    

    if(!empty($_SESSION['profiledata'])){ 
     $profiledata = $_SESSION['profiledata']; 
    } 

    ?> 

    [js] 
    function MM_findObj(n, d) { //v4.01 
     var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
     if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
     for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
     if(!x && d.getElementById) x=d.getElementById(n); return x; 
    } 

    function MM_validateForm() { //v4.0 
     var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; 

     errors += addValidation("req","first_name","- First Name is required."); 
     errors += addValidation("req","last_name","- Last Name is required."); 

     for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); 
     if (val) { nm=val.name; if ((val=val.value)!="") { 
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); 
      if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; 
      } else if (test!='R') { num = parseFloat(val); 
      if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; 
      if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); 
       min=test.substring(8,p); max=test.substring(p+1); 
       if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; 
     } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } 
     } 

     errors += addValidation("req","security_code","- Security Code is required."); 

     if(!errors){ 
     errors += addValidation("valid_lastname","first_name","- Please enter valid First Name"); 
     errors += addValidation("valid_lastname","last_name","- Please enter valid Last Name"); 
     errors += addValidation("numhyphenbrace","phone number","- Please enter valid Phone Number"); 
     errors += addValidation("valid_url","web address","- Please Enter Valid Web Address"); 
     errors += addValidation("email","email address","- Please Enter Valid Email"); 

     } 
     if (errors) alert('The following error(s) occurred:\n'+errors); 
     document.MM_returnValue = (errors == ''); 
    } 
    [/js] 

    <h1>Some content</h1> 
    <p>Some text</p> 

    <form id="form1" name="form1" method="post" action="mailform" onsubmit="MM_validateForm('Name','','R','Business Name','','R','Email Address','','R','How selling product','','R','Where did you hear about us','','R');return document.MM_returnValue"> 
     <div style="color:#FF0000; text-align:center;"><?php if(!empty($_GET['err_msg'])){echo $_GET['err_msg'];} ?></div> 
      <fieldset> 
         <legend>Contact form</legend> 
        <p class="first"> 
         <label for="name">First Name</label> 
         <input type="text" name="First Name" id="first_name" size="30" value="<?=htmlentities($profiledata['First_Name'])?>" /> 
        </p> 
          <p class="first"> 
         <label for="name">Last Name</label> 
         <input type="text" name="Last Name" id="last_name" size="30" value="<?=htmlentities($profiledata['Last_Name'])?>" /> 
        </p>     
        <p> 
         <label for="name">Phone Number</label> 
         <input type="text" name="Phone Number" id="phone number" size="30" value="<?=$profiledata['Phone_Number']?>" /> 
        </p> 
        <p> 
         <label for="email">Business Name</label> 
         <input type="text" name="Business Name" id="business name" size="30" value="<?=htmlentities($profiledata['Business_Name'])?>" /> 
        </p> 
        <p> 
         <label for="email">Web Address</label> 
         <input type="text" name="Web Address" id="web address" size="30" value="<?=$profiledata['Web_Address']?>" /> 
        </p> 
        <p> 
         <label for="email">Email</label> 
         <input type="text" name="Email Address" id="email address" size="30" value="<?=$profiledata['Email_Address']?>" /> 
        </p>    
      </fieldset> 
      <fieldset>                   
        <p> 
         <label for="message">Describe how you plan on selling this product</label> 
         <textarea name="How selling product" id="How selling product" cols="30" rows="4"><?=htmlentities($profiledata['How_selling_product'])?></textarea> 
        </p>  
        <p> 
         <label for="message">Where did you hear about us?</label> 
         <textarea name="Where did you hear about us" id="Where did you hear about us" cols="30" rows="4"><?=htmlentities($profiledata['Where_did_you_hear_about_us'])?></textarea> 
        </p> 
          <p> 
           <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /> 
         <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /> 
          </p>     
      </fieldset> 
       <p class="submit"><button type="submit">Send</button></p> 
       <input name="mailform_address" type="hidden" value="[email protected]" /> 
    </form> 

Mailform.phpの成功:私を助けるため

<?php 
session_start(); 
include("connect.php"); 

function valid_email($str) 
{ 
    return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; 
} 

function is_url($str) 
{ 
    return (! preg_match("/^((www)\.)?((\w+|[\d]?+)+(\.|\-)(\w+[\d]?+))+(\w)$/", $str)) ? FALSE : TRUE; 
} 

function valid_phone($str) 
{ 
    $Num = $str; 
    $Num = ereg_replace("([  ]+)","",$Num);; 
    $Num = eregi_replace("(\(|\)|\-|\+)","",$Num); 
    if(!is_numeric($Num)) 
    {  
     return FALSE; 
    } 
    else 
     return TRUE; 
} 

$form_field = array( 
          'First_Name'     => '', 
          'Last_Name'      => '', 
          'Business_Name'     => '', 
          'Phone_Number'     => '', 
          'Web_Address'     => '', 
          'Email_Address'     => '', 
          'How_selling_product'   => '', 
          'Where_did_you_hear_about_us' => '', 
         ); 
foreach($form_field as $key => $value){$profiledata[$key]=trim($_POST[$key]);} 

$_SESSION['profiledata'] = $profiledata; 

$emailto = NULL; 
$emailmessage = "Dealer Contact Form\n"; 
$emailsubject = "Dealer Contact Form"; 

if(!empty($_POST)){ 

    //echo "<pre>";print_r($_POST);die; 

    if($_SESSION['security_code'] != $_POST['security_code'] || empty($_SESSION['security_code'])) { 

     // Insert your code for showing an error message here 
     $err_msg = 'Sorry, you have provided an invalid security code'; 
     header("Location: reseller.php?err_msg=".urlencode($err_msg)); 
     return; 

    } else { 
     unset($_SESSION['security_code']); 
    } 

    $fname  = html_entity_decode(trim($_POST['First_Name'])); 
    $lname  = html_entity_decode(trim($_POST['Last_Name'])); 
    $company = html_entity_decode(trim($_POST['Business_Name'])); 
    $phone  = html_entity_decode(trim($_POST['Phone_Number'])); 
    $website = html_entity_decode(trim($_POST['Web_Address'])); 
    $email  = html_entity_decode(trim($_POST['Email_Address'])); 
    $notes  = "Lead Source: ".html_entity_decode(trim($_POST['Where_did_you_hear_about_us']))."\n"; 
    $notes  .= "Selling Method: ".html_entity_decode(trim($_POST['How_selling_product'])); 

    if(!valid_phone($phone)){ 
     $err_msg = 'Please enter valid Phone Number.'; 
     header("Location: reseller.php?err_msg=".urlencode($err_msg)); 
     return; 
    } 

    if(!is_url($website)){ 
     $err_msg = 'Please enter valid Web Address.'; 
     header("Location: reseller.php?err_msg=".urlencode($err_msg)); 
     return; 
    } 

    if(!valid_email($email)){ 
     $err_msg = 'Please enter valid Email.'; 
     header("Location: reseller.php?err_msg=".urlencode($err_msg)); 
     return; 
    } 

    if(!stristr($website,"http://") && !stristr($website,"https://") && $website){ 
     $website = "http://".$website; 
    } 

    $res = mysql_query("SELECT in_customer_id FROM tbl_customer WHERE st_company_name = '".addslashes($company)."'"); 
    if(mysql_num_rows($res)){ 
     $err_msg = 'Business Name already exists'; 
     header("Location: reseller.php?err_msg=".urlencode($err_msg)); 
     return; 
    } 

    $res = mysql_query("SELECT st_user_name,st_user_email_id FROM tbl_admin_user WHERE st_user_email_id='".addslashes($email)."' AND flg_is_delete=0"); 
    if(mysql_num_rows($res)){ 
     $err_msg = 'Email already exists'; 
     header("Location: reseller.php?err_msg=".urlencode($err_msg)); 
     return; 
    } 

    $sql_customer = "INSERT INTO tbl_customer (`st_company_name`, `in_customer_type`, `st_customer_account`, `in_customer_phone_number`, `flg_customer_account_type`, `flg_disable_ordering`, `st_message`, `in_status`, `dt_added_date`, `st_web`, `st_notes`) VALUES ('".addslashes($company)."', '2', '".time()."', '".addslashes($phone)."', '0', '1', 'You are an Inquiry customer', '0', '".date("Y-m-d H:i:s")."', '".addslashes($website)."', '".addslashes($notes)."')"; 

    mysql_query($sql_customer); 
    $cust_id  = mysql_insert_id(); 

    if($cust_id){ 
     $sql_user  = "INSERT INTO tbl_admin_user (`st_user_first_name`, `st_user_last_name`, `st_user_company_name`, `st_user_email_id`, `in_customer_id`) VALUES ('".addslashes($fname)."', '".addslashes($lname)."', '".addslashes($company)."', '".addslashes($email)."', '".$cust_id."')"; 
     mysql_query($sql_user); 

     $msg = ""; 
     $sub = "Thank you for contacting us."; 

     ob_start(); 
     include("mailformat.php"); 
     $msg = ob_get_contents(); 
     ob_end_clean(); 

     $headers = ''; 
     //$headers = "MIME-Version: 1.0\r\n";    
     $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 
     $headers .= "From: " . $_POST['mailform_address'] . "\r\n"; 
     $headers .= "Reply-To: ". $_POST['mailform_address'] . "\r\n"; 
     $headers .= "Bcc: [email protected]"; 

     if (@mail($email, $sub, $msg, $headers)) 
     { 
      session_unset('profiledata'); 
     } 
    } 

    foreach($_POST as $name => $value) 
    { 
     if ($name == 'mailform_address') 
     { 
      $emailto = $value; 
     } 
     elseif($name != "security_code") 
     { 
      $emailmessage .= $name . ": " . $value . "\n"; 
     } 
    } 
    session_unset('profiledata'); 
} 

?> 

    <?    
     if (@mail($emailto, $emailsubject, $emailmessage)) 
     { 
     ?> 
<p>We'll be in touch within two business days. If you haven't heard back from us within two business days, please <a href="contact">contact us</a></p> 
    <? 
     } 
     else 
     { 
     ?>  
<p>E-mail could not be sent. Please <a href="contact">contact us</a>.</p> 
     <? 
     } 
     ?> 

感謝。

+0

注:これはWordPressサイトです。 [js] [/ js]タグは、ページ上のjsを許可するプラグインで使用されています。 – blackessej

+0

動作していた時から現在になっている間にどのようなコードの変更があったのか分かりませんか?私はこれが明らかであることを知っているが、私は頼むと思った。何が変わったのかを特定するのが時々難しいことは分かっています。何らかの形のソース管理を使用していない場合は、私はそれをお勧めします。私はこれがあなたの質問に答えることはできませんが、私はそれが将来的に役立つことを願っています:) – M3NTA7

+0

いいえ、@ M3NTA7、私はコードに変更を見つけることができません。 WPやプラグインのアップデートは実装していません。また、FTPフォルダの日付をスキャンして、ファイルに何らかの変更が発生していないかどうかを確認しました。何も見つからない可能性があります。感謝します。 – blackessej

答えて

0

私は徹底的にあなたのコードを読んでいないが、これらのいずれかが問題であるかもしれないことを認める:スクリプト内MM_validateForm()への呼び出しで

  1. 、私はあなたの名を渡す必要があると思いますあなたのHTMLフォームフィールドは、すべての引数が正しいように見えますが、最初のものは有効なフォームフィールドではないような '名前'です。

  2. MM_validateForm()にはaddValidation()とは何ですか?それは何ですか?私はその定義が見えないので、あなたのJSでエラーが発生していると思われます。

  3. MM_validateForm()では、 3 & 4、変数errorsは決して空ではなく、フォームが送信されないようです。

私はどの点であなたが立ち往生しているか分かりません - あなたのフォームは全く提出していませんか? MM_validateForm()の末尾に変数errorsのアラートを表示しようとしましたか。多分それは助けるかもしれません。

+0

フォームは以前に投稿していませんでしたが、少なくともmailform.phpのURLにあるエラーを検証しています。 'action =" mailform.php "'は 'action =" mailform "'にする必要があり、私は上記のコードを変更しました。だから - 私は、URLでエラーの検証がありますが、私はそれがフォームのページに表示されるようにしたいと思います。申し訳ありませんが、私はPHPやjsでよくできていません - 私はこのコードを維持しようとしています。 – blackessej

関連する問題