0

Edit 2: I traced the code through the php, and realized that it was a faulty header that was causing it to bounce back. I've fixed the header and now the form behaves as it should. Thanks everyone for your help.

EDIT: I noticed the form is quickly refreshing when I submit, so I think it is going to the action page (createlist.php) and immediately bouncing back, so there must be some issue there. Here is the code for createlist.php:

<?php
if (!isset($_SESSION)) {    
    session_start();
}

if (!defined(__DIR__)) {
    define(__DIR__, dirname(__FILE__));
}

require_once(__DIR__.'/../config.php');

//Connect to server and select database.
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE) or die('Cannot connect to server');
//mysql_select_db(DB_DATABASE) or die('Cannot select database');
$tbl_name = 'lists'; //Table name

//Retreive data from form
$listname = $_POST['listName'];
$admin_id = $_SESSION['SESS_MEMBER_ID'];
$listtype = 'list';

//Create listname session variable for catinit.php
$_SESSION['listname'] = $listname;

//Insert new row
$sql = "INSERT INTO $tbl_name(admin_id, listname, listtype) VALUES ('$admin_id', '$listname', '$listtype')";
$result = mysqli_query($link, $sql);


if ($result) {
    header("location: catinit.php");
} else {
    die("Could not create list");
}

//mysql_close();
?>

I have 2 forms on a page, and while it was working before, since adding the backend handling of the information it has broken. Now when I submit either of the forms on the page nothing happens, it does not even attempt to load the action pages. I am completely lost as to what is stopping it from submitting, as everything looks like its working.

<h1>Create a New List</h1>

        <form action = "createlist.php" method = "POST" id = "formId" onsubmit = "formValidate(0, 0, 0, 1, 'formId', 'submitError', event)">    
        <p>List Name:
        <input type = "text" id = "listName" name = "listName" placeholder = "New List" onblur = "listNameValidate('listName','errorName1')" required><span class = "error" id = "errorName1"></span></p>
        </form>

        <h2>Categories</h2>

        <ul class = "catList" id = "list">
        <table>
            <?php

                $cats = array('Produce', 'Meat/Dairy', 'Baked Goods', 'Dry/Canned Goods', 'Household Items');

                //Check to see if Session version of array has different values
                if (isset($_SESSION['catArray']) && $_SESSION['catArray'] != $cats) {
                    $cats = $_SESSION['catArray'];
                } else {
                    $_SESSION['catArray'] = $cats;
                }

                foreach ($cats as $cat) {
                    $index = array_search($cat, $cats);
                    echo '<tr><td><li>'.$cat.'</li></td><td>&nbsp;&nbsp;&nbsp;<a href = "delcat.php?del='.$index.'">Remove</a></td></tr>';
                }
            ?>
        </table>
        </ul>

        New Category: <br>
        <form action = "addcat.php" method = "POST" id = "addcat">
        <input type = "text" id = "newCategory" name = "newCat" placeholder = "Category name" onblur = "listNameValidate('newCategory','errorName2')">
        <input type = "hidden" name = "catArray" value = "<?php echo htmlentities(serialize($cats)); ?>" >
        <input type = "submit" value= "Add" class = "add"><span class = "error" id = "errorName2"></span>
        </form>


        <h2>Invite Members</h2>

            Add a new Member: <br>

            <input type = "email" id = "email" name = "Email" placeholder = "Email Address" onblur = "emailValidate('email', 'errorEmail')">
            <input type = "button" value = "Add" class = "add" ><span class = "error" id = "errorEmail"></span>

        <p><input type = "submit" form = "formId" value = "Create"></p>
        <p class = "submitError" id = "submitError"></p>
Geoff McLennan
  • 418
  • 1
  • 6
  • 15
  • So, what does `formValidate` do? And what does it return? Any errors in the console? This form validator has the power to block the submission. – GolezTrol Mar 17 '16 at 22:54
  • formValidate has the potential to stop submission if some input does not match a certain regex statement. However, I have removed the call to that function completely and the form still does not submit. – Geoff McLennan Mar 17 '16 at 23:00
  • Your second form (invite members) isn't within a `
    ` tag, and the `add` is not a `submit` its a button.
    – dewd Mar 17 '16 at 23:07
  • Even when those two inputs outside of the forms are deleted, nothing happens. – Geoff McLennan Mar 17 '16 at 23:10
  • Within the first form (the one on top), there are no ` – Qirel Mar 17 '16 at 23:24
  • For the first form, the submit button is at the end of the page, connected to the form above using the form = "form_id" attribute, but it still does not successfully submit the form. (And yes I am using a browser with HTML5 enabled) – Geoff McLennan Mar 17 '16 at 23:29
  • Ah, alright - didn't spot that. Can you share the code for `formValidate`? And for the second form ("New Category"), I can't spot anything that seems off. You sure that it doesn't work? The email below "Invite Members" isn't within a form though, so it will never be submitted. – Qirel Mar 17 '16 at 23:32
  • I have disabled all javascript validation on the page and it still doesn't work, so I know the javascript isn't the issue. I actually just noticed that the page is refreshing very quickly when I submit, and I think it is actually going to the action page (createlist.php) and immediately bouncing back but I'm not sure why. I'll update the original question with the contents of that file. – Geoff McLennan Mar 17 '16 at 23:45

0 Answers0