js form not submitting, How to activate it.

js form not submitting, How to activate it.

Hi, I have searched and some people also stuck in this, i am not able to submit the form, I have changed php file, now using simple php mail function which i have mentioned in the code. Any help please, How to activate it.

  1. //forms
  2. ;(function($){
  3. $.fn.forms=function(o){
  4. return this.each(function(){
  5. var th=$(this)
  6. ,_=th.data('forms')||{
  7. errorCl:'error',
  8. emptyCl:'empty',
  9. invalidCl:'invalid',
  10. notRequiredCl:'notRequired',
  11. successCl:'success',
  12. successShow:'4000',
  13. mailHandlerURL:'js/test.php',
  14. ownerEmail:'owltemplates.com@gmail.com',
  15. stripHTML:true,
  16. smtpMailServer:'localhost',
  17. targets:'input,textarea',
  18. controls:'a[data-type=reset],a[data-type=submit]',
  19. validate:true,
  20. rx:{
  21. ".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
  22. ".state":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
  23. ".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},
  24. ".phone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
  25. ".fax":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
  26. ".message":{rx:/.{20}/,target:'textarea'}
  27. },
  28. preFu:function(){
  29. _.labels.each(function(){
  30. var label=$(this),
  31. inp=$(_.targets,this),
  32. defVal=inp.val(),
  33. trueVal=(function(){
  34. var tmp=inp.is('input')?(tmp=label.html().match(/value=['"](.+?)['"].+/),!!tmp&&!!tmp[1]&&tmp[1]):inp.html()
  35. return defVal==''?defVal:tmp
  36. })()
  37. trueVal!=defVal
  38. &&inp.val(defVal=trueVal||defVal)
  39. label.data({defVal:defVal})
  40. inp
  41. .bind('focus',function(){
  42. inp.val()==defVal
  43. &&(inp.val(''),_.hideEmptyFu(label),label.removeClass(_.invalidCl))
  44. })
  45. .bind('blur',function(){
  46. _.validateFu(label)
  47. if(_.isEmpty(label))
  48. inp.val(defVal)
  49. ,_.hideErrorFu(label.removeClass(_.invalidCl))
  50. })
  51. .bind('keyup',function(){
  52. label.hasClass(_.invalidCl)
  53. &&_.validateFu(label)
  54. })
  55. label.find('.'+_.errorCl+',.'+_.emptyCl).css({display:'block'}).hide()
  56. })
  57. _.success=$('.'+_.successCl,_.form).hide()
  58. },
  59. isRequired:function(el){
  60. return !el.hasClass(_.notRequiredCl)
  61. },
  62. isValid:function(el){
  63. var ret=true
  64. $.each(_.rx,function(k,d){
  65. if(el.is(k))
  66. ret=d.rx.test(el.find(d.target).val())
  67. })
  68. return ret
  69. },
  70. isEmpty:function(el){
  71. var tmp
  72. return (tmp=el.find(_.targets).val())==''||tmp==el.data('defVal')
  73. },
  74. validateFu:function(el){
  75. el.each(function(){
  76. var th=$(this)
  77. ,req=_.isRequired(th)
  78. ,empty=_.isEmpty(th)
  79. ,valid=_.isValid(th)
  80. if(empty&&req)
  81. _.showEmptyFu(th.addClass(_.invalidCl))
  82. else
  83. _.hideEmptyFu(th.removeClass(_.invalidCl))
  84. if(!empty)
  85. if(valid)
  86. _.hideErrorFu(th.removeClass(_.invalidCl))
  87. else
  88. _.showErrorFu(th.addClass(_.invalidCl))
  89. })
  90. },
  91. getValFromLabel:function(label){
  92. var val=$('input,textarea',label).val()
  93. ,defVal=label.data('defVal')
  94. return label.length?val==defVal?'nope':val:'nope'
  95. }
  96. ,submitFu:function(){
  97. _.validateFu(_.labels)
  98. if(!_.form.has('.'+_.invalidCl).length)
  99. $.ajax({
  100. type: "POST",
  101. url:_.mailHandlerURL,
  102. data:{
  103. name:_.getValFromLabel($('.name',_.form)),
  104. email:_.getValFromLabel($('.email',_.form)),
  105. phone:_.getValFromLabel($('.phone',_.form)),
  106. fax:_.getValFromLabel($('.fax',_.form)),
  107. state:_.getValFromLabel($('.state',_.form)),
  108. message:_.getValFromLabel($('.message',_.form)),
  109. owner_email:_.ownerEmail,
  110. stripHTML:_.stripHTML
  111. },
  112. success: function(){
  113. _.showFu()
  114. }
  115. })
  116. },
  117. showFu:function(){
  118. _.success.slideDown(function(){
  119. setTimeout(function(){
  120. _.success.slideUp()
  121. _.form.trigger('reset')
  122. },_.successShow)
  123. })
  124. },
  125. controlsFu:function(){
  126. $(_.controls,_.form).each(function(){
  127. var th=$(this)
  128. th
  129. .bind('click',function(){
  130. _.form.trigger(th.data('type'))
  131. return false
  132. })
  133. })
  134. },
  135. showErrorFu:function(label){
  136. label.find('.'+_.errorCl).slideDown()
  137. },
  138. hideErrorFu:function(label){
  139. label.find('.'+_.errorCl).slideUp()
  140. },
  141. showEmptyFu:function(label){
  142. label.find('.'+_.emptyCl).slideDown()
  143. _.hideErrorFu(label)
  144. },
  145. hideEmptyFu:function(label){
  146. label.find('.'+_.emptyCl).slideUp()
  147. },
  148. init:function(){
  149. _.form=_.me
  150. _.labels=$('label',_.form)

  151. _.preFu()
  152. _.controlsFu()
  153. _.form
  154. .bind('submit',function(){
  155. if(_.validate)
  156. _.submitFu()
  157. else
  158. _.form[0].submit()
  159. return false
  160. })
  161. .bind('reset',function(){
  162. _.labels.removeClass(_.invalidCl)
  163. _.labels.each(function(){
  164. var th=$(this)
  165. _.hideErrorFu(th)
  166. _.hideEmptyFu(th)
  167. })
  168. })
  169. _.form.trigger('reset')
  170. }
  171. }
  172. _.me||_.init(_.me=th.data({forms:_}))
  173. typeof o=='object'
  174. &&$.extend(_,o)
  175. })
  176. }
  177. })(jQuery)
  178. $(window).load(function(){
  179. $('#form1').forms({
  180. ownerEmail:'owltemplates.com@gmail.com'
  181. })
  182. })