某些字段未以表单形式发布

时间:2013-05-30 04:34:20

标签: html forms post field

我有一个部分有效的表格。我添加了jquery星级评级插件和一个额外的字段(订阅),其中没有一个发布到下一页。我使用了'rating'单选按钮的名称和ID,两者都没有用。所有其他领域都运作良好。

    <html>
<head>
<title>
</title>
<link type="text/css" rel="stylesheet" href="/css/jquery.rating.css" />
<style type="text/css">
  #capcha div {
    float: left;
  } 
  .label {
    width:100px;
    float: left;/*Or however much space you need for the form’s labels*/
  }
  .error {
    color: red;
  }
  .row {
    margin-bottom: 5px;
    clear:both;
  }
  #subscribe {
    font-size: small;
    color: gray;
  }
</style>
<script src="/js/s3Capcha.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/jquery.rating.pack.js"></script>
<script type="text/javascript" src="/js/jquery.MetaData.js"></script>    
<script type="text/javascript">
  $(document).ready(function() {
    $('#capcha').s3Capcha();
    $('.star').rating({
      required: 'hide',
    });
    var id = $("#id").val(),
            rating = $("#rating").val(),
            name = $("#name").val(),
            citystate = $("#citystate").val(),
            email = $("#email").val(),
            message = $("#message").val(),
            subscribe = $("#subscribe").val(),
            s3capcha = $('#capcha input:radio:checked').val();

    var nameVal = $("#name").val();
    if (nameVal == '') {
      $("#name_error").html('');
      $("#name").after('<label class="error" id="name_error">Please enter your name.</label>');
      return false
    }
    else
    {
      $("#name_error").html('');
    }

    /// email validation

    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    var emailaddressVal = $("#email").val();
    if (emailaddressVal == '') {
      $("#email_error").html('');
      $("#email").after('<label class="error" id="email_error">Please enter your email address.</label>');
      return false
    }
    else if (!emailReg.test(emailaddressVal)) {
      $("#email_error").html('');
      $("#email").after('<label class="error" id="email_error">Enter a valid email address.</label>');
      return false
    }
    else
    {
      $("#response").html('');
    }

    jQuery.post("/s3verify.php",
            {
              id: id,
              rating: rating,
              name: name,
              citystate: citystate,
              email: email,
              message: message,
              subscribe: subscribe,
              s3capcha: s3capcha
            },
    function(data) {
      if (data === 'Fail') {
        $("#capcha_error").html('');
        $("#capcha").after('<div style="clear:both"></div><label class="error" id="capcha_error">Verify your pictures selection.</label>');
      } else {
      alert(data);
        var obj = jQuery.parseJSON(data);
        $("#listcomments" + obj.id).append("<div class='rentalcomments'><b>" + obj.score + "!</b> <span class='rentalcomments'>" + obj.message + "</span></div>");
        $("#commentform").dialog('destroy').remove()
      }
    });
    return false;
  });
</script>
</head>
<body>
<?php
$ID = $_GET['ID'];
?>
<div style="padding:20px;autoflow:none;">
  <form>
    <input id="id" type="hidden" name="id" value="<?php echo $ID; ?>"/>
    <fieldset>
      <h3>Make your recommendation:</h3>
      <div class="row">
        <label class='label'>Rating</label>
        <input id="rating" name="rating" type="radio" class="star" Value="1" title="Worst"/>
        <input id="rating" name="rating" type="radio" class="star"  Value="2" title="Bad"/>
        <input id="rating" name="rating" type="radio" class="star" Value="3" title="OK" checked="checked"/>
        <input id="rating" name="rating" type="radio" class="star" Value="4" title="Good"/>
        <input id="rating" name="rating" type="radio" class="star"  Value="5" title="Best"/>
      </div>
      <div class="row">
        <label class='label'>Name</label>
        <input id="name" name="name" size="30" type="text"/>
      </div>
      <div class="row">
        <label class='label'>City, State</label>
        <input id="citystate" name="citystate" value=""/>
      </div>
      <div class="row">
        <label class='label'>Email</label>
        <input id="email" name="email" size="30" type="email"/>
      </div>
      <div class="row">
        <label class='label'>Comments</label>
        <textarea id="message" name="message"></textarea>
      </div>
      <div class="row">
        <label class='label'>Subscribe</label>
        <input id="subscribe" name="subscribe" type="checkbox" value="1" checked /> 
        <span>receive updates on comments made by you.</span>
      </div>
      <div id="capcha"> <?php include("s3Capcha.php"); ?> </div>
      <div style="clear:both"></div>
      <h3> Submit the form</h3>
      <input type="button" id="button" value="submit"><br>
      <label id="response"></label>
    </fieldset>
  </form>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

您需要指定表单操作 - 将数据发送到哪个页面

<form action='next page url' method='POST'>

使用按钮 -

<input type="submit" value="Submit">

可以帮忙!!

编辑:

更改这些 -

<input name="rating" type="radio" class="star" Value="1" title="Worst"/>
    <input name="rating" type="radio" class="star"  Value="2" title="Bad"/>
    <input name="rating" type="radio" class="star" Value="3" title="OK" checked="checked"/>
    <input name="rating" type="radio" class="star" Value="4" title="Good"/>
    <input name="rating" type="radio" class="star"  Value="5" title="Best"/>

和jquery -

rating = $(".star:checked").val()

或 -

rating = $('input[type=radio]:checked').val()

答案 1 :(得分:0)

问题在于:rating =(“#rating”)。val应该是.... rating = $('input:radio [name = rating]:checked')。val(),