Question

NEWB here working with a lot of things that are a little beyond their ability (trying to learn). In a nutshell, i'm building a form that allows someone report an incident with a giant kaiju (Godzilla, Cloverfield, Gamera, whatever giant monster you like - it's silly but it motivates me). My form is working as hoped in all respects but one, when i submit data through the form, i get an error message that reads 'Required Form Data Not Passed'.

I've gone over the form for the last two hours and i can't figure out what i've done wrong - i'm sure its something simple but whatever it is it's beyond me. I've tried to google an answer and looked through stackOverflow, etc - but i've not found an answer that i can internalize enough to figure out what i'm doing incorrectly.

A working version of the form can be seen here

CODE:

    <?php //w05c09b_OOPincidentReport.php

require '../inc_0700/config_inc.php'; #provides configuration, pathing, error handling, db credentials
//END CONFIG AREA ----------------------------------------------------------
# Read the value of 'action' whether it is passed via $_POST or $_GET with $_REQUEST
if(isset($_REQUEST['act'])){$myAction = (trim($_REQUEST['act']));}else{$myAction = "";}
switch ($myAction)
{//check 'act' for type of process
    case "add": //2) Form for adding new report
        addReport();
        break;
    case "insert": //3) Insert new report
        insertExecute();
        break;
    default: //1)Show existing Reports
        showReport();
}
function showReport()
{//Select Customer
    global $config;
    get_header();
    echo '<h3 align="center">' . smartTitle() . '</h3>';

    $sql = 'select kID, incWho, incWhat, incWhen from incKaiju';
    $result = mysqli_query(IDB::conn(),$sql) or die(trigger_error(mysqli_error(IDB::conn()), E_USER_ERROR));
    if (mysqli_num_rows($result) > 0)//at least one record!
    {//show results
        echo '<table align="center" border="1" style="border-collapse:collapse" cellpadding="3" cellspacing="3">';
        echo '<tr>
                <th>Kaiju Incident Report</th>
                <th>Officer Reporting</th>
                <th>Kaiju Identified</th>
                <th>Date of Incident</th>
            </tr>
            ';
        while ($row = mysqli_fetch_assoc($result))
        {//dbOut() function is a 'wrapper' designed to strip slashes, etc. of data leaving db
            echo '<tr>
                    <td>Kid00' . (int)$row['kID'] . '</td>
                    <td>Officer ' . dbOut($row['incWho']) . '</td>
                    <td>' . dbOut($row['incWhat']) . '</td>
                    <td>' . dbOut($row['incWhen']) . '</td>
                </tr>
                ';
        }
        echo '</table>';
    }else{//no records
      echo '<div align="center"><h3>Currently No Customers in Database.</h3></div>';
    }
    echo '<div align="center"><a href="' . THIS_PAGE . '?act=add"><br />ADD REPORT</a></div>';
    @mysqli_free_result($result); //free resources
    get_footer();
}
function addReport()
{# shows details from a single customer, and preloads their first name in a form.
    global $config;

    //Inject my styles and crap here

    $config->loadhead .= '
    <script type="text/javascript" src="' . VIRTUAL_PATH . 'include/util.js"></script>
    <script type="text/javascript">
        function checkForm(thisForm)
        {//check form data for valid info
            if(empty(thisForm.incWho,"Reporting Officer ")){return false;}
            if(empty(thisForm.incWhat,"Confirm Kaiji ")){return false;}
            if(empty(thisForm.incWhen,"Date of Incident ")){return false;}

            if(!isEmail(thisForm.Email,"Please Enter a Valid Email")){return false;}
            return true;//if all is passed, submit!
        }
    </script>';

    get_header();
    echo '
    <h3 align="center">' . smartTitle() . ' List + Add + Insert</h3>
    <h4 align="center">Enter Report</h4>
    <form action="' . THIS_PAGE . '" method="post" onsubmit="return checkForm(this);">
    <table align="center">
       <tr><td align="right">Reporting Officer</td>
            <td>
                <input type="text" name="incWho" />
                <font color="red"><b>*</b></font> <em>(alphanumerics & punctuation)</em>
            </td>
       </tr>
       <tr><td align="right">Confirm Kaiji</td>
            <td>
                <input type="text" name="incWhat" />
                <font color="red"><b>*</b></font> <em>(alphanumerics & punctuation)</em>
            </td>
       </tr>
       <tr><td align="right">Date of Incident </td>
            <td>
                <input type="text" name="incWhen" />
                <font color="red"><b>*</b></font> <em>(alphanumerics & punctuation)</em>
            </td>
       </tr>
       ';

       echo '<input type="hidden" name="act" value="insert" />
       <tr>
            <td align="center" colspan="2">
                <input type="submit" value="Submit Report"><em>(<font color="red"><b>*</b> required field</font>)</em>
            </td>
       </tr>
    </table>
    </form>
    <div align="center"><a href="' . THIS_PAGE . '">Exit (Do not submit Incident Report)</a></div>
    ';
    get_footer();
}

function insertExecute()
{
    $iConn = IDB::conn();//must have DB as variable to pass to mysqli_real_escape() via iformReq()
    $redirect = THIS_PAGE; //global var used for following formReq redirection on failure
    $incWho = strip_tags(iformReq('incWho', $iConn));
    $incWhat = strip_tags(iformReq('incWhat', $iConn));
    $incWhen = strip_tags(iformReq('incWhen', $iConn));
    $Email = strip_tags(iformReq('Email',$iConn));
    //next check for specific issues with data
    if(!ctype_graph($_POST['incWho'])|| !ctype_graph($_POST['incWhat'])|| !ctype_graph($_POST['incWhen']))
    {//data must be alphanumeric or punctuation only
        feedback("First and Last Name must contain letters, numbers or punctuation");
        myRedirect(THIS_PAGE);
    }
    if(!onlyEmail($_POST['Email']))
    {//data must be alphanumeric or punctuation only
        feedback("Data entered for email is not valid");
        myRedirect(THIS_PAGE);
    }
    $sql = "INSERT INTO incKaiju (incWho, incWhat, incWhen) VALUES ('%s','%s','%s')";
    $sql = sprintf($sql,$incWho,$incWhat,$incWhen);
    @mysqli_query($iConn, $sql) or die(trigger_error(mysqli_error($iConn), E_USER_ERROR));
    #feedback success or failure of update
    if (mysqli_affected_rows($iConn) > 0)
    {//success!  provide feedback, chance to change another!
        feedback("Report added successfully!","notice"); //notice changes color to red!
    }else{//Problem!  Provide feedback!
        feedback("Report failed to submit!");
    }
    myRedirect(THIS_PAGE);
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top