使用jQuery和PHP检查验证码(Checking captcha with jQuery and PHP)

我正在编写动态联系表格。 代码如下所示:
jQuery的:

$.ajax({
    type: "POST",
    url: "sendmail.php",
    data: {email: email, message: message, captcha: captcha}
})
.done(function( result ) {
    alert(result);
})

PHP:

<?php
    session_start();
    $email = $_POST['email'];
    $message = $_POST['message'];
    $captcha = $_POST['captcha'];

    if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&strtoupper($_SESSION["captcha_code"])==strtoupper($_POST["captcha"]))
    {
        @mail('mymail@gmail.com', 'Subject', $message, 'From:' . email);
        echo "Message successfully sent.";
    }
    else
    {
        // change opacity of #error div
    }
?>

问题是如果输入了错误的验证码,如何更改隐藏div的不透明度? 在这种情况下,我需要在PHP脚本或其他地方插入此代码:

$('#error').css({opacity:'1'}); 

请记住,我不能用echo注入代码,因为我使用alert来提供从PHP脚本返回的信息。


I'm coding dynamic contact form. The code look like this:
jQuery:

$.ajax({
    type: "POST",
    url: "sendmail.php",
    data: {email: email, message: message, captcha: captcha}
})
.done(function( result ) {
    alert(result);
})

PHP:

<?php
    session_start();
    $email = $_POST['email'];
    $message = $_POST['message'];
    $captcha = $_POST['captcha'];

    if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&strtoupper($_SESSION["captcha_code"])==strtoupper($_POST["captcha"]))
    {
        @mail('mymail@gmail.com', 'Subject', $message, 'From:' . email);
        echo "Message successfully sent.";
    }
    else
    {
        // change opacity of #error div
    }
?>

The problem is how to change opacity of hidden div if wrong captcha code has been entered? In that case I need to insert this code insid PHP script or somewhere else:

$('#error').css({opacity:'1'}); 

Remember, that I cannot inject code with echo, because I use alert for information coming back from PHP script.


原文:https://stackoverflow.com/questions/17845398
2023-01-21 13:01

满意答案

将字段分隔符(-F)更改为选项卡:

$ awk -F$'\t*' '{gsub(/ /,"_",$1); print $1,$2}' test2.in
Joe_Jonas 8
Cersei_Lann 4
Bo_Tox 6
Mis_Ter_Yo 7

编辑:在第一列使用gsub用下划线替换空格。


Change the field separator (-F) to tab(s):

$ awk -F$'\t*' '{gsub(/ /,"_",$1); print $1,$2}' test2.in
Joe_Jonas 8
Cersei_Lann 4
Bo_Tox 6
Mis_Ter_Yo 7

EDIT: Use gsub on first column to replace space with underscore.

相关问答

更多

AWK使用多个空格作为分隔符(AWK to use multiple spaces as delimiter)

awk支持正则表达式作为FS的值,因此您可以指定至少匹配两个空格的正则表达式。 类似于-F '[[:space:]][[:space:]]+' 。 $ awk '{print NF}' File2 4 3 4 $ awk -F '[[:space:]][[:space:]]+' '{print NF}' File2 3 3 3 awk supports a regular expression as the value of FS so you can specify a regular ex...

使用空格作为具有剪切命令的分隔符(use space as a delimiter with cut command)

cut -d ' ' -f 2 其中2是您想要的空格分隔字段的字段编号。 cut -d ' ' -f 2 Where 2 is the field number of the space-delimited field you want.

拆分制表符分隔的空格列(Split tab delimited column with space)

您可以再次用space split 1列,并打印第1列的部分,请尝试: awk -F'\t' '{split($1, c, " "); print c[1] "\t" $2 "\t" $3}' clicksInfo.txt You can split column 1 again with space and print the first part of it, try: awk -F'\t' '{split($1, c, " "); print c[1] "\t" $2 "\t" $3}' ...

awk命令:如何告诉它区分空格和制表符分隔符(awk command: how to tell it to distinguish between space and tab delimiter)

将字段分隔符(-F)更改为选项卡: $ awk -F$'\t*' '{gsub(/ /,"_",$1); print $1,$2}' test2.in Joe_Jonas 8 Cersei_Lann 4 Bo_Tox 6 Mis_Ter_Yo 7 编辑:在第一列使用gsub用下划线替换空格。 Change the field separator (-F) to tab(s): $ awk -F$'\t*' '{gsub(/ /,"_",$1); print $1,$2}' test2.in Jo...

读取行时,awk $行有多个分隔符(While read line, awk $line with multiple delimiters)

