0

フォームから複数のチェックボックス エントリを送信するのに苦労しています。

カービー CMS とコンタクト フォーム プラグインを使用しています。

誰かがこれに光を当てることができるなら、これは私のコードです。

<fieldset name="check">
    <h2>Project Needs</h2>     
    <ul>
        <li><input id="strategy" type="checkbox" name="needs" value="<?php echo $form->htmlValue('needs') ?> Strategy" checked><label for="strategy">Strategy</label></li>
        <li><input id="ux" type="checkbox" name="needs" value="<?php echo $form->htmlValue('needs') ?> UX"><label for="ux">UX</label></li>
        <li><input id="redesign" type="checkbox" name="needs" value="<?php echo $form->htmlValue('needs') ?> Re-Design"><label for="redesign">Re-Design</label></li>
        <li><input id="responsive" type="checkbox" name="needs" value="<?php echo $form->htmlValue('needs') ?> Responsive Design"><label for="responsive">Responsive Design</label></li>
        <li><input id="cms" type="checkbox" name="needs" value="<?php echo $form->htmlValue('needs') ?> CMS Implementation"><label for="cms">CMS Implementation</label></li>
        <li><input id="unsure" type="checkbox" name="needs" value="<?php echo $form->htmlValue('needs') ?> Unsure"><label for="unsure">Unsure</label></li>
    </ul>
</fieldset>  

上記のコードは正しく、提出ファイルに関係している可能性があります。

<?php

if(!class_exists('Submission'))  require_once('lib/submission.php');
if(!class_exists('Email')) require_once('lib/email.php');

class ContactForm extends Submission {

  public function __construct($params = array()) {

    $this->defaults();

    // set required and wanted fields
    $this->defaults('required', array('name', 'email', 'phone', 'project', 'description', 'budget', 'needs', 'date'));
    $this->defaults('keep',     array('name', 'email', 'phone', 'project', 'description', 'budget', 'needs', 'date'));

    // set the default subject
    $this->defaults('subject', 'Oi, Gaylord.');

    // take the current URL as the default goto URL
    $this->defaults('goto', $_SERVER['REQUEST_URI']);

    // set a custom validation event
    $this->defaults('validate', function($self) {
      // validate the email address    
      if(!filter_var($self->value('email'), FILTER_VALIDATE_EMAIL)) $self->addInvalid('email');
    });

    // try to send the email 
    $this->defaults('submit', function($self) {

      $to   = $self->option('to');
      $from = $self->option('from');

      if(!$from) $self->option('from', $to);

      // set the email body 
      $self->option('body', $self->body());

      // send the email form, pass all options            
      $send = email($self->options);

      if(error($send)) {
        $self->addInvalid('send');
        return $self->trigger('error');
      }

      $self->trigger('success');

    });

    // redirect to the "goto" url on success
    $this->defaults('success', function($self) {
      // redirect to callback url
      go($self->option('goto'));
    });

    // merge the defaults with the given options
    $this->options($params);

    // trigger the request
    $this->trigger('request');

  }

  function body() {

    $body = $this->option('body');

    if(empty($body)) {

      $body = snippet('contact.mail', array(), true);

      if(empty($body)) {
        $body  = 'Name: {name}' . PHP_EOL;
        $body .= '----' . PHP_EOL;
        $body .= 'Email: {email}' . PHP_EOL;
        $body .= '----' . PHP_EOL;
        $body .= 'phone: {phone}' . PHP_EOL;
        $body .= '----' . PHP_EOL;
        $body .= 'project: {project}' . PHP_EOL;
        $body .= '----' . PHP_EOL;
        $body .= 'description: {description}' . PHP_EOL;
        $body .= '----' . PHP_EOL;
        $body .= 'budget: {budget}' . PHP_EOL;
        $body .= '----' . PHP_EOL;
        $body .= 'needs: {needs{}' . PHP_EOL;
        $body .= '----' . PHP_EOL;
        $body .= 'date: {date}' . PHP_EOL;
      }
    }

    foreach($this->data() as $key => $value) {
      $body = str_replace('{' . $key . '}', $value, $body);     
    }    

    return trim($body);

  }

  function htmlBody() {
    return nl2br(html($this->body()));
  }

}
4

2 に答える 2

0

各チェックボックスの名前を一意の名前または「needs[]」に変更します。「needs[]」を使用すると、すべてのチェックボックスが 1 つの配列に転送されます $_POST["needs"]

于 2013-08-27T23:01:18.480 に答える