php form handling input value post self some characters error - php

i post data into form action to php self some characters make errors. This charactor are " or \ if u put " input name return into \ how to fix it
<form id="form1" name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<label for="name"></label>
<input name="name" type="text" id="name" value='<? print htmlspecialchars($_POST['name']); ?>' />
<br />
<input type="submit" name="button" id="button" value="Submit" />
<? print htmlspecialchars($_POST['name']); ?>
</form>

Im not exactly sure what the problem is but I think you are getting errors when returning special characters into an input field. If so try this: http://php.net/manual/en/function.htmlentities.php you will need to convert the special characters into html entities so the data isnt read as code which will cause issues.
I have just tested this by changing the message input to <?php echo htmlentities($_POST['name']); ?> and the characters are displaying as normal.
Use this code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="name"></label>
<input name="name" type="text" id="name" value="<?php echo htmlentities($_POST['name']); ?>" />
<br />
<label for="message"></label>
<textarea name="message" id="message" cols="45" rows="5"><?php echo $message; ?></textarea>
<br />
<input type="submit" name="button" id="button" value="Submit" />
</form>
echoed (<?php echo htmlentities($_POST['name']); ?>);
</body>
</html>

Related

How to keep data inside a text area after submission?

I have a text area where i can input text, after the form has been submitted the text from the first field goes to the second output field. Now I have the exact same things on the same page, so input field, submit and output field. What I want is when the either one of the submit buttons have been pressed, the output will stay and not clear out. Here is what I've done so far:
<head>
<title></title>
<meta charset="utf-8">
<?php
$inputText = $_GET['FirstText'];
$InputTextTwo = $_GET['SecondText'];
?>
</head>
<body>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="FirstText"></textarea>
<br>
<input type="submit" name="submit_firstField" value="FirstField">
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfFirst"><?php echo $inputText; ?></textarea>
</form>
<hr/>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="SecondText"></textarea>
<br>
<input type="submit" name="submit_SecondField" value="SecondField">
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfSecond"><?php echo $InputTextTwo; ?></textarea>
</form>
</body>
As you can see, when the first submit has been done and I want to do the second one, the first output disappears, and vice versa.
I have solved your problem.
The main reason is the two textareas now used different Form.
So Only one textarea value can submit at once.
I added temp hidden-input field inside each form and run the code.
And It's working well now. Please check them.
Tian Yang
<html>
<head>
<title></title>
<meta charset="utf-8">
<?php
$inputText = 'asdf';
$InputTextTwo = 'bbbb';
if(isset($_GET['FirstText'])){
$inputText = $_GET['FirstText'];
$InputTextTwo = $_GET['temp'];
}
if(isset($_GET['SecondText'])){
$InputTextTwo = $_GET['SecondText'];
$inputText = $_GET['temp'];
}
?>
</head>
<body>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="FirstText"></textarea>
<br>
<input type="submit" name="submit_firstField" value="FirstField">
<input type="hidden" name="temp" value ="<?php echo $InputTextTwo; ?>" />
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfFirst"><?php echo $inputText; ?></textarea>
</form>
<hr/>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="SecondText"></textarea>
<br>
<input type="submit" name="submit_SecondField" value="SecondField">
<input type="hidden" name="temp" value ="<?php echo $inputText; ?>" />
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfSecond"><?php echo $InputTextTwo; ?></textarea>
</form>
</body>
</html>

Pass variable PHP/HTML

