I have a form
<form action="welcome.php" method="post" ........................">
<button id=......................ERATE NEW ....</button>
<br/><br/>
<div class="form-field">
<label for...............">....... TEST</label>
<br/>
<textarea id=...........................="false"></textarea>
<span class="clipSp............ successfully copied to clipboard" ></span>
<br/>
</div>
<br/>
<div clas..........content">
<div>ADDRESS
<br/>
<span>{{vm.displayAddress}}</span>
</div>
</div>
<button class="wButton fade" type="submit">REGISTER ACCOUNT</button>
<span class="divider-2"></span>
<button class="wButton fade" type="reset" ng-click="vm.back()">BACK</button>
.
.
.
.
Then i have this "welcome.php" file.
if(!empty($_POST['formdesiredpost'])){
$var = $_POST['formdesiredpost'];
file_put_contents("data.txt", $var . "\n", FILE_APPEND);
header("Location: https://randomwebsiteredirect.com");
exit();
}
Its supposed to post the desired value from the form (textarea) into a txt file, data.txt and then redirect to a website.
The problem is that it only works for short length inputs. I mean aprox (15 characters) , if I input more than 15 , like 70, it simply redirects to blank welcome.php and does nothing.
Any clue of what may be happening?
On your html you don't have the "formdesiredpost" field. Please check does there exist "formdesiredpost" field.
And in your welcome.php, on the top side of your code add error reporting function:
error_reporting(0);
To see what happened after send data to welcome.php
Works fine:
index.php:
<form action="welcome.php" method="post">
<textarea name="formdesiredpost"></textarea>
<input type="submit" value="submit">
</form>
welcome.php
<?php
if(!empty($_POST['formdesiredpost'])){
$var = $_POST['formdesiredpost'];
file_put_contents("data.txt", $var . "\n", FILE_APPEND);
header("Location: https://randomwebsiteredirect.com");
exit();
}
?>
And please check your character limits of fields:
Limit number of characters allowed in form input text field
Related
Previously I wrote a PHP code that includes an HTML form. So basically, the user inputs info in the HTML form and if all necessary input is filled, then the PHP file directs information to another PHP file. This is the HTML form I made This is the PHP File code (I will only put one variable of the form so that it's easier to understand:
<?php
session_start();
include('config/db_connect.php');
$Telephone = '';
$errors = array('Telephone' => '');
if(isset($_POST['submit'])){
// check Telephone
if(empty($_POST['Telephone'])){
$errors['Telephone'] = 'A Telephone number is required';
} else{
$Telephone = $_POST['Telephone'];
$_SESSION['Telephone'] = $Telephone;
if(!filter_var($Telephone, FILTER_VALIDATE_INT)){
$errors['Telephone'] = 'Telephone must be a valid Telephone number';
}
if(array_filter($errors)){
//echo 'errors in form';
} else {
// escape sql chars
header('Location: OTP.php');
}
} // end POST check
?>
<!DOCTYPE html>
<html>
<?php include('templates/header.php'); ?>
<section class="container grey-text">
<h4 class="center">Add a form</h4>
<body>
<form class="white" action="add.php" method="POST">
<label style="font-size: 16px">Your Telephone</label>
<input type="text" name="Telephone" value="<?php echo htmlspecialchars($Telephone) ?>">
<div class="red-text"><?php echo $errors['Telephone']; ?></div><p></p>
<div class="center">
<input type="submit" name="submit" value="Submit" class="btn brand z-depth-0">
</div>
</form>
</body>
</section>
<?php include('templates/footer.php'); ?>
</html>
Anyway, due to some reason, now I need to make the HTML form in a separate HTML file. So when users inputs the data in that form, the data has to be transferred to the PHP file I mentioned above and the innit['submit'] has to take place to further process it from there. In other words, previously the HTML form within the PHP file was filled and when 'submit' was clicked, the PHP file redirected it to another PHP file, but now the HTML form is in a HTML file itself and I want that when the form in that file has a click on 'submit', the PHP file is forced to follow the same procedure as it did previously. However, I cannot make the HTML file transfer the info to PHP and the PHP to directly go into the innit['submit'] function.
Here's the HTML part of the code (in the new HTML file):
<form action="work/add.php" method="POST">
<div id="Group_206">
<div id="Text_ca">
<span>電話號碼</span>
</div>
<input class="TextBox03" type="text" id="Telephone" name="Telephone">
<div id="Phone_name_position">
</div>
<div id="Group_159_m">
<input type="submit" value="Submit" >
</div>
The answer is as given in the comment by brombeer:
if(isset($_POST['submit'])){ will never be triggered, there is no
HTML element with name="submit" – brombeer
<form entype="multipart/form-data" method="GET" action="">
<div class="box-body">
<input class="form-control input-lg" name="keyword" type="text" placeholder="Masukkan kata kunci">
</div>
<div class="box-body">
<input value="1" type="checkbox" class="minimal" name="queryexp" />
Gunakan query expansion
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary" value="Submit">Submit</button>
</div>
</form>
Hi hello I want to ask a simple question. The code above is search.php,
I want to send the form to a different page based on if the checkbox is checked or not. If the checkbox is checked it will be directed to resqueryexp.php, but if not it will be directed to result.php
I have been trying to adding this code but it doesn't work.
<?php
if (isset($_GET['queryexp'])){
header("Location: resqueryexp.php");
}else{
header("Location: result.php");
}?>
Sorry for my bad English and Thanks in advance.
<?php
if ( isset( $_GET['submit'] )) {
if ($_GET['queryexp'] == 1 ){
header("Location: resqueryexp.php");
exit;
}
else
{
header("Location: result.php");
exit;
}
}
?>
<html>
<head><title>test</title>
</head>
<body>
<form enctype="multipart/form-data" method="GET" action="">
<div class="box-body">
<input class="form-control input-lg" name="keyword" type="text" placeholder="Masukkan kata kunci">
</div>
<div class="box-body">
<input value="1" type="checkbox" class="minimal" name="queryexp" />
Gunakan query expansion
</div>
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary" value="Submit">Submit</button>
</div>
</form>
This code won't run here at SO, but this is how it may work on your webserver. The important part is to test if the form was submitted. So, in this case, I gave the submit button the name of "submit" and then tested with PHP to see if the form was even submitted. If the form is submitted and if the checkbox is checked, the redirect via header() occurs. Otherwise, if the checkbox is unchecked, then the redirect occurs via header to result.php. You may avoid header issues by making an adjustment to you PHP.ini settings and adding this line "output_buffering = On".
Note: usually a form with the enctype attribute having a value of "multipart/form-data" involves submitting a file and under such circumstances the method attribute should be a POST request instead of a GET; see MDN.
Remember that header() must be called before any actual output is
sent, either by normal HTML tags, blank lines in a file, or from PHP.
It is a very common error to read code with include, or require,
functions, or another file access function, and have spaces or empty
lines that are output before header() is called. The same problem
exists when using a single PHP/HTML file.
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
http://php.net/manual/en/function.header.php
<form id="form" name="form" method="post" action="">
<div class="jquery-script-clear"></div>
<h1>BARCODE GENERATOR</h1>
<div id="generator"> Please fill in the code :
<input type="text" name="barcodeValue" id="barcodeValue" value="1234"><br> <br>
</div>
<div id="submit">
<input type="button" onclick="generateBarcode();" value=" Generate "> <input type="button" onclick="printDiv('print')" value="Print" />
</div>
</form>
<?php
$barcodeValue = $_POST["barcodeValue"];
$save = file_get_contents("save.txt");
$save = "$barcodeValue" . $save;
file_put_contents("save.txt", $save);
echo $save;
?>
sample picture
How to save the input data in save.txt file. When i clicked generate button the text file not showing in same folder.
The problem with your code is you have no submit button so your form was not actually posting when you pressed the button. if you look at my edits you can see I changed the button from input type="button" to type="submit". That allows for the form to submit back to the same php script.
Your script also was causing errors because you accessed $_POST["barcodeValue"] without checking if it existed. You also have to check if the save.txt exists before reading from it. If analyze my edits you can see how checking if the variables are available will help quite a bit.
<form id="form" name="form" method="post" action="">
<div class="jquery-script-clear"></div>
<h1>BARCODE GENERATOR</h1>
<div id="generator"> Please fill in the code :
<input type="text" name="barcodeValue" id="barcodeValue" value="1234"><br> <br>
</div>
<div id="submit">
<input type="submit" value=" Generate ">
</div>
</form>
<?php
if(isset($_POST["barcodeValue"]))
{
$barcodeValue = $_POST["barcodeValue"];
if(file_exists("save.txt"))
$save = file_get_contents("save.txt");
else
$save = "";
$save = $barcodeValue . $save;
file_put_contents("save.txt", $save);
echo $save;
}
?>
Let me know if you need more help
So I'm trying to use this http://www.formget.com/how-to-redirect-a-url-php-form/ as an RSVP form.
Ideally, entering the right code on (http://baby.engquist.com/invite/) will lead you to a google form. However, when I enter any code (right or wrong) and press the button, it simply refreshes back to the /invite page.
My code is as follows:
<p style="text-align: center;">
<form action="index.php" id="#form" method="post" name="#form">
<div class="row">
<div class="large-3 columns large-centered">
<div class="row collapse">
<div class="small-10 columns">
<input id="code" name="code" placeholder="Enter the code to RSVP." type="text" >
</div>
<div class="small-2 columns">
<input id='btn' name="submit" type='submit' class="button prefix" value='Go'>
</div>
</div>
</div>
</div>
<?php
include "redirect.php";
?>
</form>
</p>
And the included redirect.php:
<?php
if(isset($_POST['submit'])){
// Fetching variables of the form which travels in URL
$code = $_POST['code'];
if($code ='show620')
{
// To redirect form on a particular page
header("Location:http://google.com/");
} else {
print "Oops that's not the right code. Try again!";
}
?>
Thanks so much for any help!
You should have action attribute pointing to file where you do processing after submitting. In your case its redirect.php
Use :
<form action="redirect.php" > ............
And dont include redirect.php at the bottom of the form.
You need to write ob_start(); on top of your page and die(); after header("Location:http://google.com/"); in redirect.php
The php header redirect only works if it's called from a page that is completely blank. You have to change your form action to "redirect.php" and simply get rid of the code at the bottom of your html.
Im having a problem displaying a php function. Its for an admin log in form.
The Function Look Like this -
function displayAdmin(){
//test if login is valid
if (isset($_SESSION['adminLogin'])){
if($_SESSION ['adminLogin']=="valid"){
?>
<script type="text/javascript">location.replace('addproduct.php')</script>
<?php
}
else {
// test if login is invalid
// display error message and login form
if($_SESSION['adminLogin']=="invalid") {
echo "<div>Incorrect User ID and/or password provided</div>";
?>
<form name="adminLogin" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div id="sign_up_form">
<label><strong>Username:</strong> <input type = "text" name="userID" class="sprited"/></label>
<label><strong>Password:</strong> <input type="password" name="passWord" class="sprited"/></label>
<div id="actions">
<a class="close form_button sprited" id="cancel" href="#">Cancel</a>
<a type ="submit" name="adminSignin"class="form_button sprited" id="log_in" href="">Sign in</a>
</div>
</div>
</form>
<?php
}
}
?>
<form name="adminLogin" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div id="sign_up_form">
<label><strong>Username:</strong> <input type = "text" name="userID" class="sprited"/></label>
<label><strong>Password:</strong> <input type="password" name="passWord" class="sprited"/></label>
<div id="actions">
<a class="close form_button sprited" id="cancel" href="#">Cancel</a>
<a type ="submit" name="adminSignin"class="form_button sprited" id="log_in" href="">Sign in</a>
</div>
</div>
</form>
<?php
}
} // end of function
And on my page where I am wanting the function to sit the code looks like this -
<?php
session_start();
// Test that page title has been created
if (!isset($pageTitle)) {
$pageTitle = '<< Page title not set >>';
}
// include the myFunctions file
include('includes/myFunctions.php');
// test if login details have been keyed in
if(!empty($_POST["userID"])) {
// Store userID and passWord in local variables
$userID=$_POST["userID"];
$passWord=$_POST["passWord"];
// check database for valid customer
checkValidAdmin($userID, $passWord);
}
?>
and then -
<div id="sign_up">
<h3 id="see_id">Administration Log in</h3>
<span>Please sign in using the form below</span>
<div><?php displayAdmin(); ?></div>
<a id="close_x" class="close sprited" href="#">close</a>
</div>
I have searched long and hard for this problem but can not seem to find the issue, if the issue jumps out at anyone I would love to hear from you!
Thank you so much in advance!!
Definitely your $_SESSION ['adminLogin']=="valid" condition is not true. Check it is set properly or session_start(); is called at beginning of the script.
The problem is you did'nt return the html string.
You should assign the form to a variable, and at the end of the function , return this variable.
$_SESSION['adminLogin'] value is empty i.e. not set or null. that is the reason function inside condition not satisfied.