M
M
mydarck2015-05-22 13:21:35
PHP
mydarck, 2015-05-22 13:21:35

Modx revo. How to submit a form without a submit button using ajax?

The site is dedicated to photo and video shooting and has the following structure:
Our works
|__Wedding
| |__Photo
| | |__Wedding photos of Anton and Peter: ) (resource containing photos)
| |__Video
| |__Video from wedding photos of Anton and Peter: )
|__Wedding
|__etc.
The "Our works" section is going to have a filter of the following nature: a
radio switch between the photo and video sections and a select with the name of the parent resource (for example, "Wedding"). By default, all child resources of the photo and video sections are displayed. I output using getPage:

[

where &parents contains ids of all photo and video sections. By clicking on the "photo" radio switch, I thought to make it so that the & parents parameter changed the id of all parent sections to the id of only the Photo or video section, dynamically without reloading the page, depending on the selected radio switch. If the select is used in parallel, i.e. For example, the "Wedding" section and the "Photo" radio are selected, then the value of the &parents parameter is narrowed down to one id and a selection is made on it. As such, there is no "submit" button, it turns out that the submit event should occur immediately upon clicking on the button or on selecting a section in the select.
Can this be done with ajax.
I enclose the markup of the form and the code of the approximate selection:
Forta - filter
<form action="" method="post" id="select-type-service">
  <div class="container">
    <div class="row">
      <div class="col-lg-4">
        <div class="jq-radio-photo">
          <input type="radio" name="photo-radio" class="photo-radio" />
          <p>Фотографии</p>
        </div>
      </div>
      <div class="col-lg-4">
        <div class="jq-radio-video">
          <input type="radio" name="video-radio" class="video-radio" />
          <p>Видеосъемка</p>
        </div>
      </div>
      <div class="col-lg-4">
        <select class="selectpicker" data-width="100%" name="service[]">
             <option value="4">Все разделы</option>
             <option value="23">свадьба</option>
             <option value="26">Корпоратив</option>
             <option value="29">Венчание</option>
             <option value="32">Выписка из роддома</option>
             <option value="35">Крестины</option>
             <option value="38">Детский сад</option>
             <option value="41">Школьные годы</option>
             <option value="44">Студийное фото</option>
             <option value="47">Фотопрогулки</option>
        </select>
      </div>
    </div>
  </div>
</form>

Sample snippet
<?php
if ( $_POST['service'][0] == 4 && empty($_POST['photo-radio']) && empty($_POST['video-radio'])){
$allRes = '24, 25, 27, 28, 31, 30, 34, 33, 37, 36, 39, 40, 43, 42, 46, 49';
} elseif ( $_POST['service'][0] == 4 && isset($_POST['photo-radio']) && empty($_POST['video-radio']))  {

$resources = $modx->getCollection('modResource',array('alias' => 'video'));
foreach ($resources as $k => $res) {
  $videoId .= $res->get('id'). ', ';
}
$videoRes = rtrim($videoId, ", ");
} elseif ($_POST['service'][0] == 4 && empty($_POST['photo-radio']) && isset($_POST['video-radio'])) {

$resources = $modx->getCollection('modResource',array('alias' => 'foto'));
foreach ($resources as $k => $res) {
  $photoId .= $res->get('id'). ', ';
}
$photoRes = rtrim($photoId, ", ");

}
?>

ps Two requests: Do not judge strictly and Help, please, bring to mind.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question