2012-03-05 10 views
0

Magentoのページでカスタマイズ可能な連絡フォームを使用することはできますか?Magentoのページでカスタマイズ可能な連絡フォームを使用することはできますか?

それが可能だ場合:

  1. 私はこれをサポートするためにどのようなアクションを呼び出す必要がありますか?
  2. カスタマイズ可能なフォーム要素を使用することはできますか、またはMagento標準を使用する必要がありますか?

私は私のページに使用していますフォーム:

<form action="" method="post"> 
    <input type="hidden" name="formID" value="20642064378453"> 
    <div class="form-all"> 
    <ul class="form-section"> 
     <li class="form-line" id="id_8"> 
     <label class="form-label-left" id="label_8" for="input_8"> Full Name </label> 
     <div id="cid_8" class="form-input"><span class="form-sub-label-container"><input class="form-textbox" type="text" size="10" name="q8_fullName8[first]" id="first_8"> 
      <label class="form-sub-label" for="first_8" id="sublabel_first"> First Name </label></span><span class="form-sub-label-container"><input class="form-textbox" type="text" size="15" name="q8_fullName8[last]" id="last_8"> 
      <label class="form-sub-label" for="last_8" id="sublabel_last"> Last Name </label></span> 
     </div> 
     </li> 
     <li class="form-line" id="id_1"> 
     <label class="form-label-left" id="label_1" for="input_1"> 
      Name<span class="form-required">*</span> 
     </label> 
     <div id="cid_1" class="form-input"> 
      <input type="text" class="form-textbox validate[required]" id="input_1" name="q1_name" size="20"> 
     </div> 
     </li> 
     <li class="form-line" id="id_3"> 
     <label class="form-label-left" id="label_3" for="input_3"> 
      Email<span class="form-required">*</span> 
     </label> 
     <div id="cid_3" class="form-input"> 
      <input type="text" class="form-textbox validate[required]" id="input_3" name="q3_email" size="20"> 
     </div> 
     </li> 
     <li class="form-line" id="id_4"> 
     <label class="form-label-left" id="label_4" for="input_4"> Topics </label> 
     <div id="cid_4" class="form-input"> 
      <select class="form-dropdown" style="width:150px" id="input_4" name="q4_topics"> 
      <option> </option> 
      <option value="Option 1"> Option 1 </option> 
      <option value="Option 2"> Option 2 </option> 
      <option value="Option 3"> Option 3 </option> 
      </select> 
     </div> 
     </li> 
     <li class="form-line" id="id_5"> 
     <label class="form-label-left" id="label_5" for="input_5"> Other Options </label> 
     <div id="cid_5" class="form-input"> 
      <div class="form-single-column"><span class="form-radio-item" style="clear:left;"><input type="radio" class="form-radio" id="input_5_0" name="q5_otherOptions" value="Option 1"> 
       <label for="input_5_0"> Option 1 </label></span><span class="clearfix"></span><span class="form-radio-item" style="clear:left;"><input type="radio" class="form-radio" id="input_5_1" name="q5_otherOptions" value="Option 2"> 
       <label for="input_5_1"> Option 2 </label></span><span class="clearfix"></span><span class="form-radio-item" style="clear:left;"><input type="radio" class="form-radio" id="input_5_2" name="q5_otherOptions" value="Option 3"> 
       <label for="input_5_2"> Option 3 </label></span><span class="clearfix"></span> 
      </div> 
     </div> 
     </li> 
     <li class="form-line" id="id_7"> 
     <label class="form-label-left" id="label_7" for="input_7"> Message </label> 
     <div id="cid_7" class="form-input"> 
      <textarea id="input_7" class="form-textarea" name="q7_message" cols="40" rows="6"></textarea> 
     </div> 
     </li> 
     <li class="form-line" id="id_2"> 
     <div id="cid_2" class="form-input-wide"> 
      <div style="margin-left:156px" class="form-buttons-wrapper"> 
      <button id="input_2" type="submit" class="form-submit-button"> 
       Submit Form 
      </button> 
      </div> 
     </div> 
     </li> 
     <li style="display:none"> 
     Should be Empty: 
     <input type="text" name="website" value=""> 
     </li> 
    </ul> 
    </div> 
    <input type="hidden" id="simple_spc" name="simple_spc" value="20642064378453-20642064378453"> 
    <script type="text/javascript"> 
    document.getElementById("si" + "mple" + "_spc").value = "20642064378453-20642064378453"; 
    </script> 
</form> 

ありがとうございました!

答えて

1

Mage_Contacts_IndexController::postAction()メソッドでカスタムの連絡先フォームを処理できます。
ポストされたデータは、いくつかの基本的な要件を満たしている必要があります

// Excerpt from Mage_Contacts_IndexController::postAction() 

$postObject = new Varien_Object(); 
$postObject->setData($post); 
$error = false; 

if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) { 
    $error = true; 
} 
if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) { 
    $error = true; 
} 
if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) { 
    $error = true; 
} 
if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) { 
    $error = true; 
} 
if ($error) { 
    throw new Exception(); 
} 

このコードは、フォームがあなたにアクションが箱から出して、あなたのデータで動作するコントローラを満たすために必要とする基準を示します。

まず、データを投稿する必要があります(GET経由で送信しないでください)。
空でないnameフィールド、emailフィールド(構文的に正しい電子メールを使用)、空でないhideitフィールド、およびcommentフィールドが存在する必要があります。

フォームはURL /contacts/index/postに投稿する必要があります。
MagentoでURLを生成する最も良い方法はecho Mage::getUrl('contacts/index/post')です。

投稿されたデータは連絡先メールの{{ var data}}変数で利用可能になりました。
電子メールテンプレートは、システム>トランザクション電子メールの管理インターフェイスで調整できます。 デフォルトでは、テンプレートは非常に基本的ですが、簡単に拡張できます。たとえば、電子メールにq5_otherOptionsというフィールドの値を追加するには、 `{{var data.q5_otherOptions}}をプレースホルダとして使用します。

+0

こんにちはVinai、私はちょっと混乱していると私は私がやったことは本当にばかだと感じ...私は、実際のページにこれを置くことができますか、私はそれのためにPHTMLを作成する必要がありますか? ここに私がしたことがあります。 http://jsbin.com/utesik/ - これは私のマゼンタのページの中の実際のフォームです。 ありがとうございます! – Pennf0lio

+0

コードは 'Mage_Contacts_IndexController :: postAction()'からのものです。フォームに入れるべきではありません。フォームの中にどのフィールドを配置する必要があるかを示すだけで、コントローラーのアクションはフォームを使用してフォーム上で動作します。 – Vinai

+0

ああ...申し訳ありませんが... :) – Pennf0lio

0

アクションがmodule、カスタムモジュールの名前です$this->getUrl('module/controller/action')は、controllerが、モジュール内のコントローラである必要があり、かつactionはそのコントローラでのアクションです。このために独自のカスタムモジュールを作成する必要があります。これを行う方法については、最初のいくつかの記事、http://alanstorm.com/category/magentoをお読みください。

0

ここには、非常に基本的なカスタム連絡先フォームの設定の詳細が書かれています。これはあなたの要件を満たしているかもしれませんが、コンタクトフォームにフィールドを追加するだけで十分です。

http://www.magentocommerce.com/boards/viewthread/262835/

関連する問題