4 Replies - 1113 Views - Last Post: 14 February 2013 - 09:22 PM Rate Topic: -----

#1 duffgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-October 12

PHP form that at submit opens on same page

Posted 14 February 2013 - 10:06 AM

Hi all,

Thank you for taking the time to look at my issue. I am a student and am having a a problem. I have a form that a user fills out, on submit, the form should display on the same page. I have several tabs on the site that when you click on them they pop up in the correct div on the main page, it is just this form at submit that opens in a new window. This is my below code. Any help would be appreciated.

<div id="primaryContent"> <!-- this is the code on my main index page where everything needs to display in primary content-->		<!-- primaryContent - START -->
			
			<?php		    if (isset($_GET['menukey'])) {
			$menukey = $_GET['menukey'];
		    } else {
			$menukey = 0;
		    }
		    switch ($menukey) {
			case 1:
        			include 'primarycontent.php';
			        break;
			case 2:
		         	include 'aboutme.php';
	        		break;
			case 3:
			        include 'products.php';
			        break;
	    		case 4:
		        	include 'AdvisorsEdit.php';
	        		break;
	        	case 5:
	        		include 'AdvisorsEditPost.php';
	        		break;
						default:	// case else
        			include 'primarycontent.php';
		        	break; 
		    }
 


<!--this is the code form action which does display in the correct location on the main page  it is found in the AdvisorsEdit where the form is filled out-->  
<form action="AdvisorsEditPost.php" method="post" name="AdvisorsEdit">




<!--THe following code is for AdvisorsEditPost which is supposed to display on the main index page in primary content like AdvisorsEdit-->
<!--  I am wondering if I should have something different in("Location: closewindow.htm");
        -->
<?php

	switch($_POST['action']) { 
	case "Cancel": 
	    header("Location: closewindow.htm");
	    break; 
	case "Save": 
	    $AdvisorID = $_REQUEST['AdvisorID'];
	    break;
	 
	}

<!--  This is the form action code on advisorseditpost-->

<form action="primarycontent.php" method="post" name="AdvisorsEditPost">




Is This A Good Question/Topic? 0
  • +

Replies To: PHP form that at submit opens on same page

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: PHP form that at submit opens on same page

Posted 14 February 2013 - 10:49 AM

Hey.

The "action" attribute on the form tells it where to submit the data; which page it should open after it is submitted. If you tell it to go the "AdvisorsEditPost.php" page, it'll do that, and that will bypass the main page completely. If you want it to open the main page with the edit post page as it's content, you need to point it to the main page, with the correct menu key set.

If the main page is just an index page, try something like:
<form action="index.php?menukey=5" method="post">


Was This Post Helpful? 0
  • +
  • -

#3 duffgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-October 12

Re: PHP form that at submit opens on same page

Posted 14 February 2013 - 12:55 PM

Thank you for your help, Still no luck, this is my post code and the form action code. The way I understand it, this should open in the index.php but it is not, it opens in a seperate window

<?php

	switch($_POST['action']) { 
	case "Cancel": 
	    header("Location: closewindow.htm");
	    break; 
	case "Save": 
	    $AdvisorID = $_REQUEST['AdvisorID'];
	    break;
	 
	}

<form action="index.php?menukey=5" method="post" name="AdvisorsEditPost">







This post has been edited by JackOfAllTrades: 14 February 2013 - 02:19 PM
Reason for edit:: Fixed code tags

Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: PHP form that at submit opens on same page

Posted 14 February 2013 - 05:28 PM

That's the second form, in the "AdvisorsEditPost.php" page, right? What about the first form?

ANY action that should show up as a part of the index page needs to be sent to the index page. You can't just say "AdvisorsEditPost.php" in the form action and expect it to appear inside the index page.
Was This Post Helpful? 0
  • +
  • -

#5 duffgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-October 12

Re: PHP form that at submit opens on same page

Posted 14 February 2013 - 09:22 PM

Yes thank you I did finally figure it out. Now I am dealing with the few unhandled exceptions, Such is the life of a student programmer :clap:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1