Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发送前检查表单中的URL(服务器端)_Javascript_Html_Smarty - Fatal编程技术网

Javascript 发送前检查表单中的URL(服务器端)

Javascript 发送前检查表单中的URL(服务器端),javascript,html,smarty,Javascript,Html,Smarty,我有下面的代码,在服务器端提交之前检查表单,如果可能的话,我想包括检查消息的URL,如果存在,防止消息被发送 if (!empty($_POST['name']) && !empty($_POST['fromemail']) && !empty($_POST['message']) && $go == TRUE) { //data has been filled $name = Filter::no_html($_POST['nam

我有下面的代码,在服务器端提交之前检查表单,如果可能的话,我想包括检查消息的URL,如果存在,防止消息被发送

if (!empty($_POST['name']) && !empty($_POST['fromemail']) && !empty($_POST['message']) && $go == TRUE)
{
    //data has been filled
    $name = Filter::no_html($_POST['name']);
    $from = Filter::no_html($_POST['fromemail']);
    $start_dt = Filter::no_html($_POST['start_dt']);
    $end_dt = Filter::no_html($_POST['end_dt']);
    $comments = Filter::no_html($_POST['message']);
    $validate->isEmpty($name, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_YOUR_NAME);
    $validate->isEmpty($from, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_YOUR_EMAIL);
    $validate->isSingleEmail($from, LANG_JAVASCRIPT_PLEASE_ENTER_EMAIL);
    $validate->isEmpty($start_dt, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_START_DATE);
    $validate->isEmpty($end_dt, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_END_DATE);
    $validate->isEmpty($comments, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_YOUR_MESSAGE);
    $modules->call_hook('contact_owner_submit', ''); // Call any module functions
    $id = (int) @$_POST['ownerid'];
    $vehicle = (int) @$_POST['listingid'];

    if ($validate->isError())
    {

您可以使用stristr方法在消息中搜索字符串中的某些条件:

$has_url = (stristr($comments, 'http') || stristr($comments, 'www.'));
if($has_url) {
  // prevent submit
}
有关stristr方法的更多信息,请参见此处:

因此,您的代码可以如下所示:

if (!empty($_POST['name']) && !empty($_POST['fromemail']) && !empty($_POST['message']) && $go == TRUE) {

  $has_url = (stristr($_POST['message'], 'http') || stristr($_POST['message'], 'www.'));
  if($has_url) {
    // whatever happens if contains url
  }

  $name = Filter::no_html($_POST['name']);
  $from = Filter::no_html($_POST['fromemail']);
  $start_dt = Filter::no_html($_POST['start_dt']);
  $end_dt = Filter::no_html($_POST['end_dt']);
  $comments = Filter::no_html($_POST['message']);
  $validate->isEmpty($name, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_YOUR_NAME);
  $validate->isEmpty($from, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_YOUR_EMAIL);
  $validate->isSingleEmail($from, LANG_JAVASCRIPT_PLEASE_ENTER_EMAIL);
  $validate->isEmpty($start_dt, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_START_DATE);
  $validate->isEmpty($end_dt, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_END_DATE);
  $validate->isEmpty($comments, LANG_JAVASCRIPT_PLEASE_ENTER . " " . LANG_YOUR_MESSAGE);
  $modules->call_hook('contact_owner_submit', ''); // Call any module functions
  $id = (int) @$_POST['ownerid'];
  $vehicle = (int) @$_POST['listingid'];

  if ($validate->isError())
    // whatever goes here
  {
}

嗨,马克,非常感谢你的回复,只是想知道我将如何/在哪里将你提供的内容包含到我的代码中?谢谢你,杰森,你好,杰森。没问题,如果$has\u url为true,那么最好在if语句的顶部放置一个位置,以防止函数进一步运行,并在定义$comments变量之前,在stristr函数中使用$\u POST['message']。嗨,Marc,很抱歉,这是一个难题,但是您认为您可以按照您认为应该的方式发布代码吗,因为我不知道自己该怎么做。再次感谢您宝贵的帮助。JasonHi,Marc,你是一个像符咒一样工作的明星,只是一个想法,还包括URL如果它包含特定的单词,它可以用来不发送消息吗?如果可以,我该如何添加它?非常感谢你对我的帮助。