将必填字段更改为可选

时间:2015-05-04 06:55:41

标签: php forms

我的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' );

正如我所说 - 我只想将EMAIL字段从强制更改为可选

如何更改?

由于

1 个答案:

答案 0 :(得分:-1)

我假设它是强制性的,因为PHP代码正在检查提交的数据,因为此HTML代码中没有任何内容将其定义为必填字段。

所以你需要向我们展示处理它的PHP。

它可能类似于:

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

您只需删除相关部分。