【问题标题】:Download brochure depends on the hidden field value下载手册取决于隐藏字段值
【发布时间】:2016-02-28 04:20:18
【问题描述】:

我有一个 html 网站并使用带有表单的小册子下载选项。每个项目我都有很多表格。我只需要一个下载小册子的表格,取决于项目的隐藏输入值。

  jQuery(".form-js-pop-vedam").submit(function () {
		var thisform = jQuery(this);
		jQuery('.required-error',thisform).remove();
		
		var pmail	= jQuery("#pmail").val();
		var pphone	= jQuery("#pphone").val();
		var psubject	= jQuery("#psubject").val();
		
		var data = {'pmail':pmail,'pphone':pphone,'psubject':psubject}
		
		 if (pmail == "") {
			 jQuery("#pmail").after('<span class="form-description  required-error">Required field.</span>');
		}else {
			jQuery("#pmail").parent().find('.required-error').remove();
		}
		if (pphone == "") {
			jQuery("#pphone").after('<span class="form-description   required-error">Required field.</span>');
		}else {
			jQuery("#pphone").parent().find('.required-error').remove();
		}
		
		if ( pmail != "" && pphone != "" ) {
			jQuery.post("contact_us_pop-vedam.php",data,function (result) {
				if (result == "done") {
					
    thisform.prepend("<div class='alert-message success-amairo'><i      class='icon-ok'></i><p><span>Vedam brochure was sent to your mail. Thank    you!</span></p></div>");
					jQuery("#pmail").val("");
					jQuery("#pphone").val("");
					
				}
			});
		 }
		return false;
	 });
	
 
    <form class="form-style form-js-pop-vedam" action="contact_us_pop-vedam.php" method=post>
  <input type="hidden" name="psubject" id="psubject" value="Brochure   Download from Vedam Page">

  <div class="col-md-6" ><input type=email class=required-item id=pmail name=pmail value="" aria-required=true placeholder="Your Email*"></div>
  <div class="col-md-6 " ><input class=required-item aria-required=true id=pphone name=pphone value="" placeholder="Your Phone*"></div>
  <div class="col-md-6 " ><input name=submit type=submit value="Download Now >" class="submit_buttom buttonColor-side" id="Brochure_Download"></div>
  </form>

 
<!-- language: lang-php --> <?php function clean_text($text='') { $text = trim($text); $text = strip_tags($text); $text = addslashes($text); $text = htmlspecialchars($text); return $text; } if (!$_POST) { die(); }else { if (empty($_POST["pphone"]) && empty($_POST["pmail"]) ) { echo "all_empty"; }else if (empty($_POST["pmail"])) { echo "empty_mail"; }else if (empty($_POST["pphone"])) { echo "empty_phone"; }else { // edit this only :) $your_email = "me@myweb.com"; $pmail = clean_text($_POST["pmail"]); $pphone = clean_text($_POST["pphone"]); $psubject = clean_text($_POST["psubject"]); $subject = "$psubject"; $headers = "From: leads@website.in" . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8'. "\r\n"; $msg = "New Brochure Download \n<br />"; $msg .= "Email : \t $pmail \r\n<br />"; $msg .= "Phone : \t $pphone \r\n<br />"; echo "done"; $done = @mail($your_email, $subject, $msg, $headers); }if($done) { if(($pmail)) { $headerRep = "From: Website <info@website.in>"; $subjectRep = "Greetings from website!"; $messageRep = "Hi, \n\r Thanks for showing interest in our property \n\r"; $messageRep .="You can download the brochure here http://www.example.in/pdf/brochure.pdf"; @mail($pmail, $subjectRep, $messageRep, $headerRep); } } } ?> <!-- end snippet -->

【问题讨论】:

  • 你有什么问题?
  • 谢谢。我只为一个项目附加了这个 PHP 和 html。我的网站中有很多这样的项目,每个项目我都有单独的 PHP 文件。填写表格后,每个项目都有单独的小册子供下载。在 PHP 中,您可以在脚本底部看到我附加的自动回复邮件。因此,通过表单中的隐藏变量,我想发送特定的小册子。请帮帮我!

标签: javascript php jquery html


【解决方案1】:

让我们大致谈谈单词(隐藏).. 我们有 2 个案例

第一种情况:type="hidden" 的输入你可以使用这样的选择器

在css中

input[type="hidden"]{}

在js中

$('input[type="hidden"]') // you can use .val()  or .attr() depending on data you want from it

检查表单是否有隐藏类型的输入

if($('form').find('input[type="hidden"]').length > 0){ // in submit event use $(this).find   instead if $('form').find
   // yes this is input with type hidden here
}else{
   // no input with type hidden here
}

当你说 (取决于隐藏的输入值) 你可以用

if($('form').find('input[type="hidden"]').val() == 'something'){ // in submit event use $(this).find   instead if $('form').find
       // type input hidden value = something
    }else{
       // type input hidden value not = something
    }

第二种情况: :hidden 和 :visible 是关于元素是否可见,我认为您在这里不需要它

【讨论】:

  • 谢谢。我只为一个项目附加了这个 PHP 和 html。我的网站中有很多这样的项目,每个项目都有单独的 PHP 文件。填写表格后,每个项目都有单独的小册子供下载。在 PHP 中,您可以在脚本底部看到我附加的自动回复邮件。因此,通过表单中的隐藏变量,我想发送特定的小册子。请帮帮我!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-20
  • 2011-03-12
  • 1970-01-01
  • 1970-01-01
  • 2014-04-10
相关资源
最近更新 更多