2015-05-04 57 views
0

我的PHP知识有限,我需要更改表单中的字段 - 从强制到可选 - EMAIL FIELD将必填字段更改为可选

下面是函数代码:

function apostherapy_leads_form($options) { 

$defaults = array(
'id'   => 'frmLead' . rand(10, 99), 
'title'  => '', 
'msg_success' => 'תודה רבה', 
'msg_failure' => 'אירעה שגיאה. נא לנסות שוב. תודה', 
'url'   => 'http://leads.apostherapy.co.il/api/receiver.asp', 
'campaign'  => '', 
'source'  => get_bloginfo('name', 'display'), 
'url_success' => '', 
'url_failure' => '', 
'placeholders' => false, 
'with_join' => false, 
'ajax'   => true, 
'label_name' => 'שם מלא', 
'label_phone' => 'טלפון', 
'label_email' => 'אימייל', 
'label_join' => 'הנני מאשר קבלת חומר פרסומי מאפוסתרפיה', 
'label_send' => 'שלח', 
); 

$defaults['name'] = $defaults['id']; 
$options = !empty($options) ? array_merge($defaults, $options) : $defaults; 
ob_start(); 

if (!empty($options['title'])): ?><h2><?= $options['title'] ?></h2><?php endif; ?> 
<div class="leads<?php if ($options['ajax']): ?> ajax<?php endif; ?>"> 
<p class="success"><?= $options['msg_success'] ?></p> 
<p class="failure"><?= $options['msg_failure'] ?></p> 
<form id="<?= $options['id'] ?>" name="<?= $options['name'] ?>" action="<?= $options['url'] ?>" method="post"> 
    <input type="hidden" id="nCampaignID" name="nCampaignID" value="<?= $options['campaign'] ?>"> 
    <input type="hidden" id="sSource" name="sSource" value="<?= $options['source'] ?>"> 
    <?php if (!empty($options['url_success'])): ?><input type="hidden" id="sSuccessRedirURL" name="sSuccessRedirURL" value="<?= $options['url_success'] ?>"><?php endif; ?> 
    <?php if (!empty($options['url_failure'])): ?><input type="hidden" id="sFailedRedirURL" name="sFailedRedirURL" value="<?= $options['url_failure'] ?>"><?php endif; ?> 

    <p> 
    <?php if (!$options['placeholders']): ?><label for="sFullName"><?= $options['label_name'] ?></label><?php endif; ?> 

    <input name="sFullName"<?php if (!$options['placeholders']): ?> id="sFullName"<?php endif; ?> type="text" value="" maxlength="30"<?php if ($options['placeholders']): ?> placeholder="<?= $options['label_name'] ?><?php endif; ?>"> 
    </p> 
    <p> 
    <?php if (!$options['placeholders']): ?><label for="sPhone"><?= $options['label_phone'] ?></label><?php endif; ?> 
    <input name="sPhone"<?php if (!$options['placeholders']): ?> id="sPhone"<?php endif; ?> type="tel" value="" maxlength="11"<?php if ($options['placeholders']): ?> placeholder="<?= $options['label_phone'] ?><?php endif; ?>"> 
    </p> 
    <p> 
    <?php if (!$options['placeholders']): ?><label for="sEmail"><?= $options['label_email'] ?></label><?php endif; ?> 

    <input name="sEmail"<?php if (!$options['placeholders']): ?> id="sEmail"<?php endif; ?> type="email" value="" maxlength="50"<?php if ($options['placeholders']): ?> placeholder="<?= $options['label_email'] ?><?php endif; ?>"> 
    </p> 
    <p> 
    <input type="submit" class="clsButton" value="<?= $options['label_send'] ?>"> 
    <?php if ($options['with_join']): ?><label for="sComments" class="join-newsletter"><input type="checkbox"checked='checked' name="sComments"<?php if (!$options['placeholders']): ?> id="sComments"<?php endif; ?> value="הירשם לניוזלטר קבל עדכונים למייל"><span><?= $options['label_join'] ?></span></label><?php endif; ?> 
    </p> 
</form> 
</div> 
<?php 
return ob_get_clean(); 
} 
add_shortcode('leads_form', 'apostherapy_leads_form'); 

正如我所说的 - 我只是想电子邮件字段从强制改为可选

我怎样才能改变呢?

感谢

+2

该字段是必填字段? –

+0

也请包括处理html元素的代码。那么我们可以让它成为可选的。让我们看看代码 –

+0

嗨 - 我更新了我的问题,包括完整的功能 - 我希望它能帮助你 - 谢谢 – Yaron123

回答

-1

我假设它是因为这是检查提交的数据的PHP代码,因为没有在这个HTML代码是将其定义为必填字段是强制性的。

因此,您需要向我们展示处理它的PHP。

这可能是这样的:

if(!isset($_POST['sEmail'])){echo "error";} 

你只是删除相关部分。

+0

你怎么这么确定? –

+0

我从来没有说过,我确信它,我说“我假设”。我需要看看是什么导致这个字段是强制性的,因为它不是这个代码,对吗? –

+0

你不应该在这里假设。 –