Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    onclick to form & sending $_POST issue

    Hi guys,

    I'm having an issue trying to accomplish this. Basically what I'm trying to do is $_POST the values of the form and echo them on the page, along with displaying another form once submited.

    The posting works fine, however the form that I want to appear, does so for a second then disappears as if it's returning false.

    I've tried changing my code to both onclick="return revealform()" and returning the javascript to false to see if it would change anything but didn't.

    Would love some assistance.

    Javascript
    Code:
    <script type="text/javascript">
    function revealform()
    {
    document.getElementById('newForm').style.display='block'; 
    }
    html
    Code:
    <input type="submit" value="add" id="add" onclick="revealform()">
    <input type="text" value="Enter New Date" id="newForm">
    php
    Code:
    If(isset($_POST['date'],$_POST['startdate'],$_POST['endate']))
    {
    echo 'Inspection ,', $_POST['date'], $_POST['startdate'], $_POST['endate'];
    }
    </script>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    I take it that you are not using ajax so why do you not have the php file echo out the new form?

    I think your php is over-riding the form. Don't have enough info to do anything but guess. Try echoing the form first.
    Evolution - The non-random survival of random variants.

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    I take it that you are not using ajax so why do you not have the php file echo out the new form?

    I think your php is over-riding the form. Don't have enough info to do anything but guess. Try echoing the form first.
    Echoing the form works just fine. Its the new form appearing that comes then disappears straight away.

    The issue like you said is perhaps the PHP is overriding the new form appearing. Is there anyway around this?

    html
    Code:
    <lu>Inspection Times<span>*</span></lu>
    <input type="text" id="date" name="date" value="01/01/2012" onfocus="if(this.value == '01/01/2012'){this.value = '';}" onblur="if(this.value == ''){this.value='01/01/2012';}"/>
    
    <select name="starthour" class="starthour" selected="hour"><option value="hour">Hour</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option></select>
    
    <!-- Start Minite inspection time -->
    <select name="startmin" class="startmin" selected="min"><option value="min">Minutes</option><option value="00">00</option><option value="05">05</option><option value="10">10</option><option value="15">15</option><option value="20">20</option><option value="25">25</option><option value="30">30</option><option value="35">35</option><option value="40">45</option><option value="45">45</option><option value="50">50</option><option value="55">55</option></select>
    
    <!-- Start AM PM time -->
    <select name="startampm" class="startam"><option value="AM">AM</option><option value="PM">PM</option></select>
    <div class="start">Start Time</div>
    
    <select name="endhour" class="endhour" selected="hour"><option value="hour">Hour</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7"></option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option></select>
    
    <!-- Start Minite inspection time -->
    <select name="endmin" class="endmin" selected="min"><option value="min">Minutes</option><option value="00">00</option><option value="05">05</option><option value="10">10</option><option value="15">15</option><option value="20">20</option><option value="25">25</option><option value="30">30</option>
    <option value="35">35</option><option value="40">45</option><option value="45">45</option><option value="50">50</option><option value="55">55</option></select>
    
    <!-- Start AM PM time -->
    <select name="endampm" class="endampm"><option value="AM">AM</option><option value="PM">PM</option></select>
    <div class="end">End Time</div>
    <input type="submit" Value="Add" class="add" name="add" onclick="revealinspectiontwo()" /></form>

  • #4
    New Coder
    Join Date
    Oct 2011
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This may not be a javascript issue afterall. I've set the second form to <style="display: none;"> so they are not displaying. it appears that when submitted, the $_POST (form method="post") is refreshing the page hence why the form is then displaying none. Is there anyway to not refresh the page?

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    This is what I had in mind:
    The first html form:
    Code:
    <p>Inspection Times<span>*</span></p>
    <input type="text" id="date" name="date" value="01/01/2012" onfocus="if(this.value == '01/01/2012'){this.value = '';}" onblur="if(this.value == ''){this.value='01/01/2012';}"/><br>
    
    <form action="test.php" method="POST" >
    <!-- Start Minite inspection time -->
    <div class="start">Start Time</div>
    <select name="starthour" class="starthour" selected="hour"><option value="hour">Hour</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option></select>
    	<select name="startmin" class="startmin" selected="min">
    		<option value="min">Minutes</option>
    		<option value="00">00</option>
    		<option value="05">05</option>
    		<option value="10">10</option>
    		<option value="15">15</option>
    		<option value="20">20</option>
    		<option value="25">25</option>
    		<option value="30">30</option>
    		<option value="35">35</option>
    		<option value="40">45</option>
    		<option value="45">45</option>
    		<option value="50">50</option>
    		<option value="55">55</option>
    	</select>
    	<!-- Start AM PM time -->
    	<select name="startampm" class="startam">
    		<option value="AM">AM</option>
    		<option value="PM">PM</option>
    	</select>
    	
    	<div class="end">End Time</div>
    	<select name="endhour" class="endhour" selected="hour">
    		<option value="hour">Hour</option>
    		<option value="1">1</option>
    		<option value="2">2</option>
    		<option value="3">3</option>
    		<option value="4">4</option>
    		<option value="5">5</option>
    		<option value="6">6</option>
    		<option value="7">7</option>
    		<option value="8">8</option>
    		<option value="9">9</option>
    		<option value="10">10</option>
    		<option value="11">11</option>
    		<option value="12">12</option>
    	</select>
    	<!-- Start Minite inspection time -->
    	<select name="endmin" class="endmin" selected="min">
    		<option value="min">Minutes</option>
    		<option value="00">00</option>
    		<option value="05">05</option>
    		<option value="10">10</option>
    		<option value="15">15</option>
    		<option value="20">20</option>
    		<option value="25">25</option>
    		<option value="30">30</option>
    		<option value="35">35</option>
    		<option value="40">45</option>
    		<option value="45">45</option>
    		<option value="50">50</option>
    		<option value="55">55</option>
    	</select>
    	<!-- Start AM PM time -->
    	<select name="endampm" class="endampm">
    		<option value="AM">AM</option>
    		<option value="PM">PM</option>
    	</select>
    	
    	<input type="submit" Value="Add" class="add" name="add" onclick="revealinspectiontwo()" /></form>
    </form>
    The form calls the php file. I name mine test.php and here is it's code:
    PHP Code:
    <?php
    If(isset($_POST['starthour'])) echo 'Start time is ' $_POST['starthour']."<br>";
    If(isset(
    $_POST['endhour'])) echo 'End time is ' $_POST['endhour'];

    echo <<<
    'EOT'
    <p>This is the second form because the <lu>tags are missing<br>
    Inspection Times<span>*</span></p>
    <
    input type="text" id="date" name="date" value="01/01/2012" onfocus="if(this.value == '01/01/2012'){this.value = '';}" onblur="if(this.value == ''){this.value='01/01/2012';}"/>

    <
    select name="starthour" class="starthour" selected="hour"><option value="hour">Hour</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option></select>

    <!-- 
    Start Minite inspection time -->
    <
    form>  // NOT CORRECT
        
    <select name="startmin" class="startmin" selected="min">
            <
    option value="min">Minutes</option>
            <
    option value="00">00</option>
            <
    option value="05">05</option>
            <
    option value="10">10</option>
            <
    option value="15">15</option>
            <
    option value="20">20</option>
            <
    option value="25">25</option>
            <
    option value="30">30</option>
            <
    option value="35">35</option>
            <
    option value="40">45</option>
            <
    option value="45">45</option>
            <
    option value="50">50</option>
            <
    option value="55">55</option>
        </
    select>
        <!-- 
    Start AM PM time -->
        <
    select name="startampm" class="startam">
            <
    option value="AM">AM</option>
            <
    option value="PM">PM</option>
        </
    select>
        <
    div class="start">Start Time</div>
        <
    select name="endhour" class="endhour" selected="hour">
            <
    option value="hour">Hour</option>
            <
    option value="1">1</option>
            <
    option value="2">2</option>
            <
    option value="3">3</option>
            <
    option value="4">4</option>
            <
    option value="5">5</option>
            <
    option value="6">6</option>
            <
    option value="7"></option>
            <
    option value="8">8</option>
            <
    option value="9">9</option>
            <
    option value="10">10</option>
            <
    option value="11">11</option>
            <
    option value="12">12</option>
        </
    select>
        <!-- 
    Start Minite inspection time -->
        <
    select name="endmin" class="endmin" selected="min">
            <
    option value="min">Minutes</option>
            <
    option value="00">00</option>
            <
    option value="05">05</option>
            <
    option value="10">10</option>
            <
    option value="15">15</option>
            <
    option value="20">20</option>
            <
    option value="25">25</option>
            <
    option value="30">30</option>
            <
    option value="35">35</option>
            <
    option value="40">45</option>
            <
    option value="45">45</option>
            <
    option value="50">50</option>
            <
    option value="55">55</option>
        </
    select>
        <!-- 
    Start AM PM time -->
        <
    select name="endampm" class="endampm">
            <
    option value="AM">AM</option>
            <
    option value="PM">PM</option>
        </
    select>
        <
    div class="end">End Time</div>
        <
    input type="submit" Value="Submit the 2nd Form now" class="submit" name="submit" />
    </
    form>
    EOT;
    ?>
    Notice the use of the nowdoc section http://www.php.net/manual/en/languag....syntax.nowdoc You of course should change this to your display of first form information and the nowdoc section to the second form you want displayed. The nowdoc allows you to copy and paste.
    Evolution - The non-random survival of random variants.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •