Отправьте HTML-форму с пустыми флажками

Вы должны использовать appBar: AppBar(... внутри своей эшафот. Поэтому MaterialApp-> Scaffold -> (AppBar и listview).

Пример кода:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("This is the title"),
        ),
        body: ListView(
          children: <Widget>[
            Text("This is text 1"),
            Text("This is text 2"),
            Text("This is text 3"),
            Text("This is text 4"),
            Text("This is text 5"),
            Text("This is text 6"),
            Text("This is text 7"),
            Text("This is text 8"),
            Text("This is text 9"),
            Text("This is text 10"),
            Text("This is text 11"),
            Text("This is text 12"),
            Text("This is text 13"),
            Text("This is text 14"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
          ],
        ),
      ),
    );
  }
}
41
задан DaveS 15 May 2012 в 18:33
поделиться

6 ответов

Элементы радио-или флажка непроверенные не отправлены, поскольку их не рассматривают как успешных. Таким образом, необходимо проверить, отправляются ли они с помощью isset или empty функция.

if (isset($_POST['checkbox'])) {
    // checkbox has been checked
}
41
ответ дан Gumbo 27 November 2019 в 00:07
поделиться

Я время от времени использовал эту технику:

<input type="hidden" name="the_checkbox" value="0" />
<input type="checkbox" name="the_checkbox" value="1" />

примечание: Это становится интерпретируемым по-другому на различных языках серверной стороны, так протестируйте и корректируйтесь при необходимости. Благодаря SimonSimCity для подсказки.

93
ответ дан Community 27 November 2019 в 00:07
поделиться

Для добавления к коду fmsf при добавлении флажков, я делаю их массивом при наличии [] на имя

<FORM METHOD=POST ACTION="statistics.jsp?q=1&g=1">
    <input type="radio" name="gerais_radio" value="primeiras">Primeiras Consultas por medico<br/>
    <input type="radio" name="gerais_radio" value="salas">Consultas por Sala <br/>
    <input type="radio" name="gerais_radio" value="assistencia">Pacientes por assistencia<br/>
    <input type="checkbox" name="option[]" value="Option1">Option1<br/>
    <input type="checkbox" name="option[]" value="Option2">Option2<br/>
    <input type="checkbox" name="option[]" value="Option3">Option3<br/>
    <input type="submit" value="Ver">

3
ответ дан user58670 27 November 2019 в 00:07
поделиться

Флажок непроверенный не становится отправленным в данных POST. Необходимо просто проверить, пусто ли это:

if (empty($_POST['myCheckbox']))
     ....
else
     ....

В PHP empty() и isset() не генерируйте уведомления.

7
ответ дан Greg 27 November 2019 в 00:07
поделиться

Используйте это

$myvalue = (isset($_POST['checkbox']) ? $_POST['checkbox'] : 0;

Или занимая место независимо от того, что Ваше никакое значение не для 0

2
ответ дан Yuck 27 November 2019 в 00:07
поделиться

Вот простой обходной путь с использованием javascript:

перед отправкой формы, содержащей флажки, установите для «выключенных» значение 0 и проверьте их, чтобы убедиться, что они отправлены. это работает, например, для массивов флажков.

///// пример //////

для формы с id = "formId"

<form id="formId" onSubmit="return formSubmit('formId');" method="POST" action="yourAction.php">

<!--  your checkboxes here . for example: -->

<input type="checkbox" name="cb[]" value="1" >R
<input type="checkbox" name="cb[]" value="1" >G
<input type="checkbox" name="cb[]" value="1" >B

</form>
<?php


if($_POST['cb'][$i] == 0) {
    // empty
} elseif ($_POST['cb'][$i] == 1) {
    // checked
} else {
    // ????
}

?>


<script>

function formSubmit(formId){

var theForm = document.getElementById(formId); // get the form

var cb = theForm.getElementsByTagName('input'); // get the inputs

for(var i=0;i<cb.length;i++){ 
    if(cb[i].type=='checkbox' && !cb[i].checked)  // if this is an unchecked checkbox
    {
       cb[i].value = 0; // set the value to "off"
       cb[i].checked = true; // make sure it submits
    }
}

return true;

}

</script>
5
ответ дан 27 November 2019 в 00:07
поделиться
Другие вопросы по тегам:

Похожие вопросы: