I just learned to use form in CodeIgniter. I had learn it before, but run on Windows. And now, I'm trying on Ubuntu. I had followed user_guide, but when I was running it, there was no change on the page.
Here are the view named myform.php
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<input type="text" name="name" value=""/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
the other form named formsuccess.php
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h3>Your form was active!</h3>
<p><?php echo anchor('form', 'Try it again!'); ?></p>
</body>
here are the controller named form.php
function index() {
$this->load->helper(array('form'));
$this->load->library('form_validation');
if ($this->form_validation->run() == FALSE) {
$this->load->view('myform');
} else {
print_r('good luck!');
}
}
when I click on submit button, it still show myform.php means the form is not working. Can you see the problem? Is there any difference between running CodeIgniter on Windows and Ubuntu?
I'm sorry for the stupid question. Because there is a note on user guide that I wasn't see. "If you submit the form you should simply see the form reload. That's because you haven't set up any validation rules yet."
Related
So I want to have the user input an animal into the array and it display back using the PHP function. I know I am missing some code, but what else do I need?
<!DOCTYPE html>
<html>
<head>
<title> Proj. 2</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1> Animal Form</h1>
<form action="display.php" method="post">
Enter animal:<br>
<input type="text" name="animal"><br><br>
<input type="Submit" value="Add Animal">
</form>
<?php
function display() {
$animal = $_POST['animal'];//If code doesnt work change these variables
echo $_POST["animal"];
}
?>
</body>
</html>
Your function display() hasn't been called. Just call it
<?php
display();
?>
Call your function, if $_POST['animal'] is set, actually you created function but didn't call it to print the value,
if(isset($_POST['animal'])){
display();
}
I am new in using PHP - i am trying to get the data from data sent to the Apache server using $_POST - but i am getting nothing
below is the details
i am using XAMPP on Windows 7 for setup (Apache & PHP)
and I am having two files
welcome.html which is calling welcome.php to echo the contents got from the html
Note that I have nothing reported in Apache error log file
C:\xampp\apache\logs\error.log
any idea what went wrong here
<head>
<meta charset="utf-8"/>
</head>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
<input type="submit">
</form>
</body>
and
welcome.php
<?php
error_reporting(E_ALL);
?>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
</head>
<body>
Welcome
<?php echo $_POST["name"]; ?><br>
</body>
for testing your php file. direct run this welcome.php from your localhost
like this http://localhost/welcome.php
<?php
echo 'Check your name';
?>
if you see "Check your name"; then your local server is working . else need to run local server
this is your html welcome.html file
<head>
<meta charset="utf-8"/>
</head>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
<input type="submit">
</form>
then submit your form using name text
then check your code using
<?php
error_reporting(E_ALL);
print_r($_POST);
?>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
</head>
Welcome
everything work here
this is the code for my html page in the site:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>index</title>
</head>
<body>
<html>
<body>
<form action="Untitled-4.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
</body>
</html>
and this is my code for the "Untitled-4.php" file:
<html>
<body>
<?php
if ($_GET["name"] == "tom"){
echo "hello you are special";
}
?>
</body>
</html>
this is the error i am getting:
"undefined index on line 7 of the php file"
I am trying to use the GET method to take whatever the user types in the "name" box to be used in the if statement that echoes "you are special" if the user types in "tom". can anyone tell me what the problem here is.
(the question stack overflow is saying is a possible duplicate is a completely different question)
Check if the variable is set first:
<html>
<body>
<?php
if (isset($_GET["name"])) {
if ($_GET["name"] == "tom"){
echo "hello you are special";}
} else {
echo "you are not special";
}
?>
</body>
</html>
for some reason i just tried it again with no changes to my code and it appears to be working i did not actually have to do anything.
When I run following snippet and click 'submit', 'price' is not posted; is there something I forgot ?
<?php
var_dump($_POST);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="libs/dijit/themes/claro/claro.css">
<script>dojoConfig = {async: true}</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script>
</head>
<body class="claro">
<form id="myform" method="post" action="index.php">
<input class="cif" name="price" type="text" value="125.10" />
<input type="submit" value="submit" name="submit">
</form>
<script type="text/javascript">
require(["dojo/ready", "dijit/form/NumberTextBox", "dojo/behavior"],
function(ready, box, behavior){
ready(function(){
behavior.add({
'.cif': function(node) { //assumes "found"
new box({constraints: {pattern: "###,###.00"}, value: dojo.number.format(node.value, {places:2})},node);
}
});
behavior.apply();
});
});
</script>
</body>
</html>
Sorry for this newbie question
Erik
Replace:
var_dump($_POST);
With:
var_dump($_POST['price']);
Recently I ran into similar problem and only this result I found but with no answer. But today I figure it out so I'll share my knowledge.
When you are creating a new widget box you also need to define 'name' attribute otherwise the widget will generate hidden input with no "name" attribute which is required when posting.
Change this line:
new box({constraints: {pattern: "###,###.00"}, value: dojo.number.format(node.value, {places:2}), name: "price"},node);
Trix
In a form I have an <iframe> that contains a PHP file (editor.php). This PHP file contains an HTML form.
Well, when I do a "submit form", I call the same PHP file, for example main.php.
When I press the submit button, I have "onclick method" that it calls a Javascript function inside editor.php. This function executes the form.
My problem is that main form is executed correctly but the second form is not.
In the second loop of the form of editor.php receives nothing.
**Check this way it will work as you expected**
//main.php
<html>
<head>
<script type="text/javascript">
function validateMain()
{
alert('main');
}
function validateSub()
{
alert('sub');
}
</script>
</head>
<body>
<form id="main" onsubmit="return validateMain();">
<input type="text" name="first" id="first"/>
<input type="submit" value="Submit Main"/>
</form>
<iframe name="ifr-form" id="ifr-form" src="test.html"></iframe>
</body>
</html>
//test.html the second form included through iframe
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<form id="sub" onclick="return window.top.validateSub();">
<input type="text" name="first" id="second"/>
<input type="button" value="Submit Sub" />
</form>
</div>
</body>
</html>
you must check if php and iframe are compatible, as far as i Know I don't think that frames and php gives any output, hope this helps.