3 Replies - 836 Views - Last Post: 18 March 2011 - 05:30 AM

#1 xtremer360   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 125
  • Joined: 03-March 11

Not displaying form fields and values

Posted 17 March 2011 - 03:30 PM

I'm trying to figure out why its not putting into the array any o the fields and its value that I have filled out inside the form. All its showing with the post parameters is the defaultCharID and the editBio.


$(document).ready(function() {
    $('div.message-error').hide();
    $('div.message-success').hide();
    
    $("#bioForm").validate({ 
        submitHandler: function(form) {
            var defaultCharID = $("input#defaultCharID").val();
            var data = ''; 
            if($('field').val() !== "" || $('field').val() !== undefined || $('field').val() !== null){ 
                data += 'postVarName'+$('field').val()+'&';
            }
            data = 'defaultCharID=' + defaultCharID + '&editBio=True';
            $.ajax({
                type: "POST",
                url: "processes/bios.php",
                data: data,
                success: function(myNewVar) { 
                    if (myNewVar == 'good') {
                        $('div.message-error').hide();
                        $("div.message-success").html("<h6>Operation successful</h6><p>Bio saved successfully.</p>");
                        $("div.message-success").show().delay(10000).hide("slow");
                        $('','#bioForm')
                        .not(':input, :submit, :hidden')
                        .val('');   
                    } else {
                        $('div.message-success').hide();
                        $("div.message-error").html("<h6>Operation unsuccessful</h6><p>Bio was not saved in the database.</p>");
                        $("div.message-error").show();    
                    }
                }
            });
            return false;
        }    
    });                                                          		
});



<?php require ('php/bios.php'); ?>

<script type="text/javascript" src="forms/edit/js/bios.js"></script>

<!-- Title -->
<div id="title" class="b2">
    <h2>Character Management</h2>
</div>
<!-- Title -->

<!-- Inner Content -->
<div id="innerContent">
    
    <form action="#" id="bioForm" >
        <?php 
            while ($row = mysqli_fetch_array($groupsResult, MYSQL_ASSOC)) {
                echo "<fieldset>
                <legend>" . $row['groupName'] . "</legend>";
                $fieldsResult = mysqli_query ( $dbc, sprintf($fieldsQuery,$row['ID']) );
                while ($row2 = mysqli_fetch_array($fieldsResult, MYSQL_ASSOC)) {
                   echo "<div class=field required>";
                   if ($row2['inputType'] == "text") {
	                   echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>";
                       echo "<input type=text name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=text title=" . $row2['fullName'] . " />";     
                   } elseif ($row2['inputType'] == "textarea") {
                       echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>";
                       echo "<textarea name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=textarea title=" . $row2['fullName'] . " />";
                   } else {
                       echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>";

echo "<select name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=dropdown title=" . $row2['fullName'] . " >";
echo "<option value= >None</option>";
if ($styleID == 1 || $styleID == 2 || $styleID == 6) {
                         $charactersQuery = "
                                SELECT 
                                    characters.ID, 
                                    characters.characterName 
                                FROM 
                                    characters 
                                WHERE 
                                    characters.styleID = 3
                                ORDER BY 
                                    characters.characterName";
}
else {
                         $charactersQuery = "
                                SELECT 
                                    characters.ID, 
                                    characters.characterName 
                                FROM 
                                    characters 
                                WHERE 
                                    characters.styleID IN (1,2,6)
                                ORDER BY 
                                    characters.characterName";
}

$charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query

while ( $row3 = mysqli_fetch_array ($charactersResult, MYSQLI_ASSOC)) { 
   echo "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r";
}

   echo "</select>";
}


                   echo "</div>";
                }
                echo "</fieldset>";
            } 
        ?>
        <fieldset>
            <input type="hidden" name="defaultCharID" id="defaultCharID" value="<?php echo $defaultCharID; ?>" /> 
            <input type="submit" class="submit" id="editBio" title="Edit Bio" value="Edit Bio" />
        </fieldset>
    </form>

</div>
<!-- /Inner Content -->



Is This A Good Question/Topic? 0
  • +

Replies To: Not displaying form fields and values

#2 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Not displaying form fields and values

Posted 17 March 2011 - 03:48 PM

That's because that's all your sending in your post:
 data = 'defaultCharID=' + defaultCharID + '&editBio=True';



To get all your form inputs use .serialize() on your form.
Was This Post Helpful? 1
  • +
  • -

#3 xtremer360   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 125
  • Joined: 03-March 11

Re: Not displaying form fields and values

Posted 17 March 2011 - 03:51 PM

look at the if statement that's supposed to add the field and its value if there is input for the field.
Was This Post Helpful? 0
  • +
  • -

#4 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Not displaying form fields and values

Posted 18 March 2011 - 05:30 AM

The line
data = 'defaultCharID=' + defaultCharID + '&editBio=True';



Assigns the value of data to just that string. You would need to do data += to add onto it, like you did in your if statement.

This post has been edited by Jstall: 18 March 2011 - 05:30 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1