问题不在于FS的值,而是由错误指出的这一行: f = "Alignments_" $5 ".sam" print > f 你在一行上有两个陈述,所以要么用a分开; 或换行符: f = "Alignments_" $5 ".sam"; print > f 要么: f = "Alignments_" $5 ".sam" print > f 作为一个完整的班轮: awk -F '[:\t]' 'FNR==NR{n[$1];next}$5 in n{print > ("Alignmen...

awk:通过特定的分隔符删除字符串(awk: remove strings by specific delimiter)

只需使用$2上的POSIX兼容split()函数即可 awk '{split($2,temp,":"); $2=temp[2];}1' file --- 16050075 16050075 A G --- 16050115 16050115 G A --- 16050213 16050213 C T --- 16050319 16050319 C T --- 16050527 16050527 C A 在解除限制器上拆分第2列: ,将$2值更新为所需的元素( temp[2] )并打印剩余的字段(...

在mule esb中使用DataMapper使用自定义分隔符(空格或制表符)编写CSV文件(Writing CSV file using custom Delimiter (space or tab) using DataMapper in mule esb)

创建CSV输出格式时可以选择分隔符。 您可以通过属性视图的输出映射区域上的“打开属性”按钮来更改它。 通过这些,您可以存档以使用选项卡作为分隔符。 我试图使用空格作为分隔符,但我无法通过使用用户界面来完成,但我通过修改映射文件(映射/ XXX.grp)获得了成功: <Record fieldDelimiter=" " name="OUTPUT_FORMAT_NAME" 最好的问候,何塞 You can chose the delimiter when creating the CSV outpu...

如何使用Netezza NZSQL中的制表符分隔符输出文件(How to output a file using tab delimiter in Netezza NZSQL)

要将制表符指定为分隔符,请将$与-F选项结合使用。 nzsql -o sample.txt -F $'\t' -A -t -c "SELECT * FROM DW_ETL.USER WHERE datasliceid % 20 = 2 LIMIT 5;" 这在nzsql -h输出中有记录。 nzsql -h This is nzsql, the IBM Netezza SQL interactive terminal. Usage: nzsql [options] [security...

从Google文档电子表格粘贴时获取不一致的制表符分隔符宽度(Getting inconsistent tab delimiter width when pasting from Google docs spreadsheet)

出于某种原因,代码编辑器实际上没有正确显示选项卡。 使用正则表达式和另一个代码编辑器(vim)显示所有这些都是实际的选项卡。 :) For some reason, it was the code editor that was actually not showing the tabs right. Using a regexp and another code editor (vim) showed that all of them were actual tabs. :)

awk如何将记录分隔符设置为多个连续的空行或行仅包含空格和/或制表符?(awk how to set record separator as multiple consecutive empty lines or lines only include space and/or tab characters?)

这是一种方法: awk '!NF {$0=""}1' file | awk -v RS="" '{print NR,$0}' 第一个awk计算该行上的字段。 如果您有空行或仅包含空格和制表符的行,则此0 。 然后它只是将行更改为空。 在此之后你可以使用RS="" 这是一个gnu awk版本(由于RS中的多个字符): awk -v RS="\n([[:space:]]*\n)+" '{print NR,$0}' file 它可以在没有括号的情况下工作,但我不确定是否所有内容都将被覆盖: awk ...

相关文章

更多

jquery 问题

[color=green] [size=medium][size=small][size=medium ...

Jquery EasyUI系列教程1

大家好,最近网上发现在做前端框架比较多,各种各的特色,经过笔者苦思纠结,最终选择了Jquery Eas ...

jQuery表格插件jqGrid(jquery.jqGrid.js)

jqGrid 是一个用来显示网格数据的jQuery插件,文档比较全面,附带中文版本,支持分页、滚动加载 ...

jQuery实战经典视频教程

PHP学习一本通.pdf PHP公益培训第3部-130-jquery插件返回值细节.wmv PHP公益 ...

《自学it网-PHP公益培训-YY直播中[24小时供源]-(4月9日更新)-PHP项目实战 mysql smarty thinkphp javascript ajax jquery linux lamp》[WMV]

中文名: 自学it网-PHP公益培训-YY直播中[24小时供源]-(4月9日更新)-PHP项目实战 m ...

PHP简介

PHP PHP是运行在服务器端的脚本,可以运行在UNIX、LINUX、WINDOWS、Mac OS下 ...

jQuery中$与$()的区别?

jQuery中$与$()的区别?

php匹配问题

文章内容:我是中国人,我喜欢上javaeye 填写的标签:中国 显示的效果是:我是 &lt;a h ...

《后盾网盾友 JQuery 视频教程 》(JQuery )更新至30课[WMV]

中文名: 后盾网盾友 JQuery 视频教程 英文名: JQuery 别名: JQuery ...

用jquery validate封装自己的验证库

如果一个项目中多个地方要验证,例如登录、注册等,每个页面都写验证代码,相当的痛苦,那这节就是用jque ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本