0

I'm trying to submit inputs from my multistep form to database (temporary table) but nothing happens when i click on Submit button. I can't figure out what's wrong as it doesn't show any errors on Console Logs on different browsers. I need it to save form inputs to temporary table first before asking the users to login at the last part of the form.

Here's the code of my multistep form.

Index.html

<!doctype HTML>
<html>
<head>
<!-- jQuery easing plugin -->
<script src="http://sandbox.lookingfour.com/forms/multistepform/jquery.easing.min.js" type="text/javascript"></script>
<script src="http://sandbox.lookingfour.com/forms/multistepform/script.js" type="text/javascript"></script>
<script src="http://www.lookingfour.com/js/temporary_buyinfo.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://sandbox.lookingfour.com/forms/multistepform/style.css">
</head>
<body>
<table>
  <tr class='popupbox-header'>      
    <td>
      <span id='buytitle'></span>
      <a href='' onclick='buyform_back(); return false;'>x</a>
    </td>
  </tr>
<!-- multistep form -->
<tr>
<td>
<div id="msform">
  <!-- progressbar -->
  <ul id="progressbar">
    <li class="active">Account Setup</li>
    <li>Social Profiles</li>
    <li>Personal Details</li>
  </ul>
  <!-- fieldsets -->
    <fieldset>
    <h2 class="fs-title">First Step</h2>
    <h3 class="fs-subtitle">This is step 1</h3>
    <label>Quantity</label>
    <?php echo input_textbox('buyqty', 1, "class='numeric'",'number'); ?><span class="formdata-required">*</span><br>
    <label>Condition </label>
    <select id = 'buycondition'>
      <option value = "New">New</option>
      <option value = "Used">Used</option>
    </select><br>
      <table>
      <tr>
      <td id='buyerexamples' ></td></br>
      </tr>
      </table>
    <input type="button" name="next" class="next action-button" value="Next" />
  </fieldset>
  <fieldset>
    <h2 class="fs-title">Second Step</h2>
    <h3 class="fs-subtitle">This is step 2</h3>
    <label>Deadline</label>
    <?php echo input_datebox('buydeadline', date('m/d/Y', strtotime("+7 days")), 1); ?>
    <span class="formdata-required">*</span><br>
    <label>Notes / Message</label>
    <textarea id='buynotes' style='width: 70%; height:90px;'></textarea>
    <input type="button" name="previous" class="previous action-button" value="Previous" />
    <input type="button" name="next" class="next action-button" value="Next" />
  </fieldset>
  <fieldset>

    <h2 class="fs-title">Third Step</h2>
    <h3 class="fs-subtitle">This is step 3</h3>
    <div id='response'></div>
    <label>Location/Area</label>
              <select id = 'buylocation'>
                <option value = "Metro Manila">Metro Manila</option>
                <option value = "Abra">Abra</option>
                <option value = "Agusan del Norte">Agusan del Norte</option>
                <option value = "Agusan del Sur">Agusan del Sur</option>
              </select>
              <span class="formdata-required">*</span><br>
              <label>Budget</label>
              <?php echo input_textbox('buybudget','','placeholder="i.e. 5000 or 3500" style="width: 65%;"', '','text'); ?><br>
      <input type="button" name="previous" class="previous action-button" value="Previous" />
      <input type='submit' value='Submit' />
            <?php
              if (util_getuserid() == 0) {
                echo input_button('Save-In', '', 'id="buyloginbtn"  class="popup-button" style="background-color: #ea6e38;"');
                echo input_button('Sign-In', 'buyform_login("buyuser_login","buyuser_password","buyloginmsg");', 'id="buyloginbtn"  class="popup-button" style="background-color: #ea6e38;"');
              } else {
                echo input_button('Look for Suppliers', 'buyerform_post();', ' class="popup-button" style="background-color: #ea6e38;"');
              }
            ?>
  </fieldset>
