logo
down
shadow

Create a set of rules if counting two or more variables. from html form


Create a set of rules if counting two or more variables. from html form

By : Auph
Date : November 19 2020, 03:59 PM
Hope this helps I want to create a set of rules in php I have a form with 2 select fields ( with values from 1->5 , Due to the recent declaration from you:
code :
<?php

class boxes
{
    private $_boxes = array();
    public $maxCake = 3; // default .. 3

    public function addBox()
    {
        $this->_boxes[] = array();
    }

    public function getBoxes()
    {
        return $this->_boxes;
    }

    public function addCake($boxNum = 0, $cake = array('paxType' => 'Cake'))
    {
        if (empty($this->_boxes)) {
            $this->addBox();
        }

        if (empty($this->_boxes[$boxNum])) {
            $this->_boxes[$boxNum] = array();
        }

        // if box is full with cakes (maxCake) create a new one
        if (count($this->_boxes[$boxNum]) == $this->maxCake) {
            $oldBoxNum = $boxNum;
            // searching for a box with enough space for another cake
            foreach ($this->_boxes as $key => $box) {
                if (count($box) != $this->maxCake) {
                    $boxNum = $key;
                    break;
                }
            }
            // if we can't found one we add a new box
            if ($oldBoxNum == $boxNum) {
                $this->addBox();
                $boxNum++;
            }
        }

        $this->_boxes[$boxNum][] = $cake; 
    }
}

$Field1 = 1; // boxes
$Field2 = 5; // cakes

$boxes = new boxes();
$boxes->maxCake = 3; // if there are more than 3 cakes in a box, a new box will be created

// create number of boxes given with field1
for ($x = 0; $x < $Field1; $x++) {
    $boxes->addBox();
}

// add cakes given with field2
$y = 0;
for ($x = 0; $x < $Field2; $x++) {
    $boxes->addCake($y);
    $y++;
    if ($Field1 == $y) {
        $y = 0;
    }
}

$result = $boxes->getBoxes();
for ($x = 0; $x < count($result); $x++) {
    echo 'Box' . ($x + 1) . ':';
    echo "<br>";
    print_r($result[$x]);
    echo "<br>";
}
Box1:
Array (
    [0] => Array( [paxType] => Cake )
    [1] => Array( [paxType] => Cake )
    [2] => Array( [paxType] => Cake )   
)                                                      

Box2:  
Array (                                                      
    [0] => Array( [paxType] => Cake )
    [1] => Array( [paxType] => Cake )
)


Share : facebook icon twitter icon
Create HTML form using rules defined in JSON

Create HTML form using rules defined in JSON


By : user5712560
Date : March 29 2020, 07:55 AM
may help you . You can try something like this: http://jsfiddle.net/epk6Z/
for fiddle i used a variable json
code :
$.each(json.modules, function (i, items) {
  $('<' + items.formElem + '/>').attr({
    "action": items.action,
        "name": items.name,
        "class": items.attributes.class
  }).appendTo('body');
  $('<h1/>').text(items.title).appendTo('.registrationform');
});
success: function(data){
 $.each(data.modules, function (i, items) {
  $('<' + items.formElem + '/>').attr({
    "action": items.action,
        "name": items.name,
        "class": items.attributes.class
  }).appendTo('body');
  $('<h1/>').text(items.title).appendTo('.registrationform');
 });
} 
{
"modules": [{
    "nav": "navigation",
        "container": "#header",
        "title": "Top Navigation",
        "attributes": {
        "class": "topNavigation",
            "id": "topNavigation"
    }
}, {
    "page-content": "content",
        "title": "Hi Welcome to mobile development",
        "subtitle": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
        "container": "#maincontent",
        "attributes": {
        "class": "topContent"
    }
}, {
    "formElem": "form", //<-----------i targeted this
        "title": "Registration Form",
        "action": "submit.aspx",
        "name": "registrationform",
        "container": "#maincontent",
        "attributes": {
        "class": "registrationform"
    }
    ...............
Multiple validation rules on html form

Multiple validation rules on html form


By : kics
Date : March 29 2020, 07:55 AM
Any of those help I have an html form that resembles the following code. My problem is I want to validate based on multiple criteria... a number can either be 0 OR it must be greater than 700. I'm using an array for the input names which is making it tough for me to get a javascript solution working. How would one go about validating in this case with the multiple critera? , Got it to validate with the following javascript function.
code :
<script>
function validateForm() {
var x = document.forms["endingweights"].elements["ending[]"];
for (var i = 0; i < x.length; i++) {
var aControl = x[i].value;
if (aControl>0 && aControl<700) {
    alert("Incorrect Weight, must be 0 or greater than 700.");
    x[i].focus();
    return false;
    }
}}
</script>
How do I create a HTML form that generates a JSON file containing all the data that was submitted to the HTML form ?

How do I create a HTML form that generates a JSON file containing all the data that was submitted to the HTML form ?


By : James Stueve
Date : March 29 2020, 07:55 AM
it fixes the issue You can actually use jQuery's serialize() function. Since you have used Bootstrap, there'll be jQuery for sure. So all you need to do is:
code :
$(function () {
  $("#myForm").submit(function () {
    var jsonOutput = JSON.stringify($(this).serializeArray());
    $("#genJSON").text(jsonOutput);
    $("#download").attr("href", 'data:application/executable;charset=utf-8,' + encodeURIComponent(jsonOutput)).show();
    return false;
  });
});
* {margin: 0; padding: 0; list-style: none; font-family: 'Segoe UI';}
pre {font-family: 'Consolas', monospace; white-space: pre-wrap;}
form,
form ul,
form ul li,
form ul li label {display: block;}
form ul li {padding: 5px;}
form ul li label strong {display: inline-block; width: 100px;}
form ul li label input {padding: 3px;}
form ul li > input {margin-left: 105px; padding: 3px 10px; cursor: pointer;}
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<form action="" id="myForm">
  <ul>
    <li>
      <label>
        <strong>Username</strong>
        <input type="text" name="Username" />
      </label>
    </li>
    <li>
      <label>
        <strong>Password</strong>
        <input type="text" name="Password" />
      </label>
    </li>
    <li>
      <label>
        <strong>Full Name</strong>
        <input type="text" name="FullName" />
      </label>
    </li>
    <li>
      <label>
        <strong>Email</strong>
        <input type="text" name="Email" />
      </label>
    </li>
    <li>
      <input type="submit" value="Get JSON" />
    </li>
  </ul>
</form>

<pre id="genJSON"></pre>
<div>
  <a id="download" style="display: none;">Download Code</a>
</div>
this.href = 'data:application/json;charset=utf-8,'
            + encodeURIComponent(genJSON.innerHTML);
how to create new variables from one variable using two rules

how to create new variables from one variable using two rules


By : NIkhil Bari
Date : March 29 2020, 07:55 AM
it helps some times I would appreciate any help to create new variables from one variable. , You can use dcast from data.table
code :
library(data.table)
dcast(dT, A + B + ID ~ paste0("E", rowid(ID)))
#   A  B ID        E1        E2        E3
#1 a1 b1  1 0.4069439 0.3526222 0.2337894
#2 a1 b2  3 0.6211421 0.3943915 0.5505793
#3 a2 b2  4 0.7421095 0.7796073 0.6906605
Create a set of variables in a dataframe based on a set of rules from another data frame

Create a set of variables in a dataframe based on a set of rules from another data frame


By : iOS Developer
Date : March 29 2020, 07:55 AM
it fixes the issue We can pivot the first dataset into 'long' format, join with the second one and then pivot it back to 'wide' format
code :
library(dplyr)
library(tidyr)
library(stringr)
df1 %>%
    mutate(rn = row_number()) %>%
    pivot_longer(cols  = -c(rn, Level), values_to = 'var1') %>% 
    rename(level = Level) %>% 
    left_join(df2) %>% 
    mutate(name = str_replace(name, 'group', 'varn')) %>% 
    na.omit %>%
    select(-level, -var1) %>% 
    pivot_wider(names_from = name, values_from = Score, values_fill = list(Score = 0)) %>% 
    select(-rn) %>% 
    bind_cols(df1, .)
#   group1  group2  group3 Level varn1 varn2 varn3
#1    cat     cat     dog     1     1     1     1
#2    dog  parrot     cat     1     1     0     1
#3  mouse dolphin dolphin     1     1     0     0
#4    red    blue    blue     2     1     1     1
#5  green  yellow   green     2     1     0     1
#6  black  purple     cat     2     0     1     0
Related Posts Related Posts :
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • What's wrong with my PHP Script? T_String issue
  • how to call a function of another file without including that file
  • is_rgb function in php
  • transform the numbers to letters using php
  • How to catch an exception from another class method PHP
  • PHP exec is blocked by ISP
  • PHP4 to PHP5 migration character encoding. latin1 vs utf8
  • Begin Transaction not defined
  • How much harm can a user do with xss on a page unique to them?
  • How to import data from a php file to javascript variable
  • PHP and Javascript - log complete workflow
  • When I echo !!! 0 it gives me a strange result
  • jquery ajax post dies after submit
  • How to upload file with curl on sftp server
  • Advanced search using a text input to search through only one category
  • Why do I get "Non-static method App\Models\Category::products() should not be called statically" in laravel
  • Stop notices from undefined indexes in arrays
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org