jQuery克隆表单字段丢失广播值 [英] Losing radio values on jQuery cloned form fields

查看:117
本文介绍了jQuery克隆表单字段丢失广播值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PHP表单和邮件功能并不擅长,但是...

我试图建立自己和RSVP表单( http://adrianandemma.com/ )人们可以在其中添加他们的姓名并选择是/否参加。他们还可以点击一个RSVP链接给另一个人。如果点击,这将通过jQuery克隆名称和收音机。



提交表单时,我试图通过电子邮件将详细信息发送给自己。电子邮件目前正在提交,如果我一次收到3个RSPV名称的电子邮件,那么3个名称值将通过电子邮件通过罚款,但我只有第一个人的值是/否回答。



任何人都可以帮助诊断为什么我的克隆单选按钮值不是通过电子邮件发送的吗?

这是我的表单:

 < form action =?方法= POST > 
<?php if(@ $ errors):?>
< p class =errors><?php echo $ errors; ?>< / p为H.
<?php endif; ?>
< input type =hiddenname =submitvalue =1/>
< div class =form-row>
< div class =field-l>
< p>名称< / p>
< / div>
< div class =field-r>
< p>参加?< / p>
< / div>
< / div>
< div class =form-row guest>
< div class =field-l>
< input type =textname =name []id =namevalue =<?php echo htmlspecialchars(@ $ _ REQUEST ['name']);?> tabindex =1/>
< / div>
< div class =field-r>
< input type =radioname =coming []id =coming-yesclass =coming-yesvalue =Yes>< label for =coming-yes >是< / label>< input type =radioname =coming []id =coming-noclass =coming-novalue =No>< label for =coming -no>否LT; /标签>
< / div>
< / div>
< div class =form-row>
< button type =submitid =rsvp-submittabindex =2>提交RSVP< / button>
< / div>
< / form>

...以下是我的PHP邮件代码:

 <?php 

$ name = $ _POST ['name'];
$ coming = $ _POST ['coming'];

$ errors =;
if(!@ $ _ POST ['name']){$ errors。=请输入您的姓名。< br /> gt; \\\
; }
if(!@ $ _ POST ['coming']){$ errors。=请输入yes或no参加。< br /> \\\
; }
$ b $ if if(@ $ _ POST ['emailaddress']!=''){$ spam ='1'; }
$ b $ if(!$ errors&& $ spam!='1')
{
$ to =xxx@example.com;}
$ subject =结婚RSVP;
$ headers =From:noreply@adrianandemma.com;
$ body =以下回复已经通过网站发送。\\\ n; $ $ b $ for $($ i = 0; $ i< count($ _ POST ['name']); $ i ++){
$ body。=
Name。($ i + 1)。:。 $ _POST ['name'] [$ i]。 \\\

Coming。($ i + 1)。:。 $ _POST ['coming'] [$ i]。\\\
\\\
;
}
$ body。=\\\
\\\
Date Received:。日期(j F Y,g:i a)。 \\\
;

邮件($ to,$ subject,$ body,$ headers);
}

?>

我的简单$错误验证也似乎有一个障碍。如果我现在提交表单时没有填写任何内容,它只会向我显示有关空白单选按钮的错误消息,而不是空白的名称字段,不知道为什么这么做?



任何帮助都将非常惊人,因为我正在努力完成这项工作。



感谢:)



...对不起,应该包括这是我通过电子邮件收到的例子,如果我说我收到3个名字的回复:

 以下回复通过网站发送。 


姓名1:戴夫琼斯

来临1:是


姓名2:艾米琼斯

来临2:


姓名3:卡尔琼斯

来临3:


收到日期: 2017年4月16日,下午2:38


解决方案

看看你的 misc.js javascript生成的html,并且 name 属性被设置为 coming [] 1 即将到来[] 2



我建议要么是:
$ b $ 1)将这些保留为即将到来[] ,因此您的请求将有 come 作为数组。然后,您可以使用与 name 相同的索引循环查看。



