I am having a hell of a time with a form, which is built dynamically from PHP. The form is constructed first by calling a page called gala-tix.php, This page holds a bunch of javascript functions, the form code and it also calls an include called dwt.php. dwt.php has a few php functions in it and it also called a template file, which is the html stuff and forms the page structure. I want to call $_SERVER from the form action so I can process some of the $_POST variables, store some stuff in a database and then redirect to another page.

I am having a crazy time with trying to get the $_SERVER working in the following code:

$content = '<div id="mainContent">'
		.'<h1>purchase tickets to the BEAC national students awards gala!</h1>'
      	.'<div id="navcrumb"><a href="/index.php">home</a> :: awards :: purchase gala tickets</div>'
		.'<div id="tix_container"><form name="tickets" id="tickets" method="post" class="tix" action="<?php echo $_SERVER["PHP_SELF"]?>">'
	  .'<fieldset><legend>Shipping Info</legend>'

It goes on to build up the entire form, which is stored in $content.

It then draws this content in a specific place on the html template I mentioned earlier.

What is happening is that when I go to the original page (gala-tix.php, the page loads but I get a bit of php code which shows up on the page which does not seem to be being drawn by PHP. (See attached image). When I submit the form, I get an error saying that the page is not found and shows a url of /conference/< which looks like the first bit of the <?php echo $_SERVER["PHP_SELF"]?>

So I am thinking that there is something wrong with the way I am adding the $_SERVER["PHP_SELF"], or, because the page gala-tix.php is already a php page, the error is caused by inserting the entire php block in the action of the form. i.e. <?php echo $_SERVER["PHP_SELF"]?>, rather than something like just echo $_SERVER;, which also does not work.

What am I missing here?

Dave

Change

action="<?php echo $_SERVER["PHP_SELF"]?>">'

to

action="'.$_SERVER["PHP_SELF"].'">

. That way you get rid of the "> on the screen and the action url should be fine now as well.

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.