如何根据表单状态(已提交/未提交)构建 php if 语句?

发布于 2024-11-30 09:32:59 字数 8797 浏览 1 评论 0原文

现在,当我提交表单时,我会在 URL 中看到以下内容:

http://www.taiwantalk.org/users/admin/edit /?updated=true

这是一个更新用户个人资料的表单(我正在使用 Wordpress 但我猜 ?updated=true 是一个 php 的东西)。

我想使用该信息构建一个 if 语句:

if ( form=updated] ) {
//do this
}

如何根据表单的提交或更新状态构建 if 语句?

编辑:

表单的源代码(以防万一):

<form id="bbp-your-profile" action="<?php bbp_user_profile_edit_url( bbp_get_displayed_user_id() ); ?>" method="post">

    <h2 class="entry-title"><?php _e( 'Name', 'bbpress' ) ?></h2>

    <?php do_action( 'bbp_user_edit_before' ); ?>

    <fieldset class="bbp-form">
        <legend><?php _e( 'Name', 'bbpress' ) ?></legend>

        <?php do_action( 'bbp_user_edit_before_name' ); ?>

        <div>
            <label for="first_name"><?php _e( 'First Name', 'bbpress' ) ?></label>
            <input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'first_name' ) ); ?>" class="regular-text" />
        </div>

        <div>
            <label for="last_name"><?php _e( 'Last Name', 'bbpress' ) ?></label>
            <input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'last_name' ) ); ?>" class="regular-text" />
        </div>

        <div>
            <label for="nickname"><?php _e( 'Nickname', 'bbpress' ); ?></label>
            <input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'nickname' ) ); ?>" class="regular-text" />
        </div>

        <div>
            <label for="display_name"><?php _e( 'Display name publicly as', 'bbpress' ) ?></label>

            <?php bbp_edit_user_display_name(); ?>

        </div>

        <?php do_action( 'bbp_user_edit_after_name' ); ?>

    </fieldset>

    <h2 class="entry-title"><?php _e( 'Contact Info', 'bbpress' ) ?></h2>

    <fieldset class="bbp-form">
        <legend><?php _e( 'Contact Info', 'bbpress' ) ?></legend>

        <?php do_action( 'bbp_user_edit_before_contact' ); ?>

        <div>
            <label for="url"><?php _e( 'Website', 'bbpress' ) ?></label>
            <input type="text" name="url" id="url" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'user_url' ) ); ?>" class="regular-text code" />
        </div>

        <?php foreach ( bbp_edit_user_contact_methods() as $name => $desc ) : ?>

            <div>
                <label for="<?php echo $name; ?>"><?php echo apply_filters( 'user_'.$name.'_label', $desc ); ?></label>
                <input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'name' ) ); ?>" class="regular-text" />
            </div>

        <?php endforeach; ?>

        <?php do_action( 'bbp_user_edit_after_contact' ); ?>

    </fieldset>

    <h2 class="entry-title"><?php bbp_is_user_home() ? _e( 'About Yourself', 'bbpress' ) : _e( 'About the user', 'bbpress' ); ?></h2>

    <fieldset class="bbp-form">
        <legend><?php bbp_is_user_home() ? _e( 'About Yourself', 'bbpress' ) : _e( 'About the user', 'bbpress' ); ?></legend>

        <?php do_action( 'bbp_user_edit_before_about' ); ?>

        <div>
            <label for="description"><?php _e( 'Biographical Info', 'bbpress' ); ?></label>
            <textarea name="description" id="description" rows="5" cols="30"><?php echo esc_attr( bbp_get_displayed_user_field( 'description' ) ); ?></textarea>
            <span class="description"><?php _e( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'bbpress' ); ?></span>
        </div>

        <?php do_action( 'bbp_user_edit_after_about' ); ?>

    </fieldset>

    <h2 class="entry-title"><?php _e( 'Account' ) ?></h2>

    <fieldset class="bbp-form">
        <legend><?php _e( 'Account' ) ?></legend>

        <?php do_action( 'bbp_user_edit_before_account' ); ?>

        <div>
            <label for="user_login"><?php _e( 'Username', 'bbpress' ); ?></label>
            <input type="text" name="user_login" id="user_login" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'user_login' ) ); ?>" disabled="disabled" class="regular-text" />
            <span class="description"><?php _e( 'Usernames cannot be changed.', 'bbpress' ); ?></span>
        </div>

        <div>
            <label for="email"><?php _e( 'Email', 'bbpress' ); ?></label>

            <input type="text" name="email" id="email" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'user_email' ) ); ?>" class="regular-text" />

            <?php

            // Handle address change requests
            $new_email = get_option( bbp_get_displayed_user_id() . '_new_email' );
            if ( $new_email && $new_email != bbp_get_displayed_user_field( 'user_email' ) ) : ?>

                <span class="updated inline">

                    <?php printf( __( 'There is a pending email address change to <code>%1$s</code>. <a href="%2$s">Cancel</a>', 'bbpress' ), $new_email['newemail'], esc_url( self_admin_url( 'user.php?dismiss=' . bbp_get_current_user_id()  . '_new_email' ) ) ); ?>

                </span>

            <?php endif; ?>

        </div>

        <div id="password">
            <label for="pass1"><?php _e( 'New Password', 'bbpress' ); ?></label>
            <fieldset class="bbp-form">
                <input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" />
                <span class="description"><?php _e( 'If you would like to change the password type a new one. Otherwise leave this blank.', 'bbpress' ); ?></span>

                <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" />
                <span class="description"><?php _e( 'Type your new password again.', 'bbpress' ); ?></span><br />

                <div id="pass-strength-result"></div>
                <span class="description indicator-hint"><?php _e( 'Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).', 'bbpress' ); ?></span>
            </fieldset>
        </div>

        <?php if ( !bbp_is_user_home() ) : ?>

            <div>
                <label for="role"><?php _e( 'Role:', 'bbpress' ) ?></label>

                <?php bbp_edit_user_role(); ?>

            </div>

        <?php endif; ?>

        <?php if ( is_multisite() && is_super_admin() && current_user_can( 'manage_network_options' ) ) : ?>

            <div>
                <label for="role"><?php _e( 'Super Admin', 'bbpress' ); ?></label>
                <label>
                    <input type="checkbox" id="super_admin" name="super_admin"<?php checked( is_super_admin( bbp_get_displayed_user_id() ) ); ?> />
                    <?php _e( 'Grant this user super admin privileges for the Network.', 'bbpress' ); ?>
                </label>
            </div>

        <?php endif; ?>

        <?php do_action( 'bbp_user_edit_after_account' ); ?>

    </fieldset>

    <?php do_action( 'bbp_user_edit_after' ); ?>

    <fieldset class="submit">
        <legend><?php _e( 'Save Changes', 'bbpress' ); ?></legend>
        <div>

            <?php bbp_edit_user_form_fields(); ?>

            <button type="submit" id="bbp_user_edit_submit" name="bbp_user_edit_submit"><?php bbp_is_user_home() ? _e( 'Update Profile', 'bbpress' ) : _e( 'Update User', 'bbpress' ); ?></button>
        </div>
    </fieldset>

