客户端和服务器端无法正常工作

时间:2016-08-07 06:42:15

标签: javascript jquery validation

我的客户端和服务器端都有一个大问题,我需要帮助 当按下第三个表单的saveentry按钮时,我必须从两个表单中收集数据并在验证后提交数据,但我感到困惑。值不会显示,服务器端验证不起作用。我有两种形式,必须经过客户端和服务器端验证。我使用onsubmit,以便在发布表单时检查值,这是代码:



function validation() {
  person_name = $('#person_name').val();
  if (test_name == '') {
    $('#test_name').parent().append('<div class="error">Please fill this field</div>');
    errors = true;
  }
  if (errors) {
    return false;
  } else {
    var personname = ("<h1>" + person_name + "</h1>");
    $('#display').append('<div class = "display">' + personname + '</div>');

  }
}
&#13;
&#13;
&#13;

&#13;
&#13;
function validation1(){
  var product_name = $('#product_name').val();
  if(product_name == ''){
    $('#product_name').parent().append('<div class="error">Please fill this field</div>');
    // the other fields are validated as well
    errors = true;					
  } 
  if(errors){
    return false;
  }
  else{
    // the values are appended to display
  }
}
&#13;
&#13;
&#13;

表单看起来像这样

&#13;
&#13;
<form name = "person" action = "" onsubmit= "return validation" method=" post" >
  <input type="text" name = "personname" id = "personname">
</form>

<form name = "products" action = "" method = "post" onsubmit= "return   validation1">
  <input type="text" name = "productname" id = "productname">
  <input type="text" name = "company" id = "company">
  <input type="text" name = "location" id = "location">
</form>

<form name = "display" id = "display" action = "saveentry.php" method = "post">
</form>
&#13;
&#13;
&#13;

检查值的PHP代码如下

if(empty($_POST['fieldname'])){
    //An error is displayed.
}

非常欢迎任何帮助!

1 个答案:

答案 0 :(得分:0)

尝试下一步:

    <h4><?php _e( 'Change Profile Photo', 'buddypress' ); ?></h4>

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

<?php if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?>

    <p><?php _e( 'Your profile photo will be used on your profile and throughout the site. If there is a <a href="http://gravatar.com">Gravatar</a> associated with your account email we will use that, or you can upload an image from your computer.', 'buddypress' ); ?></p>

    <form action="#item-nav" method="post" id="avatar-upload-form" class="standard-form" enctype="multipart/form-data">

        <?php if ( 'upload-image' == bp_get_avatar_admin_step() ) : ?>

            <?php wp_nonce_field( 'bp_avatar_upload' ); ?>
            <p><?php _e( 'Click below to select a JPG, GIF or PNG format photo from your computer and then click \'Upload Image\' to proceed.', 'buddypress' ); ?></p>

            <p id="avatar-upload">
                <input type="file" name="file" id="file" />
                <input type="submit" name="upload" class="button tiny radius" id="upload" value="<?php _e( 'Upload Image', 'buddypress' ); ?>" />
                <input type="hidden" name="action" id="action" value="bp_avatar_upload" />
            </p>

            <?php if ( bp_get_user_has_avatar() ) : ?>
                <p><?php _e( "If you'd like to delete your current profile photo but not upload a new one, please use the delete profile photo button.", 'buddypress' ); ?></p>
                <p><a class="button edit" href="<?php bp_avatar_delete_link(); ?>" title="<?php esc_attr_e( 'Delete Profile Photo', 'buddypress' ); ?>"><?php _e( 'Delete My Profile Photo', 'buddypress' ); ?></a></p>
            <?php endif; ?>

        <?php endif; ?>

        <?php if ( 'crop-image' == bp_get_avatar_admin_step() ) : ?>

            <h5><?php _e( 'Crop Your New Avatar', 'buddypress' ); ?></h5>


            <img src="<?php bp_avatar_to_crop(); ?>" id="avatar-to-crop" class="avatar" alt="<?php _e( 'Avatar to crop', 'buddypress' ); ?>" />

            <div id="avatar-crop-pane">
                <img src="<?php bp_avatar_to_crop(); ?>" id="avatar-crop-preview" class="avatar" alt="<?php _e( 'Avatar preview', 'buddypress' ); ?>" />
            </div>

            <input type="submit" class="button small radius" name="avatar-crop-submit" id="avatar-crop-submit" value="<?php _e( 'Crop Image', 'buddypress' ); ?>" />

            <input type="hidden" name="image_src" id="image_src" value="<?php bp_avatar_to_crop_src(); ?>" />
            <input type="hidden" id="x" name="x" />
            <input type="hidden" id="y" name="y" />
            <input type="hidden" id="w" name="w" />
            <input type="hidden" id="h" name="h" />

            <?php wp_nonce_field( 'bp_avatar_cropstore' ); ?>

        <?php endif; ?>

    </form>

<?php else : ?>

    <p><?php _e( 'Your profile photo will be used on your profile and throughout the site. To change your profile photo, please create an account with <a href="http://gravatar.com">Gravatar</a> using the same email address as you used to register with this site.', 'buddypress' ); ?></p>

<?php endif; ?>

<?php do_action( 'bp_after_profile_avatar_upload_content' ); ?>
相关问题