How we can get the content present in contentEditable in html format in PHP
For example i have this code and want to get its value in a variable in PHP:
<div contentEditable="true"> type here
<img src="http://t2.gstatic.com/images?q=tbn:ANd9GcQCze-mfukcuvzKk7Ilj2zQ0CS6PbOkq7ZhRInnNd1Yz3TQzU4e&t=1" /></div>
because i want to use this as html body for an email.
Infact i want to get the value of contentEditable and save it into a variable and then use that variable as a body for my email. Any idea how to perform this task.
You'll need to store the contents of the element in a form element so it can be submitted to your PHP page.
I assume you want contenteditable instead of textarea for rich text... consider taking a look at WYSIWYG editors like TinyMCE instead.
If you still want to stick with your current method, you'll need some JS to copy the value of the div into a hidden form element before the page gets submitted.
HTML
<div id="emailcontent" contenteditable>asdf</div>
<form>
<input type="text" id="a" name="a"/>
<input type="submit" name="submit" id="submit" />
</form>
jQuery
$("#submit").click(function() {
$("#a").val($("#emailcontent").html());
});
DEMO
You can try something like this:
var form = document.createElement("form");
form.setAttribute('action','some.php');
form.setAttribute('method','POST');
form.setAttribute('target','_self');
form.setAttribute('enctype','application/x-www-form-urlencoded');
form.innerHTML = '<input type="hidden" name="emailData" value="'+
document.getElementById('yourdivid').innerHTML+'" />';
form.submit();
Then in your php retrieve POSTed data:
$data = $_POST['emailData'];
If you want to use PHP maybe you can try to use php DomDocument
this is some example maybe same with want you want
How can I get a div content in php
How to get a div via PHP?
or you can use javascript and jquery to do that
Related
I want to make a page that allows the user to enter his Minecraft name, the entered name will be changed in this link:
http://www.minecraft-skin-viewer.net/3d.php?layers=true&aa=true&a=0&w=330&wt=10&abg=330&abd=40&ajg=340&ajd=20&ratio=13&format=png&login=<NAME>&headOnly=false&displayHairs=true&randomness=708
How can i do this?
You can do that with jQuery.
For example, you have this html code:
<input type="text" id="name">
<input type="button" id="dostuff" value="View your Skin!">
<hr>
<iframe width="290" height="433" id="SkinViewer"></iframe>
Where the tags used only contain relevant information for the script to work.
And the following jQuery code will work when the button is pressed. It create's the url with the value of the input field in it. And then sets the source of the iframe with the created url.
$(document).ready(function(){
$('#dostuff').click(function(){
var url = 'http://www.minecraft-skin-viewer.net/3d.php?layers=true&aa=true&a=0&w=330&wt=10&abg=330&abd=40&ajg=340&ajd=20&ratio=13&format=png&login=' + $('#name').val() + '&headOnly=false&displayHairs=true&randomness=930';
$('#SkinViewer').attr('src',url);
});
});
Keep in mind: for the jQuery to work you should load the jQuery library first!
I am quite new to PHP/HTML all this kind of stuff so sorry if this is an easy question!
Is there a way to read the contents of an HTML text area and pass it into a .php file?
Or even just reading the contents of the text area into a variable would do.
Thanks
You can achieve that with a basic form:
index.php:
<?php
if ($_POST) // If form was submited...
{
$text = $_POST["mytextarea"]; // Get it into a variable
echo "<h1>$text</h1>"; // Print it!
}
?>
<form method="post">
<textarea name="mytextarea"></textarea>
<input type="submit" value="Go!" />
</form>
And this can be done whatever input element you want e.g: inputs type text, password, checkbox, radio or a select or even and fresh HTML5 input type.
Give your textarea a name and post it to a PHP script with a form. The data from the textarea will be available in the $_POST['textareaName'] variable.
HTML
<form action="page.php" method="post">
<textarea name="myTextarea"></textarea>
<input type="submit" value="go" />
</form>
PHP
<?php
echo $_POST['myTextarea'];
?>
You can Post the form and can access the variable of the form with $_POST['myObj'];
Looking at the $_POST and fetching the value from the post through object name.
Here, "myObj" is an example object name.
you need to submit the form to get the textarea value. Or you can use Jquery to get the textarea content
How to get the value from a textbox of a form popup JQuery in PHP.
Here's my web page.
use like
$("#inline_content table").find("#makhachhang").val(); // by this get id value in your form and same rest
$("#inline_content table").find(".tdthemkhachhang").val(); // by this get name value in your form and same rest
$("#inline_content table :radio :selected").val(); // by this get radio value in your form and same rest
Try this:
$("#makhachhang").val();
If you want to get the data from textbox with PHP, you'll need put the HTML code inside a form, and send the data via GET or POST.
I recommend you to get the data via Javascript.
$("#inline_content table").find("#makhachhang");
You can use
if input is like that:
$("#IdOfYourInput").val() will return the containt
Basically, just add an action attribute to your form and name attribute to your inputs.
<form action="your php file">
<input name="email" />
<input type="submit" />
</form>
Then on your php file, get it with:
$email = $_POST['email']
I suggest you learn the basics first:
http://www.w3schools.com/html/html_forms.asp
So I am a beginner and as the title says I want to be able to; on the click of a button, allow the user to add another input field to my form. I would also like to be able to remove this.
The use of the form is adding students to a student group, which I will then be storing in my database.
my form example:
<form name="addstudents" id="addstudents" method="post" action="add_students.php">
<table><tr><td>Student:</td><td>
<input type='text' name="1" size='20'></td><td><input type="button" id="add" value="+">
</td><td><input type="button" id="remove" value="-"></td>
</table></form>
However from what I have been looking at there are different suggestions such as using a clone() function or Jquery appendto().
which is the best method for doing so?
thanks
$('form').append('<input ...'); //take care of appending valid DOM elements
//Create the input element
var $el = $('<input>')//Set the attribute that you want
.attr('id','inputID')
.attr('readonly',true);
//And append it to the form
$('#addstudents').append($el);
Remember you also can remove any DOM from your form just find the appropiate jquery selector
$('form > input:last').remove(); // to remove last input
check this working sample that a made on jsfiddle.net to help you with this
I would use JavaScript, I already answered this question here. Just uses plain JavaScript to edit the HTML of the page. Hope this helps!
My Problem is in brief below: This is done using PHP, JS, Smarty and HTML
<form name="todaydeal" method="post">
<span id="fix_addonval"></span>
<input type="radio" name="offer" id="offer_{$smarty.section.mem.index+1}" value="{$display_offers[mem].offervalue}" onclick="return sel_bees(this.value);" />
<input type="submit" name="SET" value="SET" />
</form>
{literal}
<script>
function sel_bees(Val)
{
document.getElementById('fix_addonval').innerHTML='<input type="hidden" name="addon" id="addon" value='+Val+' />'
}
</script>
{/literal}
When i click on the radio button its value must be replaced via javascript innerHTML and it should be placed in the span id. When i submit the form using submit button the value which is replaced in the should be get in the next page. How can this be done ?
Any ideas will be thankful and grateful. Thanks in advance
Your code is so buggy !
Your question is not clear, but if you need to create a text box in the span using javascript you can do the following:
some mistakes you've made in your code
1) you said, you need to create a textbox so you should use (text) as the type of your input.
2) use (;) at the end of the javascript statement to run successfully in all browsers
3) use < script type="text/javascript"> for your javascript code, to make it more readable
4) you've forgot to enclose the value attribute in (") and I do it in the following code for you
jQuery:
$('fix_addonval').html('< input type="text" id="addon" value="' + Val + '"/>');
This approach looks convoluted for me. All you are trying to do is to create a dynamic hidden variable and assign a value to if the checkbox is checked. Ideally, I would keep the hidden variable in the markup and will assign the value to it if the checkbox is checked. Since it is hidden, it is not going affect your HTML markup.
I don't know if span element is supposed to contain anything else besides text, at least the XHTML way, and if the input is of type hidden it can safely reside in the page and simply replace the value.
Try it with jQuery.
http://jsfiddle.net/vXgzK/