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>
Related
I simplified my real php page just to get an idea, I have this simple php page with a div, I want to keep this div open and its input with the text that has been changed by the user, when I change the page and go to page2.php
<html>
<head> stuff.. </head>
<body>
stuff in the body..
<div>I want this div to stay in the other page, (without cloning it)
<input type="text" value="hello" />
</div>
</body>
</html>
I'm learning Php, reading it from a book following examples.
But something isnt working as described in the book, i dont understand why not
I have installed XAMP, and am running PHP version 5.5.9.
register_globals has not been set as was described in the book (as i understood this is default in v 5.5.9)
There are two .php pages
The first page is called form.php, the book didnt explain where to put.
It didnt work in the root, and so i made phpforms folder and placed it there
<html><head><title>First HTML Form</title></head>
<body>
<table cellpadding ="15"><td bgcolor="lightblue" >
<form action="/phpforms/form.php" method="POST" >
<p> Please enter your name: <br /> <input type="text" size=80 name="your_name">
<p> Please enter your phone: <br /> <input type="text" size=80 name="your_phone">
<p>
<input type=submit value="submit"><input type=reset value="clear">
</form>
</table></body></html>
The seccond page is made to read the entered vaues.
<HTML><Head><Tile>Show me the data</Title></Head><body>
<?php extract($_REQUEST, EXTR_SKIP); // Extracting the form input
print "Welcome to PHP $your_name<br />";
print "Can I call you at $your_phone<br />";
?>
</body></HTML>
When I enter data in the first page, it gives no error.
However when i then try to readout the entered data in the seccond page it doesnt work
I get two lines showing
Notice: Undefined variable: your_name in C:\xampp\htdocs\Peter.php on line 3 *
Notice: Undefined variable: your_name in C:\xampp\htdocs\Peter.php on line 4 *
Its an introduction to php forms, but well its pretty essential for going on with this book. I'm new to this could someone help me out here ?.
Simply add quotes around the type="" attribute and insert a > at the end of the form.
It is important to understand how the POST method works. The action attribute on your first form should contain the url of the destination page. Then use
$name = $_POST["your_name"];
echo $name;
to display the information in the second page. the $_POST form returns an associative array so all of the keys correspond to the name="" attribute in the form and all of the values equal the value of the form. Be sure to use: if (isset($_POST["your_name"]){} to handle any exceptions as well.
Enclose your <form> tag's type attribute with quotations.
<input type=submit value="submit"><input type=reset value="clear">
should be
<input type="submit" value="submit"><input type=reset value="clear">
Other than that, your code appears to be working fine.
Whatever book you are following, I would recommend you to first check some HTML basics.
In any case, I've re-written the whole code here, actually trying to be as close close as possible to your.
What I've done is:
Define a DOCTYPE foreach file (this is important, not that we
have HTML5.
Syntax errors have been corrected, almost everywhere (in both scripts).
Tried to put some effor to make this code a little bit more responsive. Most of the tags you have used are deprecated, such as cellpadding, bgcolor.
What the tutorial was about is using the extract php function to extract the values passed to the form into some temporary variables in order to don't have to store each variable using $_POST, which is clever but you don't see that often.
First of all, check the extract() function: http://php.net/manual/en/function.extract.php
What I've done, I've rewritten your main code:
It should have any name, in your case, it SHOULD BE peter.php, in the main directory:
<!doctype HTML>
<html>
<head>
<meta charset="utf-8">
<title>First HTML Form</title>
</head>
<body>
<table>
<tr>
<td style="background: lightblue; padding: 1%;" >
<form action="/phpforms/form.php" method="POST" >
<p> Please enter your name:</p> <br /> <input type="text" size=80 name="your_name">
<p> Please enter your phone:</p> <br /> <input type="text" size=80 name="your_phone">
<input type="submit" value="submit"><input type="reset" value="clear">
</form>
</td>
</tr>
</table>
</body>
</html>
Most important:
THE CHARSET: Nowaday, please define a charset.
Your table structure was completely wrong. It still doesn't have a sense either, but at least it has a correct syntax.
I've corrected all the syntax error you had: First, you didn't close your <form, second, you didn't close any <p> tag with its </p> and third, you didn't enclose properly your submit and your reset button, but some browers still would interprete it correctly.
Now, in order to make it work, you should have, in your C:\xampp\htdocs\ folder, a folder named phpforms CONTAINING A FILE CALLED form.php. If you don't have such, your form will never work, because it is aiming to the form.php script which is located in the /phpforms folder. Don't forget that you have defined that in your action parameter in the form ahead, by writing: action="/phpforms/form.php".
At this point, the form.php page should be structured like such:
<!doctype HTML>
<html>
<head>
<meta charset="utf-8">
<title>Show me the data</title>
</head>
<body>
<?php
extract($_REQUEST, EXTR_SKIP); // Extracting the form input
print "Welcome to PHP $your_name<br />";
print "Can I call you at $your_phone<br />";
?>
</body>
</html>
How does it work?
Using extract() on $_REQUEST will get the $_REQUEST array and explode it in a serie of variables according to the name of the compiled form.
Since you have named the two inputs in the previous form as name="your_name" and name="your_phone", the extract() function will parse the value of the input named "your_name" in the variable $your_name and the value of the input named "your_phone" into the variable $your_phone.
Once you extracted the values, so, you can easily print them using:
print "Welcome to PHP $your_name<br />";
print "Can I call you at $your_phone<br />";
The output, would be this:
main page (maybe peter.php?) :
Once submitted:
I am testing Html form using post method and got this odd result:
I have two html pages on server apache (already installed php): post.html and target.html, and the code for these page are followings:
post.html (don't worry about the html standard)
<div style="text-align: center">
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
and target.html
<html>
<head>
</head>
<body>
<h1>Target page</h1>
</body>
</html>
When I entered data to the form on post.html page and hit submit button, I got to the target.html page. When on this page(target.html), I refreshed the page, and what I receive is a blank page. The second time I refreshed, It turned to normal Html page.
I don't know why it returned a blank page the first time I refreshed, I have tried the same approach but with PHP page, and the content of target page (assum name target.php) still remains (not blank like html files above)
So, could you explain me about this problem?
Thank you.
This definitely has something to do with your browser. Same here on a mac using Safari, on some pages after submitting the content, the page seems to freeze, I refresh it, and then it works again.
Definitely not a code problem, as far as I'm concerned.
It's because you cannot pass an input from html to html file. Your target.html should be a php file (target.php).
and try to put this code on your target.php
<?php
var_dump($_POST); //this will show the inputted text and also show the data type and will stop the code execution here. other codes below will not be executed.
echo $_POST['testname'];
?>
Additionally, change target.html to target.php in your form action
First I will start out by correcting your post.html
<div style="text-align: center;"> <!-- added a ; after center -->
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
that may not matter but you should end all your styles with ;
To continue, everything looks fine. maybe something weird happened between refreshes.
save your form page in php than add the php script in the same page, here try this. remember save in .php.
<?php $testname = $_Post['testname'];
echo $testname ?>
<div style="text-align: center">
<form method="POST" action="">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
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".
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.