0

予約を行うための joomla コンポーネントがあり、予約の開始日用のチェックボックスがあります...私の問題は、一度に 1 つの予約しかできないことです。複数のボックスをチェックできるようにしたいので、それらのボックスの値複数のチェックボックスをチェックすると、最後にチェックしたものだけがデータベースに保存されます...

これは、調整する必要があると思うjoomlaコンポーネントのコードです。できれば助けてください...

これはチェックボックスのコードです...

$timetableHTML .= '<td class="timeSlot timeFree" ><input type="checkbox" name="appointment[]" value="'.$startKey.'" onclick="changeTimes(\''.$calendar->min_duration.'\',\''.$startKey.'\',\''.$endKey.'\')"/></td>';

これは、コンポーネントのコントローラーの保存機能です...

function save() {
    global $app;
    JRequest::checkToken() or jexit( 'Invalid Token' );

    $db =& JFactory::getDBO();
    $row =& JTable::getInstance('appointments', 'Table');
    $post   = JRequest::get( 'post',4 );
    if (!$row->bind( $post )) { JError::raiseError(500, $row->getError() ); }
    for ($i=1;$i<=10;$i++) {
        if (is_array($row->{'field'.$i})) $row->{'field'.$i} = implode('|',$row->{'field'.$i}); $row->{'field'.$i} = strip_tags($row->{'field'.$i});
    }
    if (!$row->check()) { JError::raiseError(500, $row->getError() ); }
    if (!$row->store()) { JError::raiseError(500, $row->getError() ); }
    $row->checkin();

            if ($this->config->emails){
                $this->notifyOwner(array($row->id));
                $this->notifyAppointee(array($row->id));
            }

            $url = JRoute::_('index.php?option=com_jxtcappbook'.(JRequest::getInt( 'pop', 0) ? '&view=complete&tmpl=component' : ''));
    $this->setRedirect($url ,JText::_( 'Termin je zakazan!'.$pop ));
}

私は少しググって、配列でjrequest::getを設定する必要があると思います、そうですか?

4

1 に答える 1

0

Joomla>1.6と仮定します。JRequestかなりの量を使用しているので:

$appointments = JRequest::getVar('appointments', null, 'post', 'array');

これは3.0以降で非推奨になるため、JInputを使用できます。

$jinput = JFactory::getApplication()->input;
$appointments = $jinput->post->get('appointments', 'null', 'ARRAY');

入力をサニタイズしてDBに追加します。

foreach (array_keys($appointments ) as $element) {
    $myappointments[] = $db->quote($element);
}


// construct query using implode and use comma separator
$myappointments = implode(',', $myappointments );
$db =& JFactory::getDBO();
$query  = $db->getQuery(true);
$query = sprintf('UPDATE $db->quoteName(#__mytable) SET $db->quote(...) WHERE $db->quote(...) IN (%s)', $myappointments );
$db->setQuery($query);
$db->query();

あなたはアイデアを得る...

編集(あなたのコメントに基づく):

私はあなたが何を達成しようとしているのかまだわかりません。ですから、方向性を示すのは難しいです。私はそれをもう一度刺します。フォームからチェックされた値を取得してデータベースに入れたいと思います。

//this pulls out the values in an array of all the things that have been "checked" (selected in the checkbox)
$jinput = JFactory::getApplication()->input;
$appointments = $jinput->post->get('appointments', 'null', 'ARRAY');

//**This is not code you need** I just want to illustrate what you are getting.
//This is looping through the values of the checkboxes to see what you have
for($i=0; $i < count($appointments); $i++){
    echo "Selected " . $appointments[$i];
}

前に提供したコードは、値を取得してDBに格納する方法を示しています。DBの構造がわからないので、DBに指示を出すことができません。

于 2013-02-28T01:57:51.690 に答える