Skip navigation
Currently Being Moderated

Tabbed Pannel keeps collapsing

Aug 11, 2011 3:15 PM

Hi, on  my page I have a tabbed pannel.  One tab has 8 child tabs in it and the others have forms or info.

 

Screen shot 2011-08-11 at 3.56.02 PM.png

All the tabs work great all info show up no problems.  Two of the tabs,registration and contact us, have forms on them and the message board you can post comments on them.  The forms all work fine I get emails with the form info and the message board works fine the new comments show up.  Here is where my problem lies. 

 

Now when I hit submit on the 2 forms and post on the message board my page refreshes and I get taken back to my home page when my site first launches.(just screen shots of top of pages)

 

Screen shot 2011-08-11 at 3.44.36 PM.png

So when I hit post I get redirected to my home page(below).

 

Screen shot 2011-08-11 at 3.45.21 PM.png

When I go back in to the message boardtab  my new comment is there.   How do I get my page to refresh while staying in the message board tab.

 

As for posting code I am not sure of what to post.  When I hit post it triggers my form action is as follows:

------------------------

<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">

 

Here is the $editFormAction code:

 

$currentPage = $_SERVER["PHP_SELF"];


$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO comments (comment_by, email, `comment`) VALUES (%s, %s, %s)",

                       GetSQLValueString($_POST['name'], "text"),

                       GetSQLValueString($_POST['email'], "text"),

                       GetSQLValueString($_POST['Comment'], "text"));


  mysql_select_db($database_conComments, $conComments);

  $Result1 = mysql_query($insertSQL, $conComments) or die(mysql_error());


  $insertGoTo = "IndexMain.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}


$pageNum_rsComments = 0;

if (isset($_GET['pageNum_rsComments'])) {

  $pageNum_rsComments = $_GET['pageNum_rsComments'];

}

$startRow_rsComments = $pageNum_rsComments * $maxRows_rsComments;

 

-------------------------

Now when I created the insert record it asked me what page to goto after.  How do I get it to refresh but stay on the same tab?

 

Thanks winrol

 
Replies
  • Currently Being Moderated
    Aug 11, 2011 4:23 PM   in reply to winrol

    You can submit the form using Spry utils via ajax, so you never leave the page.  You add call back function that runs when the server page responds. In the call back function you reload the messageboard by using Spry Data Seturl function.

     

    if (Spry.Widget.Form.validate(Spry.$$('#replyform')[0]) == true)
        {
        Spry.Utils.submitForm('replyform', updateReplyDiv, {method:'post',url:'newReply.asp'})

     

    updateReplyDiv is the function to run when the server page newreply.asp responds.

     

    function updateReplyDiv(req)
    {
        var x = req.xhRequest.responseText;
       
        if (x == 'Success')
        {
            Spry.$$('#replyResponse','TabbedPanels1')[0].innerHTML = 'Your reply has been posted. Thank you for your Contribution<p> </p>';
           
           
         latesttopics.setURL('serverside/latestJSON.asp?cache=' + (new Date()).valueOf());
         latesttopics.loadData() ;
             }

    ....

    the cache new date query string ensures that it doesn't return the cached Spry dataset.(I.e. the data before the message post). loadData cause the Spry data to be reloaded which causes any spry regions using that data to also be refreshed

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 13, 2011 3:25 AM   in reply to winrol

    Hi,

     

    See http://www.thehmc.co.uk/forum2 , Click on a topic then click on a reply button to see my page in action. You'll be able to fill out the form and click submit without registering. The server code will reject your submission but you'll be able see it in action.

     

    Is the first part validating the form fields and the next line submiting the form and getting a reply?

     

    Yes - I have Spry validation fields see complete form html below

     

     

     

    PHP When the function is called if the response from the submit is success, what would the response be?

     

    Yes just replace my asp server page url with your serverside php page url.  All the php server page does is update the database and then respond with some simple text like success or fail.


    In my asp page the code for the response, if the database update was ok is


    Response.Write("Success")

     

    So that is what the server responds with Success and nothing else. So imagine your php server page writes one word instead of a HTML web page.

     

    Now after the if(x=="Success") line do I change the '0' in "

    TabbedPanels1')[0].innerHTML " to "tabbedPanels1')[4].innerHTML?

     

    The arrays are zero indexed so [0] represents the first tab, and [4] would represent the 5th tab. I think you want [3] as it's the 4th tab you are updating

     

     

    The cache stuff at the end is that for browsing history?

     

    Yes the browser can cache the Spry Data as can Spry itself.  This way you force the data to refresh and pick up the latest from your database, assuming the Spry dataset is dynamically generated via one of your php pages.

     

    Would I then change my form action to call the function updateReplyDiv(req)?  Where would this code go?

     

    No the form looks like this, it has not default method or action, as that is handled in the Spry form submit code


    <form id="replyform" name="replyform">
                  <input id="rforumID" name="rforumID" type="hidden" value="0" />
                  <input id="rtopicID" name="rtopicID" type="hidden" value="0" />
                  <span id="sprytextareareply">
                  <textarea name="ReplyQuote"  rows="10" id="ReplyQuote" ></textarea>
                  <span class="textareaRequiredMsg">You have not entered a reply.</span></span>
                </form>
                <div id="preview" class="mynone"></div>
                <div id="replyResponse" class="formresponse"></div>
                <br />
                <ul class="forumMenu" >
                  <li id="postreply" title="Click here to post your reply"><strong>Post your reply</strong></li>
                  <li id="cancelreply" title="Click here to cancel your reply"><strong>Cancel your reply</strong></li>
                </ul>

     

    The Javascript is in an external file at the end of the page with the form on it.


    </div>
    <script src="js/default.end.js" type="text/javascript"></script>
    </div>

    <!-- InstanceEndEditable -->
      <div id="footer">   
       <p> &copy; 2008 Created / Maintained by Phil Whitehurst</p>
       
      </div>
    </div>
    <script type="text/javascript">
    <!--

    Spry.Utils.addEventListener("#footer","load",footer(),false);

    function footer()
    {
    // Update copyright notice in footer
    var d = new Date();
    var dYear = d.getFullYear();
    var content = "<p>&copy; 2008 - " + dYear + " Created and maintained by Phil Whitehurst</p>"
    Spry.$$("#footer")[0].innerHTML = content;
    }

    //-->
    </script>
    </body>

     

    I attach a event listener to a list item made to look like a button rather than use the default submit button.

     

    Spry.$$('#postreply').addEventListener('click',postreply,false);

     

    function postreply()
    {
      
        if (Spry.Widget.Form.validate(Spry.$$('#replyform')[0]) == true)
        {
        Spry.Utils.submitForm('replyform', updateReplyDiv, {method:'post',url:'newReply.asp'});
       
        }
    }

     

    function updateReplyDiv(req)
    {

    ....

     

    Here's a diagram to try and explain what each of your pages is doing

     

    Ajax.jpg

     

    Hope that explains it

     

    Phil

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points