</div>
<div class='menu-loginform' id='buyloginform' style="display:none;">
        <table width=100%>
          <tr>
            <td>
              <label style='text-align: left;'>Sign-In to proceed</label>
            </td>
          </tr>
          <tr>
            <td>
              <label style='text-align: left;'>Username / e-mail</label>
              <?php echo input_textbox('buyuser_login', '', 'class="popup-inputbox"', 'buyloginbtn'); ?>
            </td>
          </tr>
          <tr>
            <td>
              <label style='text-align: left;'>Password</label>
              <?php echo input_textbox('buyuser_password', '', 'class="popup-inputbox"', 'buyloginbtn','password'); ?>
              <a href='' OnClick='user_createtoplogin(); return false;' style='float: left;' id='buyform-createaccount'>Create a new account</a>
            </td>
          </tr>
          <tr>
            <td align=center>
              <div id='buyloginmsg' class="formdata-required" style="display:none;"></div>
            </td>
          </tr>
          <tr>
            <td>
            <?php
              if (util_getuserid() == 0) {
                echo input_button('Sign-In', 'buyform_login("buyuser_login","buyuser_password","buyloginmsg") && buyerform_post();', 'id="buyloginbtn"  class="popup-button" style="background-color: #ea6e38;"');
                echo input_button('Sign-In FB', 'Login()', 'id="status"  class="popup-button" style="background-color: #ea6e38;"');
              } else {
                echo input_button('Look for Suppliers', 'buyerform_post();', ' class="popup-button" style="background-color: #ea6e38;"');
              }
            ?>
            </td>
        </tr>
        </table>
      </div>
</td>
</tr>
</table>
<script>
$(document).ready(function(){
    $('#msform').submit(function(){

        // show that something is loading
        $('#response').html("<b>Loading response...</b>");

        /*
         * 'post_receiver.php' - where you will pass the form data
         * $(this).serialize() - to easily read form data
         * function(data){... - data contains the response from post_receiver.php
         */
        $.ajax({
            type: 'POST',
            url: 'http://www.lookingfour.com/jquery/serialize.php', 
            data: $(this).serialize()
        })
        .done(function(data){

            // show the response
            $('#response').html(data);

        })
        .fail(function() {

            // just in case posting your form failed
            alert( "Posting failed." );

        });

        // to prevent refreshing the whole page page
        return false;

    });
});
</script>
</body>
</html>

Serialize.php

<?php
require_once(dirname(dirname(__FILE__))."/templates/initialize.inc");
$global_connection = db_connect();

    if($_POST["buylocation"] != '') {
    $buyinfo_temp = db_saverecord("buyinfo_temp", array(
                                    'buyinfo_location'=>$_POST['buylocation'],
                                    'buyinfo_notes'=>$_POST['buynotes'],
                                    'buyinfo_condition'=>$_POST['buycondition'],
                                ), 0, $global_connection);
}
?>
4
  • 5
    Where are your <form> tags? Commented Dec 14, 2015 at 7:53
  • Include <form> tag in your code.and then make submit event. Commented Dec 14, 2015 at 8:00
  • It doesn't have any. Should I add or replace? Commented Dec 14, 2015 at 8:01
  • Nothing happens even if I replace the div to form. Commented Dec 14, 2015 at 8:09

2 Answers 2

1

You are trying to submit a div. You can only submit a form. Replace

<div id="msform">
...
</div>

with

<form id="msform">
....
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

form loses its style. but still doesnt send details to db.
0

I think you should include jquery library <script src="https://code.jquery.com/jquery-2.1.4.js"></script> before

<script src="http://sandbox.lookingfour.com/forms/multistepform/jquery.easing.min.js" type="text/javascript"></script>

in PHP file, use $_POST instead of $_REQUEST

After i added jquery lib, it working

7 Comments

I think it is working now but not totally. Doesnt save info to db still. plus I think it creates conflict with other functions namely autocomplete and datepicker.
in PHP file, use $_POST instead of $_REQUEST
you try change $('#msform').submit(function(){ to $("input[type='submit']").click(function(){
still doesnt save to db. No error aside from the conflict to autocomplete and datepicker function.
I'm adding this to integrate fb login at the final part of the form. You might know a different approach like reloading back the user to the filledup form after fb login or anything that might be simplier than this.,
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.