<2>用 come1 替换来[] coming2 coming3 使用您的jquery,然后在PHP中将这些作为单独的变量处理。


I'm not great with PHP forms and mail functions, but...

I'm trying to build myself and RSVP form (http://adrianandemma.com/) where people can add their name and select yes/no for attending. They can also click a link to RSVP for a further person. If clicked, this clones the name and radios via jQuery.

When the form is submitted I am trying to send the details through to myself via an email. The email is currently submitting and if I receive an email for 3 RSPV names at once, then 3 name values are coming through fine via email, but I only have a value for the first persons yes/no answer.

Can anybody help diagnose why my cloned radio button values aren't being sent via email?

Here's my form:

    <form action="?" method="post">
        <?php if(@$errors) :?>
            <p class="errors"><?php echo $errors; ?></p>
        <?php endif; ?>
        <input type="hidden" name="submit" value="1" />
        <div class="form-row">
            <div class="field-l">
                <p>Name</p>
            </div>
            <div class="field-r">
                <p>Attending?</p>
            </div>
        </div>
        <div class="form-row guest">
            <div class="field-l">
                <input type="text" name="name[]" id="name" value="<?php echo htmlspecialchars(@$_REQUEST['name']); ?>" tabindex="1" />
            </div>
            <div class="field-r">
                <input type="radio" name="coming[]" id="coming-yes" class="coming-yes" value="Yes"><label for="coming-yes">Yes</label><input type="radio" name="coming[]" id="coming-no" class="coming-no" value="No"><label for="coming-no">No</label>
            </div>
        </div>
        <a class="addguest" href="#">Add further guest</a>
        <div class="form-row">
            <button type="submit" id="rsvp-submit" tabindex="2">Submit RSVP</button>
        </div>
    </form>

...and here's my php mail code:

<?php

$name = $_POST['name'];
$coming = $_POST['coming'];

$errors = "";
if(!@$_POST['name'])    { $errors .= "Please enter your name.<br/>\n"; }
if(!@$_POST['coming'])  { $errors .= "Please enter yes or no for attending.<br/>\n"; }

if(@$_POST['emailaddress'] != '')   { $spam = '1'; }

if (!$errors && @$spam != '1')
    {
        $to = "xxx@example.com";
        $subject = "Wedding RSVP";
        $headers = "From: noreply@adrianandemma.com";
        $body = "The following RSVP has been sent via the website.\n\n";
        for($i=0; $i < count($_POST['name']); $i++) {
            $body .= "
            Name ".($i+1)." : " . $_POST['name'][$i] . "\n
            Coming ".($i+1)." : " . $_POST['coming'][$i] ."\n\n";
        }
        $body .= "\n\nDate Received: " . date("j F Y, g:i a") . "\n";

        mail($to,$subject,$body,$headers);
    }

?>

My simple $error validation also seems to have a snag. If i submit the form with nothing filled out at the moment it only shows me the error message regarding the empty radio buttons and not the empty 'name' field, not sure why this is either?

Any help would be really amazing, as I'm struggling to get this finished off.

Thanks :)

...sorry should have included that this is an example of what I'm receiving via email currently if say I receive an RSVP for 3 names:

The following RSVP has been sent via the website.


         Name 1 : Dave Jones

         Coming 1 : Yes


         Name 2 : Amy Jones

         Coming 2 : 


         Name 3 : Carl Jones

         Coming 3 : 


Date Received: 16 April 2017, 2:38 pm

解决方案

I've taken a look at the html being generated by your misc.js javascript and the name attribute is being set to coming[]1,coming[]2.

What i would suggest is either:

1) retaining these as coming[]and therefore your request will have coming as an array. You can then loop through this using the same index as name.

2) Replacing coming[] with coming1,coming2,coming3using your jquery and then dealing with these as separate variables in your PHP.

这篇关于jQuery克隆表单字段丢失广播值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