Need to pass variable from actual site like this
<form id="form" action="Atest.php" method="post" enctype="multipart/form-data">
name: <input name="name" value="" id="name" /> <br />
**<a href='Atest.php?searchname=<?php $_GET['name'];?>'>**GO</a>
</form>
The part searchname= isn t working.
Problem still staying after SET/SET or GET/GET fix
Page throwing :
/Atest.php? searchname= Notice:%20%20Undefined%20index:%20name%20in%20C:\xampp\htdocs\PhpProject3\Atest.php%20on%20line%2032
fULL CODE
<?php
function runMyFunction(){ echo "DONE";
}
if (isset($_GET['searchname'])) {
runMyFunction();
}
?>
<html><head></head>
<body>
<div class="sas">
<form id="form" action="Atest.php" method="post" enctype="multipart/form-data">
Heslo: <input name="name" value="" id="name" /> <br />
<a href='Atest.php?searchname=<?php $_POST['name'];?>'>Run PHP Function</a>
</form></div></body></html>
The closest I can think you mean is like this:
<?php
function runMyFunction(){
echo "DONE";
}
if ( isset( $_GET['searchname'] ) ) {
call_user_func('runMyFunction');
}
?>
<html>
<head></head>
<body>
<div class="sas">
<form id="form" method="get" enctype="multipart/form-data">
Heslo: <input name="searchname" value="" id="name" /> <br />
<input type='submit' value='Run PHP Function'>
</form>
</div>
</body>
</html>
You could alternatively use a textual link and assign a javascript function to it that submits the form.
You have to do this following way:
<form id="form" action="Atest.php" method="get" enctype="multipart/form-data">
name: <input name="searchname" value="" id="name" /> <br />
<button type="submit">**GO</button>
</form>
This code will throw you an error. you are mixing POST and GET.
<form id="form" action="Atest.php" method="post" enctype="multipart/form-data">
name: <input name="name" value="" id="name" /> <br />
****GO
Before you use GET or POST, make sure you check for the value.
if(isset($_GET['name']){
// your stuff here
}
you can try this one:
<a href='Atest.php?searchname=<?php $_GET['name'];?>'>**GO</a>

connection between php scripts and html input

<form id="submit-form" method="post" action="" enctype="multipart/form-data">
<label>dateField1</label>
<?php
print "<b>calendar:</b><br/>";
$dateField1 = new dateField($format,"date1",$img);
$dateField1->setTitles($arr_daysOfTheWeek,$arr_months,$format_title);
$dateField1->setCssClasses($arr_cssClasses);
print "value:" . $dateField1->makeDateField();
?>
<input type="text" class="span3" name="dateField1" tabindex="2" value=" " />
</form>
I want to make that value in php script ... be related to the value of the input form html
I tried so many ways ,but not implemented , please help
Try it like
PHP in HTML :
<input type="text" class="span3" name="dateField1" value="<?php echo $dateField1->makeDateField();?>" />
Or even you can try like
HTML in PHP :
<?php echo '<input type="text" class="span3" name="dateField1" value="'. $dateField1->makeDateField().'" />';?>
Try this:
<form id="submit-form" method="post" action="" enctype="multipart/form-data">
<label>dateField1</label>
<?php
print "<b>calendar:</b><br/>";
$dateField1 = new dateField($format,"date1",$img);
$dateField1->setTitles($arr_daysOfTheWeek,$arr_months,$format_title);
$dateField1->setCssClasses($arr_cssClasses);
$value = $dateField1->makeDateField();
?>
<input type="text" class="span3" name="dateField1" tabindex="2" value=" <?php echo $value; ?> " />
</form>
You can use php inside html by starting php tags within html
<form id="submit-form" method="post" action="" enctype="multipart/form-data">
<label>dateField1</label>
<?php
print "<b>calendar:</b><br/>";
$dateField1 = new dateField($format,"date1",$img);
$dateField1->setTitles($arr_daysOfTheWeek,$arr_months,$format_title);
$dateField1->setCssClasses($arr_cssClasses);
print "value:" . $dateField1->makeDateField();
?>
<input type="text" class="span3" name="dateField1" tabindex="2" value="<?php echo $value;?>" />
</form>

PHP Post Variable

How would i get the $frompage variable to send to the page it is posting to here is what i thought:
<link rel="stylesheet" type="text/css" href="style1.css" />
<?php
$frompage = $_SERVER['HTTP_REFERER'];
echo '<form name="form1" method="post" action="report.php">';
echo "What is Wrong?";
echo '<textarea style="resize: none;" name="message" cols="70" rows="10" id="message"> </textarea>';
echo'<input type="hidden" name="$frompage" value="$frompage">';
echo '<input type="submit" name="Submit" value="Submit">';
echo "</form>";
?>
If you change this line:
'<input type="hidden" name="$frompage" value="$frompage">'
into this:
'<input type="hidden" name="frompage" value="$frompage">'
when the user send the data, you can retrieve it using:
$_POST['frompage']
Keep it simple, no need to echo all of the HTML.
<link rel="stylesheet" type="text/css" href="style1.css" />
<form name="form1" method="post" action="report.php">
<label>What is Wrong?</label>
<textarea style="resize: none;" name="message" cols="70" rows="10" id="message"> </textarea>
<input type="hidden" name="frompage" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
<input type="submit" name="Submit" value="Submit" />
</form>
First your using too much echos :P this is how I would do it.
<link rel="stylesheet" type="text/css" href="style1.css" />
<?php
$frompage = $_SERVER['HTTP_REFERER'];
?>
<form name="form1" method="post" action="report.php">
What is Wrong?
<textarea style="resize: none;" name="message" cols="70" rows="10" id="message"> </textarea>
<input type="hidden" name="<?php echo $frompage" ?> value="<?php echo $frompage" ?>>
<input type="submit" name="Submit" value="Submit">
</form>
When you use echo ''; The single quotes forces everything to be read exactly as it stated. If you REALLY wanted to echo all that html, use double quotes.
Such as echo "Hello $frompage";

HTML form PHP post not working

I'm writing a little website for myself and I'm having trouble with what seems like a simple line of code:
form action="send.php" method="post"
Furthermore, even a simple line like form action="http://www.google.com"> isn't working. Here is my code:
<html>
<head>
<title>
AnonMail!
</title>
</head>
<body style="font-family:'Tahoma';>
<form action="send.php" method="post">
<label for="from">From: </label><input type="text" name="from" id="from"></input></br>
<label for="to">To: </label><input type="text" name="to" id="to"></input></br>
<label for="subj">Subject: </label><input type="text" name="subj" id="subj"></input></br>
<textarea rows=10 cols=100 name="message"></textarea></br>
<input type="submit" value="Send"/>
</form>
</body>
</html>
The error starts with your body tag.
You have not closed your double quotes in the style tag of your body.
Just close it properly and then run it.
I think that is only the problem.
Here's a form that should work:
<html>
<body>
<form action="contact.php" method="post">
<p><b>Your Name:</b> <input type="text" name="yourname" /><br />
<b>Subject:</b> <input type="text" name="subject" /><br />
<b>E-mail:</b> <input type="text" name="email" /><br />
Website: <input type="text" name="website"></p>
<p><input type="submit" value="Send it!"></p>
</form>
</body>
</html>
If you're still having troubles: http://myphpform.com/php-form-not-working.php
browsers show warnings when your action refers to an external source. Some browsers do not post form at all. This is unsafe for users.

Categories