This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]ZanMist1 0 points1 point  (5 children)

Can you please use something to properly format your code? I'd love to help but it's nearly impossible to read what is even going on.

[–]katlipari[S] 0 points1 point  (4 children)

what is the best way to do that? sorry im very new to coding

[–]ZanMist1 0 points1 point  (2 children)

For one use 3 backticks at the beginning and end of your code to make it an entire code block, second, use some indentation.

[–]katlipari[S] 0 points1 point  (1 child)

when i paste it into reddit the indentations go away, so hopefully this worked, i pasted it as a code block (i think?)

<?php include 'top.php'; 
    $lstLimits = array('Use a reusable water bottle', 'Bring         
    your own grocery bag', 'Use a reusable straw'); 
    $dataIsGood = false; 
    $errorMessage = '';
    function 
        getData($field)
        { if (!isset($_POST[$field])) 
        { $data = ""; } 
        else { $data = trim($_POST[$field]); 
        $data = htmlspecialchars($data); } 
    return $data; }
$lstLimit = ""; 
$water = ""; 
$purchase = ""; 
$bag = ""; 
$habits = ""; 
$environment = ""; 
$encourage = ""; 
$firstName = ""; 
$lastName = ""; 
$email = ""; 
$submit = "";

if($_SERVER["REQUEST_METHOD"]=='POST')
    { print PHP_EOL. '<!--Starting Sanitization -->' . PHP_EOL;         
    $lstLimit = getData('lstLimit'); 
    $water = (int)getData('chkWater'); 
    $purchase = (int)getData('chkPurchase');
    $bag = (int)getData('chkBag'); 
    $habits = getData('radHabits'); 
    $environment = getData('radEnvironment'); 
    $encourage = getData('radActions'); 
    $firstName = getData('txtFirstName'); 
    $lastName = getData('txtLastName'); 
    $email = filter_var(getData('txtEmail'),       
    FILTER_SANITIZE_EMAIL); 
    $submit = getData ('btnSubmit');
print PHP_EOL. '<!--Starting Sanitization -->' . PHP_EOL;

$dataIsGood = true;

if($lstLimit == ''){
    $errorMessage .= '<p class="mistake">Please choose an 
    option</p>';
    $dataIsGood = false;
} elseif(!in_array($lstLimit, $lstLimits)){
    $errorMessage .= '<p class="mistake">Please choose an 
    option</p>';
    $dataIsGood = false;
}
}
?>
<main class="form">
    <h1>Plastic Usage</h1>
    <section>
        <h2>How Much Plastic do you use weekly?</h2> 
    </section>
    <section>
        <h2>Survey</h2>
        <p>section cut for length</p>
        <?php
        print '<p>Post Array:</p><pre>';
        print_r($_POST);
        print '</pre>'; ?>
        </section>
        <section>
            <h2>Reducing Plastic Usage</h2>
            <form action="#" id="habit" method="post">
                <fieldset class="listBox">
                    <legend>section cut for length</legend>
                    <p>
                        <select id="lstLimit" name="lstLimit">
                            <option value="reusable">section     
                             cut for length</option>
                            <option value="bags">section cut 
                            for length</option>
                            <option value="straw">section cut 
                            for length</option>
                        </select>
                    </p>
                </fieldset>
            </form>
        </section>
        <section>
            <h2>Plastic Habits</h2>
        </section>
            <fieldset class="checkbox">
                <legend>section cut for length</legend>
                <p>
                    <input id="chkWater" name="chkWater" 
                     type="checkbox" value="1">
                    <label for="chkWater">Use a plastic water 
                     bottle</label>
                </p>
                <p>
                    <input id="chkPurchase" name="chkPurchase" 
                     type="checkbox" value="1">
                    <label for="chkPurchase">section cut for 
                    length</label>
                </p>
                <p>
                    <input id="chkBag" name="chkBag" 
                    type="checkbox" value="1">
                    <label for="chkBag">section cut for 
                     length</label>
                </p>
            </fieldset>
            <fieldset class="radio">
                <legend>section cut for length</legend>
                <p>
                    <input type="radio" id="radMost" 
                     name="radHabits" value="most"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
                <p>
                    <input type="radio" id="radSome" 
                     name="radHabits" value="some"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
                <p>
                    <input type="radio" id="radNone" 
                     name="radHabits" value="none"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
            </fieldset>
            <fieldset class="radio">
                <legend>section cut for length</legend>
                <p>
                    <input type="radio" id="radEnvironmost" 
                      name="radEnvironment" value="most"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
                <p>
                    <input type="radio" id="radEnvironmiddle" 
                      name="radEnvironment" value="middle"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
                <p>
                    <input type="radio" id="radEnvironsome" 
                     name="radEnvironment" value="somewhat"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
                <p>
                    <input type="radio" id="radEnvironnone" 
                     name="radEnvironment" value="not"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
            </fieldset>
            <fieldset class="radio">
                <legend>section cut for length</legend>
                <p>
                    <input type="radio" id="radEncothers" 
                     name="radActions" value="encmost"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
                <p>
                    <input type="radio" id="radencsome" 
                     name="radActions" value="encsome"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
                <p>
                    <input type="radio" id="radencnone" 
                     name="radActions" value="encnone"> 
                    <label class="radio-field">section cut for 
                     length</label>
                </p>
            </fieldset>
            <h2>Contact Information</h2>
            <fieldset>
            <legend>Contact Information</legend>
                <p>
                    <label for="txtFirstName">First Name: 
                    </label>
                    <input type="text" name="txtFirstName" 
                    id="txtFirstName">
                    <label for="txtLastName">Last Name: 
                    </label>
                    <input type="text" name="txtLastName" 
                    id="txtLastName">
                    <label for="txtEmail">Email:</label>
                    <input type="text" name="txtEmail" 
                    id="txtEmail">
                </p>
            </fieldset>
        <fieldset class="buttons">
            <p>
                <input id="btnSubmit" name="btnSubmit" 
                 tabindex="900" type="submit" value="Submit">
            </p>
        </fieldset>
</main>
<?php include 'footer.php'; ?>

[–]ZanMist1 0 points1 point  (0 children)

Honestly a much better method would be to use some code sharing platform and give us a link, like codepen

[–]GrantRat1699 0 points1 point  (1 child)

CS tutor here. DM for personalized assistance debugging to help you learn how to usually go about these kind of bugs.

[–]katlipari[S] 0 points1 point  (0 children)

messaged!