这是我的代码: 图
<label>
<input class="i-check" name="amenity[]" type="checkbox" value="{{$amn->ht_amenity_id}}" />{{$amn->ht_amenity_name}}
</label>
控制器
$purp = $_POST['amenity'];
print_r($purp);
这里(在控制器中),我只是想打印值
请有人帮助我。
答案 0 :(得分:1)
使用AJAX
在视图中:
$(selector).change(function()
{
if($(selector).is(':checked'))
checked = 'checked';
else
checked = 'unchecked';
$.post('The page u want', checked:checked, function(data){});
});
控制器中的:
您提到的代码:
$purp = $_POST['checked'];
print_r($purp);
答案 1 :(得分:0)
你使用Laravel,所以你应该使用Laravel Collective并使用它的Form :: model和Form :: open结构以正确的方式完成:
https://laravel.com/docs/4.2/html#checkboxes-and-radio-buttons
Laravel会将数据传递给控制器内的public class Menu extends Application {
private Pane splashLayout;
private Stage mainStage;
private ImageView splash;
// Creating a static root to pass to ScreenControl
private static BorderPane root = new BorderPane();
public void start(Stage splashStage) throws IOException {
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.splash = new ImageView(new Image(getClass().getResource("/splash.png").toString()));
splashStage.initStyle(StageStyle.TRANSPARENT);
showSplash(splashStage, screenSize);
// Constructing our scene using the static root
root.setCenter(new ScrollPane);
Scene scene = new Scene(root, screenSize.getWidth(), screenSize.getHeight());
showMainStage(scene);
if (splashStage.isShowing()) {
mainStage.setIconified(false);
splashStage.toFront();
FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.5), splashLayout);
fadeSplash.setDelay(Duration.seconds(3.5));
fadeSplash.setFromValue(1.0);
fadeSplash.setToValue(0.0);
fadeSplash.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
splashStage.hide();
}
});
fadeSplash.play();
}
}
private void showMainStage(Scene scene) {
mainStage = new Stage(StageStyle.DECORATED);
mainStage.setTitle("book-depot");
mainStage.getIcons().add(new Image(getClass().getResourceAsStream("/icon.png")));
mainStage.setScene(scene);
mainStage.show();
}
private void showSplash(Stage splashStage, Dimension screenSize) {
splashLayout = new StackPane();
splashLayout.setStyle("-fx-background-color: transparent;");
splashLayout.getChildren().add(splash);
Scene splashScene = new Scene(splashLayout, 690, 590);
splashScene.setFill(Color.TRANSPARENT);
splashStage.setScene(splashScene);
splashStage.show();
}
public void mainGui(String[] args) {
launch(args);
}
}
或store()
方法。然后你可以使用它:update()
另外,了解RESTful控制器,这是使用表单最简单的方法: https://laravel.com/docs/5.1/controllers#restful-resource-controllers