mardi 27 juin 2017

Error when checkbox not checked in php mysql form

The checkbox in my form works to put in a true value (1) when the checked and otherwise, the value for the column is false (0).. however, when I run the form without the checkbox checked it gives me this error -

"Notice: Undefined index: publish in C:\xampp\htdocs\phpoop\create_product.php on line 37"

Here is the Product class for creating the product (only including the publish variable)

class Product{

    // database connection and table name
    private $conn;
    private $table_name = "products";

    // object properties
      public $publish;


    public function __construct($db){
        $this->conn = $db;
    }

    // create product
    function create(){

        //write query
        $query = "INSERT INTO
                    " . $this->table_name . "
                SET
                    publish=:publish";

        $stmt = $this->conn->prepare($query);

        // posted values
        $this->publish=htmlspecialchars(strip_tags($this->publish));

        // to get time-stamp for 'created' field
        $this->timestamp = date('Y-m-d H:i:s');
        $this->timestamp2 = date('Y-m-d H:i:s');

        // bind values 
        $stmt->bindParam(":publish", $this->publish);


        if ($stmt->execute()){
            return true;    

        }else{
            return false;
        }

    }

and this is where the form is located for creating the product

// if the form was submitted 
if ($_POST){

    // set product property values
    $product->publish = $_POST['publish'];

    if(isset($_POST['publish'])){
    $published = $_POST['publish'];
    }
    else{
        $published = 0;
    }

    // create the product
    if($product->create()){
        echo "<div class='alert alert-success'>Product was created.</div>";
    }


}

?>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
  <input type="checkbox" name="publish"  value="1" class="form-control" <?php if(isset($_POST['publish'])) echo "checked='checked'";?>/>
  <button type="submit" class="btn btn-primary">Create Product</button>
 </form>




How do I save my checkbox tick to local storage

My question is how do I save the checkbox so that when i reopen or reload the page it stays like that for example when i tick it, it stays tick and when i untick it it stays untick

what i have so far:

html>

head>

title>MY DATABASE/title>

meta charset="UTF-8">

style>

        #myInput {
            background-image: url('http://ift.tt/2shp6Na');
            background-position: 10px 10px;
            background-repeat: no-repeat;
            width: 100%;
            font-size: 16px;
            padding: 12px 20px 12px 40px;
            border: 1px solid #ddd;
            margin-bottom: 12px;
        }

        #myTable {
            border-collapse: collapse;
            width: 100%;
            border: 1px solid #ddd;
            font-size: 18px;
        }

        #myTable th, #myTable td {
            text-align: left;
            padding: 12px;
        }

        #myTable tr {
            border-bottom: 1px solid #ddd;

        }

        #myTable tr.header, #myTable tr:hover {
            background-color: #f1f1f1;

        }

        * {
            box-sizing: border-box;
        }
</style>

/head>

body>

<h2>DATABASE</h2>

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for an name.." title="Type in an name">

<table id="myTable">
    <tr class="header">
        <th style="width:60%;">Anime</th>
        <th style="width:40%;">Email</th>
        <th style="width:auto;">PTW</th>
    </tr>
    <tr>
        <td>name1</td>
        <td>email1</td><td><input type="checkbox" id="checkbox" class="checkbox"></td>
    </tr>
    <tr>
        <td>name2</td>
        <td>email2</td><td><input type="checkbox" id="checkbox" class="checkbox"></td>
    </tr>
    <tr>
        <td>name3</td>
        <td>email3</td><td><input type="checkbox" id="checkbox" class="checkbox"></td>
    </tr> 
    </table>
    <!--Search Filter-->
    <script>
        function myFunction() {
          var input, filter, table, tr, td, i;
          input = document.getElementById("myInput");
          filter = input.value.toUpperCase();
          table = document.getElementById("myTable");
          tr = table.getElementsByTagName("tr");
          for (i = 0; i < tr.length; i++) {
            td = tr[i].getElementsByTagName("td")[0];
            if (td) {
              if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                tr[i].style.display = "";
              } else {
                tr[i].style.display = "none";
              }
            }
          }
        }
    </script>
    <script>
enter code for saving checkboxes here
    </script>
</body>
</html>

PS a working version of this on https://54x1.github.io/




Is it possible to combine several (form) search fields into one with checkboxes and/or dropdown?

I am using my own starting page for my browsers. This page is used by myself only (and some friends and family). Which contains news, weather, links and such.

Also this page includes several search fields, like Google, Usenet, forumsearch (on a favourite website) and a subtitles search field. Ofcourse each search field uses different queries for different sites.

Now as I am redoing the starting page, I am wondering if it's possible to create just one search field and use checkboxes to select the page I want to search. By default it should check Google, but if I select the checkbox for subtitles it would use the search field to search for subtitles (on the appropiate website).

If this isn't possible, would it be possible with a dropdown or something similar? Or maybe a different approach or solution to this?

When both are not possible or takes a massive amount of coding / tweaking, I will refer to using multiple search fields as I did before.

I took a screenshot of how the search fields are currently (on the old design) to give you an impression.

enter image description here

Reason for switching to checkboxes / dropdown field is, is that I can add more searches without making the page look messy.

While typing this and looking at things, once more, maybe a better solution would be to just create several buttons and use only one search field? Still might be a little tacky, but that could actually work. What do you think?

And like I said; if it takes to much coding or tweaking just tell so. I am just wondering if there is a different approach to this.




A checked checkbox is not displaying checked? Laravel

i have a problem where a checked checkbox is not displaying checked.

My view:

@if(in_array($searchgroup->id.','.$searchtag->id, session()->get('zoektermen')))
     
@else
     
@endif

I'm using laravel collective.

I'm using this code on other places on the website in different scenario's, where this works perfectly and the checkboxes display checked.

I'm using firefox but i also tried safari, no difference. enter image description here

Any help is appreciated..




DataGrid BindingSource Checkbox Filters

I have a DGrid that is attached to a BindingSource which is full of data. I am trying to use checkboxes for the user to filter out data in a specific column named 'Status'. I have four checkboxes as there will be four different data text in the same column (Column is on the far right). Picture here

Obviously when the user checks/unchecks one of the checkbox it will set a filter to the grid to add/remove that data in the column.

How would I go about doing this? Obviously I would attach a CheckChanged function to each checkbox and apply the filter using bs.Filter but what would be the best way to check if the other checkboxes are checked and aren't checked so I can concat the filter string? Would I have to use a ton of If statements for each checkbox to see if it's checked?




Angular 4 : How to assign array of string into checkbox in reactive forms

I am trying display checkboxes for my user roles:

For eg. I have two user roles : 1.Admin 2.Employee

I have an array of roles in userObject:

user={
    "name":"Bhushan",
    "email":"bhushan@yaho.com",
    "roles":['Admin','Employee']
}

I want to use reactive form to populate this model into form. I want to populate the roles array into read-only checkboxes i.e. when form loads, user can edit name & email but checkboxes will show admin toggeled if user has admin role or untoggled if he is not an admin. same can be said for employee role.

So far I have tried following:

<form [formGroup]="userForm" (ngSubmit)="onSubmit()" novalidate>
  <div style="margin-bottom: 1em">
    <button type="submit" [disabled]="userForm.pristine" class="btn btn-success">Save</button> &nbsp;
    <button type="reset" (click)="revert()" [disabled]="userForm.pristine" class="btn btn-danger">Revert</button>
  </div>
  <div class="form-group">
    <label class="center-block">Name:
        <input class="form-control" formControlName="name">
    </label>
  </div>
  <div class="form-group">
    <label class="center-block">Email:
        <input class="form-control" formControlName="email">
    </label>
  </div>
  <div class="form-group" *ngFor="let role of roles;let i=index">
    <label>
        // I tried this, but it doesn't work
        <!--<input type="checkbox" [name]="role" [(ngModel)]="role">-->
       
    </label>
  </div>
</form>

<p>userForm value: </p>`

Any Inputs?




bootgrid change checkbox into radiobutton

I'm using jQuery-Bootgrid to create my tables. If I set rowSelect=true and multiSelect=falsethe checkbox can not be clicked (or checked).

I want to change the checkbox into a radiobutton if rowSelect=true and multiSelect=false. I don't know how to change this without editing the jquery.bootgrid.js file. Otherwise I don't know how to change this if I edit jquery.bootgrid.js.

The question is, how to :D