I am trying to generate an HTML page using data gathered in a form on another page. I have this tag on the html page with the form:
<html>
<body>
<meta http-equiv="cache-control" content="private" >
<link rel="stylesheet" type="type/css" href="vytran_css.css" />
<head> New Product Introduction </head>
<p> In order to begin the process of introducing a new product, please complete
the following form. Once you are satisfied with your responses to the various
prompts, please click on the submit button at the bottom of the page. If you
would like to start over, click the Reset button. If you have any questions,
Please follow the link that says "Help".
<form action="html_data.php" id=from1 method="post">
Product Name:
<input name="Name" size="20" type="text">
<br><br>
Project Lead Name:
<input name="PLname" size="20" type="text"> <br><br>
Team-members: <br>
<textarea name="Team-members" rows=10 cols=40 type="text"> </textarea> <br><br>
Product Type: <br>
<input name="Product Type" size="20" type="text"> <br><br>
Description: <br>
<textarea name="Description" rows=10 cols=40 type="text"> </textarea>
<br>
<br> <br>
<input value="Submit" type="submit" name="formSubmit">
<input value="Reset" type="reset">
<input value="Help" type="button" onclick="window.location.href='problems.html'">
</form>
</p>
</body>
</html>
and on the html_data.php page I have the following:
<?php
ob_start(); // start trapping output
$name = #$_POST['Name'];
?>
<html>
<body>
<p>
Product Name: <?php echo $Name; ?><br>
Project Lead: <?php echo $PLname; ?><br>
Team Members: <?php echo $Team-members; ?><br>
Description: <?php echo $Description; ?>
</p>
</body>
</html>
<?php
$output = ob_get_contents();
$newfile="output.txt";
$file = fopen ($newfile, "w");
fwrite($file, $output);
fclose ($file);
ob_end_clean();
?>
This should do what I am asking it to do. The form submits with no problem, but I cannot find the page once it submits. Any idea what I need to change?
In your form
Change from
<textarea name="Team-members" rows=10 cols=40 type="text">
to
<textarea name="Team_members" rows=10 cols=40 type="text">
In your html_data.php
Change from
<?php echo $Team-members; ?>
to
<?php echo $Team_members; ?>
There is obviously an issue with the dash between Team and members.
PHP is treating the hyphen as a mathematical operation, being a minus.
I.e.: Team minus members
Then, if you wish to echo the data to screen after submission, add
echo $output;
underneath ob_end_clean();
This worked for me.
Related
I am using php and CodeIgniter. I am a novice at both of these (career VB.Net and C# developer). However, trying to create a basic registration form, I'm having a hard time getting jQuery validation to work.
header.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?><!DOCTYPE html>
<html>
<head>
<?php if(isset($title)) {?>
<title>Discuss Cards - <?php echo $title ?></title>
<?php } else { ?>
<title>Discuss Cards</title>
<?php } ?>
<link rel="stylesheet" href="<?php echo base_url();?>styles/forum.css" type="text/css"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<script src="<?php echo base_url();?>js/jquery.validate.min.js"></script>
</head>
<body>
<?php if(isset($title)) {?>
<h1><?php echo $title?></h1>
<?php } ?>
<?php if (isset($page_description)) {?>
<p id="page_description"><?php echo $page_description?></p>
<?php } ?>
create.php
<script>
$("#createaccount").validate();
</script>
<?php $attributes = array('id'=>'createaccount');
echo form_open('user/create_account',$attributes); ?>
<?php echo form_label('Email','txtEmail');?>
<br />
<?php $data = array('type'=>'email','name'=>'txtEmail','id'=>'txtEmail','maxlength'=>'50','minlength'=>'2');
echo form_input($data); ?>
<br /><br />
<?php echo form_label('Username','txtUsername');?>
<br />
<?php $data = array('name'=>'txtUsername','id'=>'txtUsername','maxlength'=>'50','minlength'=>'5');
echo form_input($data); ?>
<br /><br />
<?php echo form_label('Password','pswPassword');?>
<br />
<?php $data = array('name'=>'pswPassword','id'=>'pswPassword');
echo form_password($data); ?>
<br /><br />
<?php echo form_label('Confirm Password','pswConfirmPassword');?>
<br />
<?php $data = array('name'=>'pswConfirmPassword','id'=>'pswConfirmPassword');
echo form_password($data); ?>
<br /><br />
<input type="submit" value="Register" name="Register" />
<?php echo form_close();?>
footer.php
<strong>© 2016</strong>
</body>
</html>
result...
<!DOCTYPE html>
<html>
<head>
<title>Discuss Cards - Create New Account</title>
<link rel="stylesheet" href="http://[::1]/forum/styles/forum.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://[::1]/forum/js/jquery.validate.min.js"></script>
</head>
<body>
<h1>Create New Account</h1>
<script>
$("#createaccount").validate();
</script>
<form action="http://[::1]/forum/index.php/user/create_account" id="createaccount" method="post" accept-charset="utf-8">
<label for="txtEmail">Email</label>
<br>
<input type="email" name="txtEmail" value id="txtEmail" maxlength="50" minlength="2">
<br>
<br>
<label for="txtUsername"></label>
<br>
<input type="text" name="txtUsername" value id="txtUsername" maxlength="50" minlength="5">
<br>
<br>
<label for="pswPassword">Password</label>
<br>
<input type="password" name="pswPassword" value id="pswPassword">
<br>
<br>
<label for="pswConfirmPassword">Confirm Password</label>
<br>
<input type="password" name="pswConfirmPassword" value id="pswConfirmPassword">
<br>
<br>
<input type="submit" value="Register" name="Register">
</form>
<strong>© 2016</strong>
</body>
</html>
Now, the links to the js and css files are correct. I used the example from http://jqueryvalidation.org/documentation/:
<form class="cmxform" id="commentForm" method="get" action="">
<fieldset>
<legend>Please provide your name, email address (won't be published) and a comment</legend>
<p>
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" name="name" minlength="2" type="text" required>
</p>
<p>
<label for="cemail">E-Mail (required)</label>
<input id="cemail" type="email" name="email" required>
</p>
<p>
<label for="curl">URL (optional)</label>
<input id="curl" type="url" name="url">
</p>
<p>
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" name="comment" required></textarea>
</p>
<p>
<input class="submit" type="submit" value="Submit">
</p>
</fieldset>
</form>
<script>
$("#commentForm").validate();
</script>
However, I feel that I'm missing something because it's not working. When I use their demo (http://jqueryvalidation.org/files/demo/), a new label is created under the input area which displays the error. However, when I test my code (Notepadd++, latest version of Google Chrome, WAMPServer 2.5), I only get Chrome validation. Could someone point out to me what I'm doing incorrect? Thanks.
A bit too long for a comment, but not sure if it is the only problem. The first thing I see is that the
<script>
$("#createaccount").validate();
</script>
is located before the form with id="createaccount". This means this javascript code is parsed and run before the element exists inside the DOM.
In order to run this JS when the DOM is loaded, you then need to wrap it into this specific jquery part :
$( document ).ready( function( ) {
$("#createaccount").validate();
}
(And ideally you put all JS at the end of the page, before the closing </body> tag)
I want to develop an ez breezy calculator to upload to a page on my site. I have written both the HTML and PHP code to the best of my understanding but still fail to produce an answer to my screen. After I click the "button", I get redirected to a blank screen with no code. When I try it in my site, it takes me back to my home page...every time! Below is all the code...I need help!
<?php
$a=$_POST["'a'"];
$b=$_POST["'b'"];
$c=0;
?>
<meta charset="utf-8">
<html>
<head>
<title>Proposal Sheet Calculator</title>
</head>
<body>
<form method="post" action="/Merchant Calc 1.php">
<h1>How Much Money Are You Losing?</h1>
<p> </p>
<p> </p>
<h2>How many clients walk out your business each month when finding out they don't have the cash or credit to pay?<br/>
<input type="text" name="'a'"><br/></h2>
<h2>What is your average ticket price?<br/>
<input type="text" name="'b'"><br/></h2>
<p> </p>
<h2><input name="calc" type="Submit" value="Show me the numbers" /></h2>
<p> </p>
<p> </p>
<br/>
<p>
<?php
$a = $_POST[‘a’];
$b = $_POST[‘b’];
$c=$a*$b
// should output $a*$b
if(isset($_POST[‘submit’])){
echo "$a * $b";
}
more?<br/>
<input type="text" name="'Y/N'"><br/>
<input name="calc" type="Submit" />
if(isset($_POST[‘submit’]))<br/>
</p>
?>
</form>
</body>
</html>
I don't even get to the "more?" input...it dumps me out before that so I have not done anything below the "more?" lines. And the crazy output of the last if statement...WebMatrix shows no errors.?.?.?.?
Thanks in advance!
<?php
error_reporting(0);
?>
<html>
<head>
<title>Proposal Sheet Calculator</title>
</head>
<body>
<form method="post" action="">
<h1>How Much MONEY Are You Losing?</h1>
<p> </p>
<p> </p>
<h2>How many clients walk out your BUSINESS each month when finding out they don't have the cash or credit to pay?<br/>
<input type="text" name="a"><br/></h2>
<h2>What is your average ticket price?<br/>
<input type="text" name="b"><br/></h2>
<p> </p>
<h2><input name="calc" type="Submit" value="Show me the numbers" /></h2>
<p> </p>
<p> </p>
<br/>
<p>
<?php
$a = $_POST["a"];
$b = $_POST["b"];
$c=$a*$b;
// should output $a*$b
if(isset($_POST["calc"])){
echo $c;
}
?><br/>
<input type="text" name="'Y/N'"><br/>
<input name="calc" type="Submit" />
<br/>
</p>
</form>
</body>
</html>
You have few syntax errors, fix them it will work.
Firstly, add semicolon ; in this line
$c=$a*$b;
^
Next, you are enclosing multiplication operation inside double quotes, so multiplication will now work, it will be considered as string. so remove double quotes.
echo "$a * $b";// will echo number * number
change to
echo $a * $b;// will echo multiplied value.
Next remove action to your form. I mean make action as action=""
Next access either usnf single quotes or double quotes not both.
$a=$_POST["'a'"];
this should be
$a=$_POST["a"]; or
$a=$_POST['a'];
and also
<input type="text" name="'Y/N'"><br/>
this also
<input type="text" name="Y/N"><br/> or
<input type="text" name='Y/N'><br/>
I am a completely new programmer and I am trying to develop a website in php. All I want to do in this part of the code is to "read" the user's inputs and save them as session variables in order to do/ calculate something else in another subpage. In order to see if everything is working fine I added the lines echo "Welcome ",$_SESSION["firstname"]; echo "ok" but it is not working. Can you help me?
Here is my code:
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
<b>First Name:</b> <input name="firstname" type="text" value=""></br></br>
<b>Last Name:</b> <input name="lastname" type="text" value=""></br></br>
<b>Age:</b> <input name="age" type="number" min="0" value=""></br></br>
<b>Number of people in household:</b> <input name="numberofpeopleinhousehold" type="number" min="1"value=""></br></br>
</br></br>
<input type="submit" name="submit" value="Submit">
</form
<?php
session_start();
if (isset($_POST["submit"])){
$_SESSION["firstname"]= $_POST["firstname"];
$_SESSION["lastname"]= $_POST["lastname"];
$_SESSION["age"]= $_POST["age"];
$_SESSION["numberofpeopleinhousehold"]= $_POST["numberofpeopleinhousehold"];
}
echo "Welcome ".$_SESSION["firstname"];//here is....
echo "ok"
?>
</body>
</html>
What session_start() does is sends a cookie in the page header when it's served to the browser. If you've already send some data to the browser, like your form, then PHP will not be able to start a session. You need to move session_atart() to the very top of your document, above the form or any echos. Also, you're missing a semi-colon, as noted by others. Also, you need to properly close your <form> tag.
That is actually working. If you look at the source code you will see the your name is echoed out.
One issue is you are missing a greater than sign at the end of your form tag.
</form
should be
</form>
Also, you need to start the session before any html. Try this...
<?php
session_start();
if (isset($_POST["submit"])){
$_SESSION["firstname"]= $_POST["firstname"];
$_SESSION["lastname"]= $_POST["lastname"];
$_SESSION["age"]= $_POST["age"];
$_SESSION["numberofpeopleinhousehold"]= $_POST["numberofpeopleinhousehold"];
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
<b>First Name:</b> <input name="firstname" type="text" value=""></br></br>
<b>Last Name:</b> <input name="lastname" type="text" value=""></br></br>
<b>Age:</b> <input name="age" type="number" min="0" value=""></br></br>
<b>Number of people in household:</b> <input name="numberofpeopleinhousehold" type="number" min="1"value=""></br></br>
</br></br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if ($_SESSION["firstname"] != ""){
echo "Welcome ",$_SESSION["firstname"];
echo "ok";
}
?>
</body>
</html>
echo output inside if, delcare session start on top, tested and works 100%. Note- add php code on top and close form tag
<?php
session_start(); //session start must be first line
if (isset($_POST["submit"])){
$_SESSION["firstname"]= $_POST["firstname"];
$_SESSION["lastname"]= $_POST["lastname"];
$_SESSION["age"]= $_POST["age"];
$_SESSION["numberofpeopleinhousehold"]= $_POST["numberofpeopleinhousehold"];
echo "Welcome ".$_SESSION["firstname"]; //inside if condition
echo "ok";
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="#">
<b>First Name:</b> <input name="firstname" type="text" value=""/></br></br>
<b>Last Name:</b> <input name="lastname" type="text" value=""/></br></br>
<b>Age:</b> <input name="age" type="number" min="0" value=""/></br></br>
<b>Number of people in household:</b> <input name="numberofpeopleinhousehold" type="number" min="1"value=""/></br></br>
</br></br>
<input type="submit" name="submit" value="Submit"/>
</form> <!-- close form tag -->
</body>
</html>
I have a PHP file that parses a JSON list and feeds it to a combobox:
<?php
$jsonData = '{"marco":"marco#test.it", "giovanni":"giovanni#mail.it"}';
$json = json_decode($jsonData, true);
$opts = '';
foreach($json as $name => $email)
{
$opts .= '<option value="'.$email.'">'.$name.'</option>';
}
echo ' <select name="Team1">'.$opts.'</select> <br> ';
echo ' <select name="Team2">'.$opts.'</select> <br>';
?>
I'm trying to include it in an HTML page, so that when it loads it will show the combobox:
<html>
<head>
<title> Invio Mail </title>
</head>
<body>
<form name="mail" action="mailer.php" method="post">
<p>
<center><b> Invio mail </b>
<br>
<br>
<? include("combobox.php") ?><br>
Messaggio: <input type="text" name="name" rows="5" required><br>
<br>
<center><input type="submit" value=" Invia "></center><br>
</form>
</body>
</html>
But I can't manage to make them appear!
I don't need a real time update, it's enough that the list is updated when the page is created.
Also, I can't manage to read the associated value from the combobox.
Make sure that the HTML page has the .php extension instead of .html and check if your webserver supports short open tag for php.
Edit:
You can check the phpinfo() if short_open_tag has the value on.
Edit 2:
You can access the selected value in your mailer.php with $_POST['Team1'] and $_POST['Team2']
Edit:
<? include("combobox.php") ?>
to
<?php include("combobox.php") ?>
So, html code will be:
<html>
<head>
<title> Invio Mail </title>
</head>
<body>
<form name="mail" action="mailer.php" method="post">
<p>
<center><b> Invio mail </b>
<br>
<br>
<?php include("combobox.php") ?><br>
Messaggio: <input type="text" name="name" rows="5" required><br>
<br>
<center><input type="submit" value=" Invia "></center><br>
</form>
</body>
</html>
I have a simple form where I want users to select items and those items appear on the results page. The items also include a link. I would like the link to be included on the results page too. Right now, I click on a check box with a link and the link does not appear on the results page. Not sure where to go from here.
<html>
<body>
Teaching Tools<br><br>
Testing version only<br><br>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Building: <input type=“text” name=“bldg”><br><br><br>
Teaching Tools:<br><br>
<input type="checkbox" name="videos[]" value="Word"><label>Word</label><br /><br>
<input type="checkbox" name="videos[]" value="Padlet"> <label>Padlet</label><br />
<br>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
Results Page:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Email: <?php echo $_POST["email"]; ?><br><br>
Your building: <?php echo $_POST[“bldg”]; ?><br><br>
<?php
if(isset($_POST['submit'])) { // to run PHP script on submit
if(!empty($_POST['videos'])) {
// Loop to store and display values of individual checked checkbox.
foreach($_POST['videos'] as $selected) {
echo $selected."</br>";
}
}
}
?>
<br><br>Testing Mode<br>
</body>
</html>
Remove the link from the form and add this instead:
<input type="checkbox" name="link" value="http://www.bluevalleyk12.org">
On welcome.php get the value of link with :
$link = $_POST["link"];
If you want to hide the link use type="hidden":
<input type="hidden" name="link" value="http://www.bluevalleyk12.org">
Finally, if you want the link visible but non editable, use readonly:
<input type="checkbox" name="link" value="http://www.bluevalleyk12.org" readonly>