The task, a rather simple one. In one .HTML page is the HTML script whose task is to 'collect imput' and pass 'this data' (given to variable names) onto another .php page, then display the variables.
This simple .HTML page is -
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form action="processorder.php" method="post">
<table border="0">
<tr bcolor="#cccccc">
<td with="150">Item</td>
<td with="5">Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align="center"><input type="text" name="tireqty" size="3" maxlength="3" />
</td>
</tr>
<tr>
<td>Oil</td>
<td align="center"><input type="text" name="oilqty" size="3" maxlength="3" />
</tr>
<tr>
<td>Spark Plugs</td>
<td align="center"><input type="text" name="sparkqty" size="3" maxlength="3" />
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Order" />
</td>
</tr>
</table>
</form>
</body>
The input is collected and the call
<form action="processorder.php" method="post">
fails to 'load the .php file into the browser but will OPEN this file onto the clipboard.
The simple processorder.php file is
<?php
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ";
echo date('H:i, jS F Y');
echo "</p>";
echo '<p>Your order is as follows:</p>';
echo $tireqty.'tires<br />';
echo $oilqty.';bottles of oil<br />';
echo $sparkqty.';spark plugs<br />';
?>
</body>
</html>
Nothing too complicated, just a simple exercise in passing variables around. So, the question remains as to why the call does not load the .php file but instead opens the .php file and the variables collected in one page are not passed onto another page.
Each page loaded onto the browser does load seperately but of course, the variables are not then collected in one page and passed onto the other page which is the principale objective.
If the line on the orderform.html page which is
<form action="processorder.php" method="post">
is then edited to be
<form action="processorder.html" method="post">
then the page is loaced onto the browser and not opened to the clipboard. The other change to this .html file is the tag
All this is happening inside the Rapid PHP 2007 editor.
PHP is 'present' in the files and configured with the Rapid 2007 editor.
One question is about the IE browser and how the browser detects/decides not to load the file, execute the PHP parts or what the problem is by not loading the file but opening the file to the clipboard.
Your PHP files are probably delivered as text/plain by your server (or you don't use any server, or your server doesn't support PHP)
It sounds like you haven't got PHP correctly installed. First create a simple php page with just:
<?php
phpinfo();
?>
If this doesn't does the same, and you just see the source code then you need to check your PHP stack setup.
A good place to get started is by downloading a complete stack such as EasyPHP:
http://www.easyphp.org/
Then following the install instructions.
http://www.easyphp.org/introduction.php
PHP has nothing to do with Internet Explorer and vice-versa, but considering that you've tagged your question with internet-explorer, I guess you're not having that issue with Firefox, Chrome, Opera, etc. ... and that would mean it's nothing related to PHP.
In that case - you actually have a whole bunch of problems:
Your HTML code is not valid according to W3C standards.
You have extra output before the actual HTML code starts.
IE has a long history of web standards incompatibility and on top of that, it's pretty bad at guessing content types too. So even if you were conforming to the standards - you could still have the same problem, although I doubt you're using IE 6, so that's probably not the case. But I guess it's best explained in here.
So ... what you could do to fix it:
Remove the white-spaces(new lines count too!) preceeding the <html> tag.
Send a content-type header with PHP(it's still not related to it - you'd have the same problem if you were using e.g. Perl or Ruby).
Removing the xmlns attribute could probably work ... but only in IE 6, and you'd still have to remove the white-spaces.
Include a DOCTYPE declaration - this would make sure that the browser knows what type of document it's trying to render, instead of leaving it to guess in "dumb mode".
Related
I am trying to add a php code in my html file, but whenever i do, my file instead of outputting my expected outcome, it instead presents the source code
again, i am creating a server for my project at school and i am a total noob in programming as i learn it all by myself without formal education about it. i tried to save the file as both .html and .php, although .html presents the output, but not the desired one. now i have two files below and since i am a noob in programming, my concept was to have users input the form in the .html file and output in on an identical one but in .php
this is the first file, saved in ABM11.html
<form action="AMB11.php" method="post"><table border="0">
<tr>
<td>Name</td>
<td align="center"><input type="text" name="StudentName" size="30"></td>
</tr>
<tr>
<td>Subject</td>
<td align="center"><input type="text" name="Subject" size="30"></td>
</tr>
<tr>
<td>Final Grade</td>
<td align="center"><input type="text" name="FinalGrade" size="30"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="submit"></td>
</tr>
</table>
</form>
this is the second file, saved as ABM11.php
<?php
$studentname = $_POST['StudentName'];
$subject = $_POST['Subject'];
$finalgrade = $_POST['FinalGrade'];
echo $studentname '<\br>';
echo $subject '<\br>';
echo $finalgrade '<\br>';
?>
basically i just want users to answer a form then have that data be posted on the same page perpetually, not have my noob source code presented
it seems , the problem with your web server , weather you are using apache or nginx . its not running properly or its not configured properly on your local machine so rather then executing php code its just showing that file on the browser .
You can debug like , create one simple php file just like echo "yourname "; and put it to your www directory and try to run it form browser if the server is proper configured then it must print and if its not prited then its mistake with your local server configuration .
and also on your source code there is one mistake of echo and .
Wrong : echo $finalgrade '<\br>';
True : echo $finalgrade .'<\br>';
You must concat br with .
that is mistake 110% but as you said in your question the code is showing on the page is not only because of this , its surely configuration problem
if . is the only mistake then it wont show you the source code on the page but you will get any php error if thats the only issue .so check your config well first.
Thanks
Akshay Champavat
If you combine variables and strings in an echo, you need to add dots to connect them. So instead of this
echo $studentname '<br>';
you need to write it as
echo $studentname.'<br>';
And similar in all other lines.
(and no backslashes, by the way!)
And also ("sourcecode displayed...") make sure to open/call the php file via a server (for example XAMPP, via localhost), not simply as a file on your computer.
I have a form for users to fill out information and am wondering how to retain the previously typed information if the user redirects back to the page.
So, I have two files,
form.html
validate.php
Under form.html:
<form id="regForm" action="index.php?validate" method="post" onsubmit="return regValidation();" >
<tr>
<td width="150px" >First Name: <font color="red">*</font> </td>
<td><input type="text" name="firstNameField" id="firstNameField" value/ ></td>
</tr>
and under validate.php, I have stored the info with $_SESSION:
<?php
session_start();
$_SESSION['first'] = $_POST['firstNameField'];
?>
but when I tried to populate the firstNameField with $_SESSION['first'] as follow
<td><input type="text" name="firstNameField" id="firstNameField" value="<?php echo isset($_SESSION['first']) ? $_SESSION['first'] : NULL; ?>" /></td>
The field will literally be replaced with <?php echo isset($_SESSION['first']) ? $_SESSION['first'] : NULL; ?>
Can someone tell me why and how to properly fix it?
Thanks.
Change the file name to form.php instead of form.html so Apache knows to parse PHP inside that file.
Alternatively you can modify your .htaccess file and add a line like this:
AddType application/x-httpd-php .html
This tells Apache to to render all files that end in HTML using PHP.
Why make this complicated by having two files?
Just have the one.
The first time around nowt is filled in as the $_POST has nothing in it. Subsequent times that variable will have the appropriate value.
This will save you a lot of heartache in the future as you do not need to keep two files in step.
Also it removes the complexity of using sessions.
By default, any file with the file extension of .html will not be parsed, therefore exposing <?php $yourCode->exposed = true; ?>
If you rename the same file, changing its file extension from .html to .php, then
<?php echo 'HelloWorld'; ?> will be parsed, and the end result is HelloWorld
This default behavior can be overridden as described above by Tim
Change the file name to form.php instead of form.html as is the php tag
or add .html handler
I know this question is similar to other questions, I did hours of research yet I could not figure out a solution, please help me find a solution.
I want to pass textfield value from html to php textfield but instead of value, the php code is shown as output.
Page 1:
<body>
<form action="fare1.php" method="post">
<input name="address1" id="address1" type="text" size="15" value="City" />
<input name="" type="submit" />
</form>
</body>
Page 2:
<body>
<div class="content">
<h1>Instructions</h1>
<table width="200">
<tr>
<td colspan="2">
<input type="text" name="from" id="from" value="<?php echo $_POST['address1']; ?>" /></td>
</tr>
</table>
<!-- end .content --></div>
</body>
I tried using hidden fields, using javascript function and many other things but I couldn't reach a solution to my problem :(
Thanks!
Edit...
It seems I am having trouble with PHP itself, I am trying to figure it out now. PHP is not running in my system. Please let me know if you know of any free hosting sites which provides php support, I tried 50webs, it is saving the php files instead of opening it.
Thanks!
If the php is running on your server, fare1.php should execute without showing any php code for the output. If it is, then your server doesn't support the php. I suggest you download xampp. Its a free and open web server that supports php.
I am learning from already created webpages (php,javascript, and with smarty) and I promise I've been trying hard to understand this code but my mind just can't, I don't how it works, I have read and read, but I still don't understand.
The next code works perfectly, but I don't know how. It's about a contact form.
This is the original php page:
<?php
include("includes/globals.php");
include("includes/smarty/Smarty.class.php");
$vista = new Smarty();
$vista->display('contacto.tpl');
?>
As you can see, it just displays contacto.tpl, which is (I will put just the interesting parts):
<link href="{$smarty.const.__SERVER_URL__}css/estilo.css" rel="stylesheet" type="text/css" />
<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
<link href="../css/coeco.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{$smarty.const.__SERVER_URL__}scripts/jquery.js"></script>
{literal}
<script>
function validar()
{
$('#formContacto').submit();
}
</script>
{/literal}
</head>
<body>
<form id="formContacto" action="/contacto-enviado.html" method="post">
<table class="formulario_contacto" cellspacing="0" cellpadding="0">
<tr>
<td width="228" height="17">NOMBRE</td>
<td width="110" height="17">TELÉFONO</td>
<td height="17">E-MAIL</td>
</tr>
<tr>
<td><input class="campo_texto" name="nombre" id="nombre" type="text" /></td>
<td><input class="campo_texto2" name="telefono" type="text" /></td>
<td><input class="campo_texto" name="email" id="email" type="text" /></td>
</tr>
</table>
<table class="formulario_contacto" cellspacing="0" cellpadding="0">
<tr>
<td height="17">SU MENSAJE</td>
</tr>
<tr>
<td><textarea class="texto_contacto" name="detalles" rows=5></textarea>
<div align="right"><a class="btn_formulario_contacto2" href="#" onclick="validar()">enviar</a></div></td>
</tr>
</table>
</form>
{include file="foot.tpl"} </div>
</body>
</html>
So, well, ok, fine, it gets data from a form and it submits it with the function submit(), but where is function submit() defined? I mean, yes, I've read http://api.jquery.com/submit/ and it's kind of a trigger, but it must be defined somewhere, right? where? how is it possible that this code works?
Thanks!
Sorry, I know I'm so neeeeeeewbie.
The submit() method is defined on the "form" DOM element. jQuery is just calling into that method to submit the form on the page.
The submit function that jQuery is using is inside of the jQuery code itself. You're using the 'smarty' templating engine to include jQuery in your page with this line
<script type="text/javascript" src="{$smarty.const.__SERVER_URL__}scripts/jquery.js"></script>
Once you've done that, you now have access to all of the awesomeness that jQuery provides, such as, the submit() function to submit a form. jQuery's version helps to make your submit work cross browser. If you'd like to see more on the submit function, look here.
it's you in the future, 7 years later.
Nobody answered your question properly. So I'll do my best.
A <form> is an HTML object with some special properties that differentiate it from other HTML elements, the same way a <button> or a link <a> have special properties that differentiate them from others.
In particular, <form> allows to send information to a server. The information is sent through an HTTP request, the method used is defined in the property method (either GET or POST), while as the URL where the request is sent is specified in the property action.
The way <form> works is governed and specified the same way any other HTML objects are, via a standard. The official body in charge of it is W3C, here is the spec for forms:
https://www.w3.org/TR/html52/sec-forms.html
The spec is then freely implemented by browsers, so the specifics of 'where' the behaviour is defined is inside the guts of the browser core. For instance, you might find an implementation if you look deep enough in the Chromium Project, which is the core in which Chrome is based on. However knowing the specs is more than enough to work with it.
Going back to your specific example:
This form will create and send a POST request from the client page where this form appears with the information input in the form to the relative URL /contacto-enviado.html
Further Reading
For a nice explanation of how works in general, check:
https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data
Like you said submit is a trigger for the onSubmit event. So when its called it just makes the form invokes that event on the form... by default it will do the exact same thing as clicking a submit input within the form.
I'm trying to understand this bit of code:
in display.php:
<html>
...
<body>
<table>
<tr>
<td>
User info: <iframe id="SpControlFrame1" name="SpControlFrame1" src="javascript:'';"path_src="index.php?cmd=YYY" ></iframe>
</td>
</tr>
</table>
</body>
</html>
in another file, I have a switch statement:
main.php
switch ("cmd") {
case ZZZ:
include("foo.php");
break;
case YYY:
include("blah.php")
break;
}
blah.php:
<?php
//some functions for processing
?>
<html>
<head>
...
</head>
<body>
<input type="text" size="12" name="username">
<input type="button" value="submit">
</body>
</html>
1) So, can some explain what is happening here? The iframe is embedded in the page and doesn't cause a reload or anything like that.
2) I'm trying to duplicate this functionality on another page but the iframe is always empty (I've verified this using the IE developer Toolbar)
Without seeing the code in question, I couldn't really say what's happening. Your example presumes that the code in question is server-side, and when a particular variable/condition is met, then the iframe is created or populated by blah.php.
You would have to ensure that the same code is called when creating this other iframe. Perhaps you could expand on the code in question? Source for the original, and source for the new (not the iframe, but the containing document).
How does this work for you?
User info: <iframe id="SpControlFrame1" name="SpControlFrame1" src="index.php?cmd=YYY" ></iframe>