Greetings!

I created this form that works like a charm, captures data in my db and sends email.

Suppose user Joe hits the RESET button before he clicks SUBMIT, all fields are reset. If Joe hits the RESET button AFTER he clicked SUBMIT (e.g. to make a new submission)...nothing gets reset.

Here's my code...............

...        <form enctype="multipart/form-data" method="post" name="webform" onsubmit="return validate(this)" action="<?php echo $_SERVER['PHP_SELF'];?>">
            <h2>Title of request:</h2>
            <input type="text" tabindex="0" name="request_title"  maxlength="255" size="62"
                   value='<?php echo $_POST['request_title'];?>'
                   ><br><br>
            <h2>Please describe your request in detail:</h2><br>
            <textarea tabindex="1"  name="request_description" cols="87" rows="10" ><?php echo $_POST['request_description'];?></textarea>
            <table border="0" cellspacing="3" cellpadding="3">
                <tbody>
                    <tr>
                        <td><fieldset id="output"><legend>Output Options: </legend>
                                <input type="checkbox" tabindex="2" id="chb0" name="check_output[]" value="CSV" <?php if(isset($_POST['check_output']) && in_array('CSV', $_POST['check_output'])) echo ' CHECKED ';?>>CSV<br>
                                <input type="checkbox" tabindex="3" id="chb1" name="check_output[]" value="Excel" <?php if(isset($_POST['check_output']) && in_array('Excel', $_POST['check_output'])) echo ' CHECKED ';?>>Excel<br>
                                <input type="checkbox" tabindex="4" id="chb2" name="check_output[]" value="Email" <?php if(isset($_POST['check_output']) && in_array('Email', $_POST['check_output'])) echo ' CHECKED ';?>>Email<br>
                                <input type="checkbox" tabindex="5" id="chb3" name="check_output[]" value="HTML" <?php if(isset($_POST['check_output']) && in_array('HTML', $_POST['check_output'])) echo ' CHECKED ';?>>HTML<br>
                                <input type="checkbox" tabindex="6" id="chb4" name="check_output[]" value="None" <?php if(isset($_POST['check_output']) && in_array('None', $_POST['check_output'])) echo ' CHECKED ';?>>None<br>
                                <input type="checkbox" tabindex="7" id="chb5" name="check_output[]" value="PDF" <?php if(isset($_POST['check_output']) && in_array('PDF', $_POST['check_output'])) echo ' CHECKED ';?>>PDF<br>
                            </fieldset></td>
                        <td><fieldset> <legend>Frequency: </legend>
                                <input type="radio" id="rad0" tabindex="8" name="Frequency" value="One Time" <?php echo ($_POST['Frequency']=="One Time")?"CHECKED":""; ?>>One Time<br>
                                <input type="radio" id="rad1" tabindex="9" name="Frequency" value="Daily" <?php echo ($_POST['Frequency']=="Daily")?"CHECKED":""; ?>>Daily<br>
                                <input type="radio" id="rad2" tabindex="10" name="Frequency" value="Weekly" <?php echo ($_POST['Frequency']=="Weekly")?"CHECKED":""; ?>>Weekly<br>
                                <input type="radio" id="rad3" tabindex="11" name="Frequency" value="Monthly" <?php echo ($_POST['Frequency']=="Monthly")?"CHECKED":""; ?>>Monthly<br>
                                <input type="radio" id="rad4" tabindex="12" name="Frequency" value="Ongoing" <?php echo ($_POST['Frequency']=="Ongoing")?"CHECKED":""; ?>>Ongoing<br>
                            </fieldset></td>
                        <td><fieldset> <legend>Request Type: </legend>
                                <table border="0" cellspacing="3" cellpadding="3">
                                    <tbody>
                                        <tr>
                                            <td><fieldset id="myfieldset"> <legend>Data: </legend>
                                                    <input type="radio" id="req0" tabindex="13" name="request_type" value="Add Data" <?php echo ($_POST['request_type']=="Add Data")?"CHECKED":""; ?>>Add<br>
                                                    <input type="radio" id="req1" tabindex="14" name="request_type" value="Extract Data" <?php echo ($_POST['request_type']=="Extract Data")?"CHECKED":""; ?>>Extract<br>
                                                    <input type="radio" id="req2" tabindex="15" name="request_type" value="Update Data" <?php echo ($_POST['request_type']=="Update Data")?"CHECKED":""; ?>>Update<br>
                                                    <input type="radio" id="req3" tabindex="16" name="request_type" value="Validate Data" <?php echo ($_POST['request_type']=="Validate Data")?"CHECKED":""; ?>>Validate<br>
                                                </fieldset></td>
                                            <td><fieldset id="myfieldset"> <legend>Report: </legend>
                                                    <input type="radio" id="req4" tabindex="17" name="request_type" value="New Report" <?php echo ($_POST['request_type']=="New Report")?"CHECKED":""; ?>>New<br>
                                                    <input type="radio" id="req5" tabindex="18" name="request_type" value="Modify Report" <?php echo ($_POST['request_type']=="Modify Report")?"CHECKED":""; ?>>Modify<br>
                                                </fieldset></td>
                                            <td><fieldset id="myfieldset"> <legend>Table: </legend>
                                                    <input type="radio" id="req6" tabindex="19" name="request_type" value="New Table" <?php echo ($_POST['request_type']=="New Table")?"CHECKED":""; ?>>New<br>
                                                    <input type="radio" id="req7" tabindex="20" name="request_type" value="Modify Table"  <?php echo ($_POST['request_type']=="Modify Table")?"CHECKED":""; ?>>Modify<br>
                                                </fieldset></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </fieldset></td></tr>
                </tbody>
            </table>
            <br>
            <input type="hidden" value="Created" name="status">
            <input type="submit" id="sd" tabindex="24" value="submit" name="submit">
            <input type="reset" onclick="resetform();" id="rs"  tabindex="25"  name="reset" value="reset">
        </form>...

I created a small javascript that I called the head() section of my page.

function resetform(form) {
    // resets title
document.forms[0].request_title.value = "";
...///you get the idea...
}

Nothing happens!! What am I doing wrong?

I'm not clear as to why you have a customized reset rather than a simple html reset but I don't think that is the problem. I'm guessing that reset is clearing the values in the boxes but the fact that you have it defined to load values into those variables (the previous values entered) is probably still happening after the form is reset. I think you will probably have to change the code to clear those previous values and only return them if the user chooses to update them. If the form is accepted then I think that you must clear the previous values before displaying the form again.

Member Avatar for diafol

A normal reset button will change values back to their original startup values - not set them to empty, so placing php derived values at the server will make these values the originals.

You're trying to empty the values right? Your problem is that you've used a html reset button to run your js script. Change the input type to 'button'. This should then work.

The html reset button will not do anything if it doesn't perceive a change in data. *I think*

i had a major headache with this not too long ago, as far as i remeber i just reloaded the page with an onClick event, might not be the best method but worked like a charm for me.

Hope it helps...

Sigh....I edited my code from

<input type="reset" onclick="resetform();" id="rs"  tabindex="25"  name="reset" value="reset">

to

<input type="BUTTON" onclick="resetform();" id="rs"  tabindex="25"  name="reset" value="reset">

It worked!!!

....I gotta go. I need some private time to smack myself....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.