</form>

Right now, when I submit a form, I get this in my URL:

http://www.taiwantalk.org/users/admin/edit/?updated=true

It's a form to updates an user's profile (I'm using Wordpress
but I guess that ?updated=true is a php thing).

I want to build a if-statement with that information:

if ( form=updated] ) {
//do this
}

How to build an if-statement based on the submitted or updated status of the form?

EDIT:

The source code of the form (just in case):

<form id="bbp-your-profile" action="<?php bbp_user_profile_edit_url( bbp_get_displayed_user_id() ); ?>" method="post">

    <h2 class="entry-title"><?php _e( 'Name', 'bbpress' ) ?></h2>

    <?php do_action( 'bbp_user_edit_before' ); ?>

    <fieldset class="bbp-form">
        <legend><?php _e( 'Name', 'bbpress' ) ?></legend>

        <?php do_action( 'bbp_user_edit_before_name' ); ?>

        <div>
            <label for="first_name"><?php _e( 'First Name', 'bbpress' ) ?></label>
            <input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'first_name' ) ); ?>" class="regular-text" />
        </div>

        <div>
            <label for="last_name"><?php _e( 'Last Name', 'bbpress' ) ?></label>
            <input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'last_name' ) ); ?>" class="regular-text" />
        </div>

        <div>
            <label for="nickname"><?php _e( 'Nickname', 'bbpress' ); ?></label>
            <input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'nickname' ) ); ?>" class="regular-text" />
        </div>

        <div>
            <label for="display_name"><?php _e( 'Display name publicly as', 'bbpress' ) ?></label>

            <?php bbp_edit_user_display_name(); ?>

        </div>

        <?php do_action( 'bbp_user_edit_after_name' ); ?>

    </fieldset>

    <h2 class="entry-title"><?php _e( 'Contact Info', 'bbpress' ) ?></h2>

    <fieldset class="bbp-form">
        <legend><?php _e( 'Contact Info', 'bbpress' ) ?></legend>

        <?php do_action( 'bbp_user_edit_before_contact' ); ?>

        <div>
            <label for="url"><?php _e( 'Website', 'bbpress' ) ?></label>
            <input type="text" name="url" id="url" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'user_url' ) ); ?>" class="regular-text code" />
        </div>

        <?php foreach ( bbp_edit_user_contact_methods() as $name => $desc ) : ?>

            <div>
                <label for="<?php echo $name; ?>"><?php echo apply_filters( 'user_'.$name.'_label', $desc ); ?></label>
                <input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'name' ) ); ?>" class="regular-text" />
            </div>

        <?php endforeach; ?>

        <?php do_action( 'bbp_user_edit_after_contact' ); ?>

    </fieldset>

    <h2 class="entry-title"><?php bbp_is_user_home() ? _e( 'About Yourself', 'bbpress' ) : _e( 'About the user', 'bbpress' ); ?></h2>

    <fieldset class="bbp-form">
        <legend><?php bbp_is_user_home() ? _e( 'About Yourself', 'bbpress' ) : _e( 'About the user', 'bbpress' ); ?></legend>

        <?php do_action( 'bbp_user_edit_before_about' ); ?>

        <div>
            <label for="description"><?php _e( 'Biographical Info', 'bbpress' ); ?></label>
            <textarea name="description" id="description" rows="5" cols="30"><?php echo esc_attr( bbp_get_displayed_user_field( 'description' ) ); ?></textarea>
            <span class="description"><?php _e( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'bbpress' ); ?></span>
        </div>

        <?php do_action( 'bbp_user_edit_after_about' ); ?>

    </fieldset>

    <h2 class="entry-title"><?php _e( 'Account' ) ?></h2>

    <fieldset class="bbp-form">
        <legend><?php _e( 'Account' ) ?></legend>

        <?php do_action( 'bbp_user_edit_before_account' ); ?>

        <div>
            <label for="user_login"><?php _e( 'Username', 'bbpress' ); ?></label>
            <input type="text" name="user_login" id="user_login" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'user_login' ) ); ?>" disabled="disabled" class="regular-text" />
            <span class="description"><?php _e( 'Usernames cannot be changed.', 'bbpress' ); ?></span>
        </div>

        <div>
            <label for="email"><?php _e( 'Email', 'bbpress' ); ?></label>

            <input type="text" name="email" id="email" value="<?php echo esc_attr( bbp_get_displayed_user_field( 'user_email' ) ); ?>" class="regular-text" />

            <?php

            // Handle address change requests
            $new_email = get_option( bbp_get_displayed_user_id() . '_new_email' );
            if ( $new_email && $new_email != bbp_get_displayed_user_field( 'user_email' ) ) : ?>

                <span class="updated inline">

                    <?php printf( __( 'There is a pending email address change to <code>%1$s</code>. <a href="%2$s">Cancel</a>', 'bbpress' ), $new_email['newemail'], esc_url( self_admin_url( 'user.php?dismiss=' . bbp_get_current_user_id()  . '_new_email' ) ) ); ?>

                </span>

            <?php endif; ?>

        </div>

        <div id="password">
            <label for="pass1"><?php _e( 'New Password', 'bbpress' ); ?></label>
            <fieldset class="bbp-form">
                <input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" />
                <span class="description"><?php _e( 'If you would like to change the password type a new one. Otherwise leave this blank.', 'bbpress' ); ?></span>

                <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" />
                <span class="description"><?php _e( 'Type your new password again.', 'bbpress' ); ?></span><br />

                <div id="pass-strength-result"></div>
                <span class="description indicator-hint"><?php _e( 'Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).', 'bbpress' ); ?></span>
            </fieldset>
        </div>

        <?php if ( !bbp_is_user_home() ) : ?>

            <div>
                <label for="role"><?php _e( 'Role:', 'bbpress' ) ?></label>

                <?php bbp_edit_user_role(); ?>

            </div>

        <?php endif; ?>

        <?php if ( is_multisite() && is_super_admin() && current_user_can( 'manage_network_options' ) ) : ?>

            <div>
                <label for="role"><?php _e( 'Super Admin', 'bbpress' ); ?></label>
                <label>
                    <input type="checkbox" id="super_admin" name="super_admin"<?php checked( is_super_admin( bbp_get_displayed_user_id() ) ); ?> />
                    <?php _e( 'Grant this user super admin privileges for the Network.', 'bbpress' ); ?>
                </label>
            </div>

        <?php endif; ?>

        <?php do_action( 'bbp_user_edit_after_account' ); ?>

    </fieldset>

    <?php do_action( 'bbp_user_edit_after' ); ?>

    <fieldset class="submit">
        <legend><?php _e( 'Save Changes', 'bbpress' ); ?></legend>
        <div>

            <?php bbp_edit_user_form_fields(); ?>

            <button type="submit" id="bbp_user_edit_submit" name="bbp_user_edit_submit"><?php bbp_is_user_home() ? _e( 'Update Profile', 'bbpress' ) : _e( 'Update User', 'bbpress' ); ?></button>
        </div>
    </fieldset>

</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

独自←快乐 2024-12-07 09:32:59
if (isset($_GET['updated']) && $_GET['updated'] == 'true') {
    //do this
}
if (isset($_GET['updated']) && $_GET['updated'] == 'true') {
    //do this
}
万劫不复 2024-12-07 09:32:59

您可以使用$_GET["updated"]。有关 $_GET此处 code> 和其他预定义变量。

You can use $_GET["updated"]. See here for more information on $_GET and the other predefined variables.

末骤雨初歇 2024-12-07 09:32:59

尝试使用 POST 而不是 GET,因为您的表单声明了 POST 方法,并检查提交按钮而不是变量:

if (isset($_POST['bbp_user_edit_submit'])) {
    //do this
}

Try with POST instead of GET, because your form has POST method declared, and checking the submit button instead of a variable:

if (isset($_POST['bbp_user_edit_submit'])) {
    //do this
}
我只土不豪 2024-12-07 09:32:59
if(isset($_REQUEST['updated']) && $_REQUEST['updated'] == "true"){

`//do process`

}
if(isset($_REQUEST['updated']) && $_REQUEST['updated'] == "true"){

`//do process`

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文