想让这些PHP函数在这个html echo中工作

时间:2016-07-02 21:45:18

标签: javascript php jquery html

这是php文档,在构建此表单时,我想使用该forech函数来构建下拉菜单...因为我在(HTML)内部它不起作用...任何人都有一个线索如何让它工作?

echo <<<HTML
    <form method="post" class="form">
    <label for="datafalta">Data da falta</label>
    <input id="datafalta" type="date" value="{$dateToday}"  name="datafalta"/>
    <label for="alunofalta">Selecionar aluno</label>
    <select name="aluno">
         <option value="0" selected></option>
        foreach ($calfaltas as $a) {
            <option value="1">$a->nome</option>
        }

    </select><br /><br />
    <input type="submit" name="enviar" value="Enviar">
    </form>
HTML;

4 个答案:

答案 0 :(得分:0)

这应该有效:

module.exports = {
    entry: path.resolve(__dirname, "./app/component/Home.js"),
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.css$/, loader: "style!css" }
        ]
    },
    resolve: {
       alias: {
           moment: path.resolve(__dirname, './node_modules/moment/moment.js')
       }
    }
};

答案 1 :(得分:0)

你不能像现在这样混合html和php。首先,你会发现像字符串''这样的简单部分。

<?php
echo ' 
<html>
    <form method="post" class="form">
        <label for="datafalta">Data da falta</label>
        <input id="datafalta" type="date" value="' . $dateToday . '"  name="datafalta"/>
        <label for="alunofalta">Selecionar aluno</label>
        <select name="aluno">
            <option value="0" selected></option>';

            foreach ($calfaltas as $a) {
                echo '
                <option value="1">' . $a->nome . '</option>';
            }

        echo '
        </select><br /><br />
        <input type="submit" name="enviar" value="Enviar">
    </form>
<html>';

答案 2 :(得分:0)

将你的heredoc分成两部分,中间是foreach:

<?php
echo <<<HTML
    <form method="post" class="form">
    <label for="datafalta">Data da falta</label>
    <input id="datafalta" type="date" value="{$dateToday}"  name="datafalta"/>
    <label for="alunofalta">Selecionar aluno</label>
    <select name="aluno">
         <option value="0" selected></option>
HTML;
        foreach ($calfaltas as $a) {
            echo "<option value='{$a->id}'>{$a->nome}</option>";
        }
echo <<<HTML
    </select><br /><br />
    <input type="submit" name="enviar" value="Enviar">
    </form>
HTML;
?>

答案 3 :(得分:0)

而不是将foreach循环放在heredoc输出中....在变量中创建所有选项并在字符串中间输出该变量

 $options='';
 foreach ($calfaltas as $a) {
      $options.='<option value="'.$a->someProperty.'">'.$a->nome.'</option>';
 }

echo <<<HTML
    <form method="post" class="form">
    <label for="datafalta">Data da falta</label>
    <input id="datafalta" type="date" value="{$dateToday}"  name="datafalta"/>
    <label for="alunofalta">Selecionar aluno</label>
    <select name="aluno">
         <option value="0" selected></option>
         $options

    </select><br /><br />
    <input type="submit" name="enviar" value="Enviar">
    </form>
HTML;

请注意,您需要修复<option>标记的值以反映数组中的正确数据