i want to have a textarea where I can edit html code directly. After submitting the form the content if the textarea (with html tags) should be saved to a MySQL database. I use PHP to receive the date and save it to the database. My problem is, that the HTML code is not properly sent to PHP. I do not receive the HTML code but just the text. How could I fix this?
my Form looks like this:
<form method="post" enctype="multipart/form-data" action="form.php">
<textarea name="html_code">
testlink
</textarea>
<input type=submit value="submit"/>
</form>
The form.php should now be able to show the content of the textarea
echo $_POST['html_code'];
shows: testlink
I want: testlink
Thank you all for your answers. I found the problem. It was Joomla. Joomla removed HTML tags when I got strings via getVar. I had to use the mask option JREQUEST_ALLOWRAW to solve the issue.
JRequest::getVar('html_code', '', 'post' , 'STRING', JREQUEST_ALLOWRAW);
Are you echoing it into an HTML page? Because the code will be parsed into an actual link.
View the source of your output page.
You're using the wrong encoding type.
Instead of "multipart/form-data", it should be "text/plain".
You don't have to encode the data as Doug says above; but it will be encoded for you when you submit the form, so don't forget to decode before using.
Your form should be:
<form method="post" enctype="multipart/form-data" action="form.php">
<textarea name="html_code">
<a href="link">testlink</a>
</textarea>
<input type=submit value="submit"/>
</form>
(No, it's not messed up. They're called HTML entities)
You can use htmlentities() in PHP to achieve that.
Related
I have successfully hosted an .onion website but I don't have much experience in HTML codes. I need someone to tell me how to create a form + be able to input the submitted stuff inside the form (raw) into a text file + output the contents of a text file. Thanks :) Any help is greatly appreciated.
As per my understanding regarding your requirement, try below stuffs.
In view page(page for input form) use the below HTML code.
<html>
<body>
<form action="" method="POST">
<input name="field1" type="text" />
<input name="field2" type="text" />
<button type="submit">Save</button>
</form>
<button><a href='file_data.php'>Get file data</a></button>
</body>
</html>
Below the above HTML code use the PHP code below for processing submitted form inputs and to add the submitted form data to a text file(data.txt). The text file will be automatically created if it's not existing.
NB: You can also use a PHP file for this, for eg: form.php. In that case use <form action="form.php" method="POST"> in the above HTML code.
Create a file file_data.php and use below code.
$myFile = "data.txt";
$lines = file($myFile);//file in to an array
foreach($lines as $line)
{
echo $line.'<br>';
}
Now, if you click on Get file data button in view page, data added to the text file will be printed.
So I've been playing around with HTML forms and I am kind of new you all of this so any help would go a long way! But anyway... This is my form coding for emailing.
So when I submit that form with the correct areas filled, it then opens
in Outlook (2010 If that matters) were it then converts the spaces in the
body of the email into '+' (Plus symbols)... Can anyone give me ideas?
This HTML will be used on an offline site within our network and will not
go live. All computers are on the domain and will have access to this
HTML link on there desktop.
You should set the enctype attribute of the <form> tag to text.
<form enctype="text/plain" ...
More details in this KB
In both cases, the FORM data is e-mailed in as an Attachment, in an encoded format. For instance, in the preceding case, this is how the data looks:
Subject=Test+Subject&Body=%09kfdskfdksfkds%0D%0A%09
This is because the default ENCTYPE attribute for the FORM element is "application/x-www-form-urlencoded". To e-mail data in > plain-text format instead, explicitly specify an ENCTYPE attribute of "text/plain". For instance:
<FORM Action="mailto:xyz" METHOD="POST" ENCTYPE="text/plain">
mailto: protocol test:
<Br>Subject:
<INPUT name="Subject" value="Test Subject">
<Br>Body:
<TEXTAREA name="Body">
kfdskfdksfkds
</TEXTAREA>
<BR>
<INPUT type="submit" value="Submit">
</FORM>
produces the following Body:
Subject=Test Subject
Body= kfdskfdksfkds
You can use %20 for spaces in mailto links. I think you need to convert the + to spaces before you open the mailto link.
I am trying to create an upload script and am having issues with IE8 and older. (of course ;) ) In all other browsers it works fine but in IE8 the $_FILES array is empty. This is the html code being used:
<FORM method=post action=api/upload.php target=form8230839>
<INPUT name=file type=file>
<INPUT value="Submit Query" type=submit>
<INPUT name=id value=id66130748349062623150808191 type=hidden>
</FORM>
<IFRAME id=form8230839 name=form8230839></IFRAME>
(note the code is being generated by javascript createElement so IE8 is writing it out with the caps and lack of quotes around attributes.)
Then in the php file I am doing:
print_r($_FILES);
which returns as just an empty array? Any help would be great. Thanks!
Add enctype="multipart/form-data" to your form tag.
Spec: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
Your question seems to be a possible duplicate of this one:
$_FILES array in PHP is empty
Nevertheless, as others have pointed out, and also from the attached, the solution is to add:
enctype="multipart/form-data"
to your form.
I have a HTML form as follows:
<form action="/AddFile" method="post">
<input type="file" name="filedata"/>
<input type="submit" value="Add File"/>
</form>
When I use it and submit a file called foo with content bar the POST request contains filedata=foo not filedata=bar as expected.
What am I doing wrong? How do I get the content of the file?
One you need to add enctype="multipart/form-data" to the form.
Two you need to get the files from $_FILES instead.
Three I think it's file_get_contents($_FILES['filedata']['tmp_name']); to get the file's contents.
Your markup lacks the attribute enctype="multipart/form-data", which is needed when a file field is present. See HTML 4.01 spec on form element.
Using multipart/form-data, the file contents get sent. The rest depends on your server-side handler.
I have a form, text input and a submit button. How do I append the value of the text box to the form action i.e.
action="https://www.mywebsite.com/" & txtSessionId
The form looks like this:
<form name="form1" method="post" action="https://www.mywebsite.com/">
<label>Your Sessions ID:
<input type="text" name="txtSessionId" id="txtSessionId">
</label>
<label>
<input type="submit" name="btnContinue" id="btnContinue" value="Continue">
</label>
</form>
I want the link to look like this: https://www.mywebsite.com/123456
where 123456 is typed into the text box by the user.
Thank you
You'd have to either use javascript or something server-side to do that (or both).
Javascript:
<form name="form1" method="post" action="https://www.mywebsite.com/"
onsubmit="location.href = this.action + this.txtSessionId.value; return false;">
Server-side (PHP)
if (!empty($_POST['txtSessionId']))
{
header('Location: https://.....' . (int)$_POST['txtSessionId']);
exit();
}
The correct behavior is to send the input field to the existing form, process it, and redirect. You don't know if the user sent a valid input value yet!
In this cases I always recommend javascript unless accessibility is an strict requirement for you.
I assume you are using something like mod-rewrite on your server if you are accepting URLs like this. So, why not just write a rule on there to check if txtSessionId is set and then re-write it to whatever you'd like?
I don't know how to write mod-rewrite rules all that well, but, I definitely know you can do it.
If you're using PHP, Greg did present a fairly viable alternative to using mod-rewrite (or something similar).