Jump to content

Checkbox "Article reserved"


rolspace.net
 Share

Recommended Posts

Hi everyone

I have a problem to solve here and I can't get it to work. Kinda new to php and processwire.

This is what I want to do: It's some kind of shop. Article with fields (Title, image, description, price and article_reserved checkbox). I need a foreach line and an if else statement in it. This is the foreach line:

<?php foreach ($pages->get('/shop/')->children() as $article): ?>
           <table class="col-xs-5 col-sm-5 col-md-3 col-lg-3">
          <tr>
            <th class="item"><?php echo $article->title;?></th>
          </tr>
          <tr>
            <td class="item"><a href=""><img class="article-image" src="<?php echo $article->article_image->url;  ?>"></a></td>
            <td class="item"><?php echo $article->article_description; ?></td>
            <td class="item">Size: <?php echo $article->article_size; ?></td>
            <td class="item">Price CHF: <?php echo $article->article_price; ?></td> 
            <td class="button"><button type="button" class="btn btn-primary btn-sm">Order</button></td>
       </table>    
       <?php endforeach; ?>

When the article is checked as "reserved" (field: article_reserved), then there should be a class .reserved added to the image tag. if not, then not.

Any ideas?

Thanks.

 

Screenshot 2016-09-03 14.33.41.png

Link to comment
Share on other sites

[...]
<td class="item"><a href=""><img class="article-image<?php echo ($article->article_reserved == 1) ? ' reserved' : '';  // 1 = checked, 0 = unchecked ?>" src="<?php echo $article->article_image->url;  ?>"></a></td>
[...]

 

  • Like 5
Link to comment
Share on other sites

Hello there, I have an additional request to the above one. I have changed the shop a bit (due to time an knowledge issues). I have added an order form. The idea is, when the article's checkbox is clicked and the form filled in, an email will be sent to the owner of the site. Now, the tricky thing is, he needs to know, which article he has to send out.

This is my code so far:

<div id="shop" class="inner">
  <div class="row">
   <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
   <h1  class="title col-xs-12 col-sm-12 col-md-12 col-lg-12"><?= $pages->get('/shop/')->title ?></h1>
   <div class="moredistance col-xs-12 col-sm-12 col-md-12 col-lg-12"><?= $pages->get('/shop/')->shop_rules ?></div>
    </div>
    
   <div class="moredistance articles col-xs-12 col-sm-12 col-md-12 col-lg-12">    
        <?php foreach ($pages->get('/shop/')->children() as $article): ?>
        <div class="col-xs-6 col-sm-6 col-md-3 col-lg-3">
           <table class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
          <tr>
            <th class="item"><?php echo $article->title;?></th>
          </tr>
          <tr>
            <td class="item gallery">
                <a href="<?php echo $article->article_image->url;  ?>" data-lightbox="shop">
                    <img class="article-image<?php             
                                echo ($article->article_reserved == 1) ? ' reserved' : '';  // 1 = checked, 0 = unchecked ?>" src="<?php echo $article->article_image->url;  ?>"></a>
            </td>
            <td class="item"><?php echo $article->article_description; ?></td>
            <td class="item">Size: <?php echo $article->article_size; ?></td>
            <td class="item">Price CHF: <?php echo $article->article_price; ?></td>
            <td class="item"></td>
            <td class="button">
              
               <label><input type="checkbox" id="checkbox" <?php             
                echo ($article->article_reserved == 1) ? ' disabled' : ''; ?> class="checkbox style-2 pull-right  ">I want this!&nbsp;
                </label>
            </td>
       </table>  
       </div>     
       <?php endforeach; ?>
   </div>
   <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
   <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"><?= $pages->get('/shop/')->shop_payment ?></div>
   <div id="contactResponse" class="col-xs-12 col-sm-12 col-md-6 col-lg-6"></div>
   <div class="moredistance orderform col-xs-12 col-sm-12 col-md-6 col-lg-6">
       
       <form role="form" id="frmContact" class="" method="post" action="<?php echo $config->urls->templates?>mailer.php">
          <div class="form-group">
            <label for="fullname">Name:</label>
            <input type="text" class="form-control" name="fullname" id="fullname" required>
          </div>
          <div class="form-group">
            <label for="address">Address:</label>
            <input type="text" class="form-control" name="address" id="address" required>
          </div>
          <div class="form-group">
            <label for="email">Email:</label>
            <input type="email" class="form-control" name="email" id="email" required>
          </div>
          <div class="form-group">
            <label for="telephone">Telephone:</label>
            <input type="tel" class="form-control" name="telephone" id="telephone" required>
          </div>
          <button type="submit" class="btn btn-warning" name="action" id="submitBtn">Buy</button>
       </form>
      </div>
</div>
</div>
</div>

you can have a look at the site in progress HERE.

I was thinking of adding an empty field to the form, where the article(s) would show up as soon as there's a checked box and then sent with the other information by POST. Or is that a stoopid idea?

Thanks

 

Link to comment
Share on other sites

You could simply add the size of the article (I mean, a t-shirt (the article) and XL (the size)) in the title of the select/option by concatenating your fields (article_title and article_size) and include in the email the value of the <select>/<option> element , so your client can see in his email a line with the correct item bought.

I dont see in your code the select/option HTML element which is appearing on the website.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...