一个.php文件中有两个PHP回声。我可以隔离它们吗?

时间:2014-01-16 12:23:47

标签: php web

这是我第一次创建网站,我想在一个页面上注册和登录表单。每次我尝试注册它都会回显要登录的数据,基本上这个过程就会停止。如果我独立使用寄存器,它就可以正常工作。由于我使用的是bootstrap,我的整个代码都是一个大的(但注册/登录明显是分开的)。有没有两种方法指示PHP只在我工作的段中回显?

<!-- Form Code Start -->
<div id='fg_membersite' class="container">
    <div class="row">
        <div class="col-md-3">
            <form id='register' class="form-horizontal"  action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
                <fieldset >
                    <legend>Register</legend>

                    <input type='hidden' name='submitted' id='submitted' value='1'/>

                    <div class='short_explanation'>* required fields</div>
                    <input type='text'  class='spmhidip' name='<?php echo $fgmembersite->GetSpamTrapInputName(); ?>' />

                    <div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>
                    <div class='container'>
                        <label for='name' >Your Full Name*: </label><br/>
                        <input type='text' name='name' id='name' value='<?php echo $fgmembersite->SafeDisplay('name') ?>' maxlength="50" /><br/>
                        <span id='register_name_errorloc' class='error'></span>
                    </div>
                    <div class='container'>
                        <label for='email' >Email Address*:</label><br/>
                        <input type='text' name='email' id='email' value='<?php echo $fgmembersite->SafeDisplay('email') ?>' maxlength="50" /><br/>
                        <span id='register_email_errorloc' class='error'></span>
                    </div>
                    <div class='container'>
                        <label for='username' >UserName*:</label><br/>
                        <input type='text' name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
                        <span id='register_username_errorloc' class='error'></span>
                    </div>
                    <div class='container' style='height:80px;'>
                        <label for='password' >Password*:</label><br/>
                        <div class='pwdwidgetdiv' id='thepwddiv' ></div>
                        <noscript>
                            <input type='password' name='password' id='password' maxlength="50" />
                        </noscript>
                        <div id='register_password_errorloc' class='error' style='clear:both'></div>
                    </div>

                    <div class='container'>
                        <input type='submit' name='Submit' value='Submit' />
                    </div>

                </fieldset>
            </form>
        </div>

        <div class="col-md-3">
            <form id='login' class="form-horizontal" action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
                <fieldset >
                    <legend>Login</legend>

                    <input type='hidden' name='submitted' id='submitted' value='1'/>

                    <div class='short_explanation'>* required fields</div>

                    <div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>
                    <div class='container'>
                        <label for='username' >UserName*:</label><br/>
                        <input type='text' name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
                        <span id='login_username_errorloc' class='error'></span>
                    </div>
                    <div class='container'>
                        <label for='password' >Password*:</label><br/>
                        <input type='password' name='password' id='password' maxlength="50" /><br/>
                        <span id='login_password_errorloc' class='error'></span>
                    </div>

                    <div class='container'>
                        <input type='submit' name='Submit' value='Submit' />
                    </div>
                    <div class='short_explanation'><a href='reset-pwd-req.php'>Forgot Password?</a></div>
                </fieldset>
            </form>
        </div>
    </div>

1 个答案:

答案 0 :(得分:1)

您可以像这样构建它:

<?php if ($someBool): ?>
   <form id="register">
      <!-- more html here -->
   </form>
<? else: ?>
   <form id="login">
      <!-- yet more html here -->
   </form>
<?php endif ?>

它是if的替代语法。见http://pl1.php.net/alternative_syntax