根据select选项元素将表单重定向到不同的URL,并在电子邮件

时间:2016-04-23 07:42:57

标签: javascript php jquery

我在这段代码中遇到问题,实际上我想要在提交表单及其重定向到选择选项时的电子邮件ID的表单详细信息。我正在尝试下面的文件名contactttry.php表格详细信息是工作文件,但这些代码不适用于重定向。

我收到了有关我的电子邮件ID的表单详细信息但页面未重定向到选择标记,因此请在此代码中帮助我或建议新代码。 我在这段代码中面临一个问题,实际上我想要在提交表单及其重定向到选择选项时的电子邮件ID的表单详细信息。我正在尝试下面的文件名contactttry.php表格详细信息是工作文件,但这些代码不适用于重定向。

我收到了有关我的电子邮件ID的表单详细信息,但页面未重定向到选择标记,因此请在此代码中帮助我或建议新代码。

提前谢谢

这是我的表格代码:

<form role="form" action="contactttry.php" class="contact-form" id="contact-form" method="post">
 <div class="form-group">
    <select class="form-control" id="se1" NAME="section" onChange="SelectRedirect();">
    <Option value="">Select Section</option>
<Option value="PHP">PHP</option>
<Option value="ASP">ASP</option>
<Option value="MySQL">MySQL</option>
<Option value="JS">JavaScript</option>
<Option value="HTML">HTML</option>
  </select>
</div>
              <div class="form-group">
                <div class="controls">
                  <input type="text" placeholder="Name" name="name" id="name" required>
                </div>
              </div>
              <div class="form-group">
                <div class="controls">
                  <input type="email" class="email" placeholder="Email" name="email" id="email" required >
                </div>
              </div>
              <div class="form-group">
                <div class="controls">
                  <input type="text" class="requiredField" placeholder="Mobile No." name="phone" id="phone" required>
                </div>
              </div>

              <button type="submit" id="submit" class="btn-system btn-large" >Submit</button>
              <div id="success" style="color:#34495e;"></div>
            </form>
            <!-- End Contact Form -->

contactttry.php文件:

<?php

$name              = $_POST['name'];
$email             = $_POST['email'];
$sub           = $_POST['subject'];
$phone                   = $_POST['phone'];
$intrest           = $_POST['message'];

$from = $txtemail; 
$from_name = $txtname; 
$to = "xyz@gmail.com"; 
$to_name = $name; `enter code here`
$subject = "Contact From IJLTEMAS"; 
$body ="
Name : ". $name."
Email: ".$email."
Phone: ".$phone."
Subject: ".$sub."
Message: ".$intrest."";
if (filter_var($email, FILTER_VALIDATE_EMAIL))                   
mail($to, $subject, $body);
?>
<script>
function SelectRedirect(){
// ON selection of section this function will work
//alert( document.getElementById('s1').value);

switch(document.getElementById('s1').value)
{
case "PHP":
window.location="url1/";
break;

case "ASP":
window.location="url2/";
break;

case "MySQL":
window.location="url3/";
break;
case "JS":
window.location="url4/";
break;

case "HTML":
window.location="url/";
break;

/// Can be extended to other different selections of SubCategory //////
default:
window.location="homeurl/"; // if no selection matches then redirected to home page
break;
}// end of switch 
}
////////////////// 
</script>

2 个答案:

答案 0 :(得分:0)

&#13;
&#13;
public class Parent {
    public void print(String s) {
        System.out.println("That was a string: " + s);
    }
}

public class Child extends Parent{
    public void print(int i) {
        System.out.println("That was an int: " + i);
    }
}

public class Main {
    public static void main(String[] args) {
        Child c = new Child();
        c.print("hello"); // prints "That was a string: hello"
        c.print(7); // prints "That was an int: 7"
    }
}
&#13;
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  
<script>
$(document).ready(function(){
    alert("hi");
    $("#se1").change(function(){
      
switch($("#se1").value())
{
case "PHP":
window.location="url1/";
break;

case "ASP":
window.location="url2/";
break;

case "MySQL":
window.location="url3/";
break;
case "JS":
window.location="url4/";
break;

case "HTML":
window.location="url/";
break;

/// Can be extended to other different selections of SubCategory //////
default:
window.location="homeurl/"; // if no selection matches then redirected to home page
break;
}// end of switch 

 });
    });
////////////////// 
</script>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

form action =“samepage.php”

if(isset($_POST['submit']))
{


    //do email function here and then 

    switch ($_POST['section']) {

                    case "PHP":

                        header('Location:http://www.w3schools.com/js/js_switch.asp');
                        exit();

                        break;

                            }

}