Forum Moderators: coopster
<?php
$page_title = "Test";
$content = "This is where i enter my test that gets inserted to the default template";
include("default_template.php");
?>
I then call the $content in the default_template.php page.
It works good. But, the problem I am having is this.. I would like to add a login page and therefore need to add the following form..
<form method="post" action="">
Name : <input name="username" type="text"><br>
Password : <input name="password" type="password"><br>
<input name="send" type="submit" value="Send!">
</form>
I would like to store this form in the $content variable so that I can call it as usual on the default template page. IS there a way of doing this? Or will I have to stop using the default template page? please help!
$content .= "<form method=\"post\" action=\"\">";
$content .= etc.....
(notice that quotes are escaped)
or, use heredoc syntax
$content =<<<EOF
<form method="post" action="">
Name : <input name="username" type="text"><br>
Password : <input name="password" type="password"><br>
<input name="send" type="submit" value="Send!">
</form>
EOF;
WBF
If I created a form in html I would use javascript to check that the user has entered a value
e.g.
<script language="Javascript"
type="text/javascript">
function ValidateForm() //create function called validate form
{
if (document.login.realname.value == "") //if password name = blank
{
alert("Please Enter a Name!"); //show error
document.login.realname.select(); //move cursor to field
return false; //go no further
}
else if (document.login.spearname.value == "") //if password name = blank
{
alert("Please Enter Your Spearhead Name!"); //show error
document.login.spearname.select(); //move cursor to field
return false; //go no further
}
And so on.
When using PHP is Javascript used? or do you use the action="<?php=$_SERVER['PHP_SELF'];?>"> command to print on the same page the error? if so, how is this done?
thanks again!
So, I have this in my head:
function ConfirmChoice()
{
answer = confirm("This will delete all data relating to this item from the data base! This is irreversible. Are you sure you want to continue?")
if (answer!=0)
{
location = "<? echo $action;?>"
}
}
And this in my content var (which of course is in the body)
$content .= "<td><form action=\"$action\" method=\"post\" onSubmit=\" ConfirmChoice(); return false;\">";
WBF
You can mix php with javascript, however remember, that php is on the server side, while javascript is working on the client's side (even offline). So you can write javascript functions in php, but cannot call php functions in java.
That means that you can write:
<?PHP
print("<script>
<!--
document.write(/"Hello World/");
//-->
</script>");
?>
But you cannot write so:
<input type="text" id="1" name="1" onblur="document.getElementById(2).value = <?echo md5("this.value");?>">
<input type="hidden" id="2" name="2">
This won't work! because php is done before sending the page to user, so in the code you will get the following:
<input type="text" id="1" name="1"
onclur="document.getElementById(2).value = 6751kjhgdf9asf320987kl20950">
<input type="hidden" id="2" name="2">
where 6751kjhgdf9asf320987kl20950 is md5 hash of text "this.value", not of the value you write into the text field.
There's a way for that to work correctly:
When you submit the page, then the following page should have the code below:
<?PHP
$input2 = md5($_POST["1"]);
?>
Then you have md5 hash of what was written in <input name="1">
Have fun with php!
Michal Cibor