This is my code..I want to fetch data from textarea..
Im using ckeditor to make it active i have use contenteditable="true"...but when i use this it is not able to fetch textarea value
<body>
<form action="sample_posteddata.php" method="post">
<div id="container">
<div id="header">
<div id="headerLeft">
<h2 id="sampleTitle" contenteditable="true">
<textarea name="article_title" ></textarea>
</h2>
</div>
</div>
</div>
<div id="columns">
<div id="column1">
<div contenteditable="true">
<textarea name="article_body" ></textarea>
</div>
</div>
</div>
<input type="submit" name="submit" value="Submit">
</form>
</body>
from this code it gives me error of undefined index article_body
please suggest me with some solution
In PHP you can fetch form data by form attribute name Try this
$_POST['article_body']` and `$_POST['article_title']
OR
$_REQUEST['article_body']` and `$_REQUEST['article_title']
Remember ckeditor may change the name of that textarea.
Dump post data using
echo'<pre>';
print_r($_POST);
And check the exact variable name.
OR
For exact name you can use inspect element (or press f12)
Related
I am trying to $_GET a hidden input using PHP.
When I check the html code in Chrome, Safari, etc., I can see the value of the hidden variable but when I try to echo it with PHP it is empty. All of this is inside a modal.
I don't really understand what I am doing wrong.
I hope some of you can help me.
<form method="get">
<input name="hiddencontainer" type="hidden" id="hiddencontainer" value="default"/>
</form>
<div id="frame" class="modal">
<div class="modal-content">
<!-- Body content -->
<div class="modal-body">
<p id="content">
<?php
// Get information
$id = $_GET["hiddencontainer"];
echo $id;
?>
</p>
</div>
</div>
</div>
You need to submit the form to get the value, try this
<form method="get">
<input name="hiddencontainer" type="hidden" id="hiddencontainer" value="default"/>
Click the button to submit the form and you will see the value
<input type="submit" name="Submit form"/>
</form>
<div id="frame" class="modal">
<div class="modal-content">
<!-- Body content -->
<div class="modal-body">
<p id="content">
<?php
// Get information
$id = $_GET["hiddencontainer"];
echo $id;
?>
</p>
</div>
</div>
</div>
I'm using Bootstrap with Laravel 4.2. Whenever I try to add more than 1 textarea to my form, I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'comment'
cannot be null
I have isolated the problem to be that whichever textarea I allow to be first, no matter what variable name I give it or how I try to save it, only the first textarea content gets saved and the others get "null" when I try to read it in using Input::get('my_textarea_name');
Here's a snipped of my form:
{{ Form::open(array('url' => 'course_review', 'id'=>'clearForm'))}}
<div class="row">
<form role="form">
<div class="form-group">
<label for="course_comment">How can students succeed in this course?</label>
<textarea class="form-control" rows="5" id="course_comment" name="course_comment"></textarea>
</div>
</form>
</div>
<hr>
<div class="row">
<form role="form">
<div class="form-group">
<label for="assignments_comment">What kind of assignments and tests did this course have?</label>
<textarea class="form-control" rows="5" id="assignments_comment" name="assignments_comment"></textarea>
</div>
</form>
</div>
<hr>
<div class="row">
<form role="form">
<div class="form-group">
<label for="prerequisites_comment">What skills and prerequisites are required for this course?</label>
<textarea class="form-control" rows="5" id="prerequisites_comment" name="prerequisites_comment"></textarea>
</div>
</form>
</div>
<hr>
<div class="row">
<div class="col-xs-12">
<button type="submit" class="btn btn-info ladda-button" data-style="zoom-out" id="create_or_edit_button"><span class="ladda-label">
<span class="glyphicon glyphicon-plus"></span> Add this review</span>
</button>
</div>
</div>
</div>
{{ Form::close() }}
Here's a snipped from my Model:
$review = new Review();
$review->course_comment = Input::get('course_comment');
$review->assignments_comment = Input::get('assignments_comment');
$review->prerequisites_comment = Input::get('prerequisites_comment');
$review->save();
I was just wondering if anyone is aware of this or knows of a way around it? Thanks in advance.
The problem is you have nested forms.
{{ Form::open(...)}}
<form role="form">
...
</form>
<form role="form">
...
</form>
{{ Form::close() }}
You should get rid of all those <form role="form">...</form>. They are doing nothing and they break HTML standard. Your browser gets confused and only submits one of them at a time. Hence you get null in the not submited ones. You can have several forms in a page but they should not be nested.
From the html5 docs:
4.10.3 The form element
Content model:
Flow content, but with no form element descendants.
you are trying to insert a null value into the comment field of your table.
just make sure it isn't null.
It's pretty obvious that cause of this error is empty value of comment
$review = new Review();
$review->course_comment = Input::get('course_comment' ,false);
$review->assignments_comment = Input::get('assignments_comment', false);
$review->prerequisites_comment = Input::get('prerequisites_comment', false);
$review->save();
So... after a lot of pain, I just figured out the answer to my own question. Hopefully this will help someone else who makes the same mistake. In the code I originally posted, you will see I had wrapped each of my textareas in its own <form role="form"> wrapper:
<div class="row">
<form role="form">
<div class="form-group">
<label for="assignments_comment">What kind of assignments and tests did this course have?</label>
<textarea class="form-control" rows="5" id="assignments_comment" name="assignments_comment"></textarea>
</div>
</form>
</div>
<hr>
This was the source of the problem, as it prevented textareas #2 and #3 from getting read. I'm surprised the first textarea was getting read, in fact. Removing the extra wrappers allowed me to submit more than one textarea successfully. There should be only 1 wrapper for a form. I had copied and pasted this code directly from w3c so it took me a while to realize multiple copies of part of the code would cause me an error.
after many days of trying to get a previously working php form converted to submitting the variables inside a new div I realized that I'm missing something. Other posts show javascript, but Iv'e never used that before and don't understand the need. The new page draws correctly, but the php variables are not being received on the destination page.
HTML for the submit,
<form action="entrance2.php">
<div class="medium-12 columns m-b20"><h4 class="heading">Existing users log-in here :-</h4></div>
</div>
<div class="row">
<div class="user medium-12 columns text-center m-b15"><img src="images/user-img.png" alt=""/></div>
</div>
<div class="row">
<div class="medium-10 columns medium-offset-1"><label for="User Name"></label>
<input id="OwnerEmaili" type="text" placeholder="User Name" name="UserName"></div>
</div>
<div class="row">
<div class="medium-10 columns medium-offset-1"><label for="Password"></label>
<input id="OwnerPasswordi" type="password" placeholder="Password" name="Password"></div>
</div>
<div class="row">
<div class="medium-12 columns text-center"><button class="grd-button">Log In</button></div>
<input type="submit" id="save" name="save" value = "Submit"/>//simple submit for testing
<div class="grd-button1" onClick="document.forms['submit-form'].submit();"></div>
</form></div>
</div>
</div>
Receiving page,
<?php
$p_OwnerEmaili=$_POST["OwnerEmaili"];
$p_OwnerPasswordi=$_POST["OwnerPasswordi"];
echo "$p_OwnerEmaili;$p_OwnerPasswordi";
Only shows the ;.
Is javascript required to submit from inside a div?
You're accessing the wrong items.
You'll need to set your forms input name attributes to this if you want to access them the way you currently have in your php script:
<input id="OwnerEmaili" type="text" placeholder="User Name" name="OwnerEmaili">
And
<input id="OwnerPasswordi" type="password" placeholder="Password" name="OwnerPasswordi">
That will allow you to access them as you do in your PHP script.
You can always check what values have been sent to your php script by using var_dump() or print_r().
<?php print_r($_POST); ?>
Would've shown you that you had UserName & Password set instead of what you wanted.
As Ghost pointed out in the comments, your form will always send user input via GET if you dont specify a method in it. So set this in your form tag:
<form action="entrance2.php" method="post">
I'm making a tool to pull eve API data and I use a GET form to take the data and get access to the key ID and code to access the data. This then pulls the first character ID on the key and grabs all that character data.
for example the url is:
whatever.com/APIChecker/?keyID=123456&code=ABCDEFGHIJKL
I pull these variables out via the session variables that they create.
What I'm now trying to do is now have a for loop which puts up buttons for each character on the key so you can flick between characters, I'm trying and have tried get and post methods hidden in the button but can't seem to get my desired result. It seems to not be taking out the variable that i'm trying to pass and adding it into the $_SESSION array or the $_POST or the $_GET - i've tried print_r on all these variables but I can't get any output.
Here is my primary form thats on my main page:
<form method="get" action="APIChecker/" >
<legend> Submit an API Key</legend>
<div class="control-group">
<label class="control-label">Key ID:</label>
<div class="controls">
<input type="text"
class="input-small"
name="keyID""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Verification Code:</label>
<div class="controls">
<input type="text"
class="input-xxlarge"
name="vCode"
/>
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Submit API</button>
</div>
</div>
What I'm trying to do now is get another session variable from another page - which updates a variable and refreshes the page with the keyID and code unaltered.
As in:
whatever.com/APIChecker/?keyID=123456&code=ABCDEFGHIJKL **&charID=654321**
so $_SESSION['keyID'] = 123456
& $_SESSION['code'] = ABCDEFGHIJKL
& $_SESSION['charID'] = 654321
what I've tried is:
<form method="get" action="" >
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">
<input type="hidden"
name="charID"
value="$charID"
/>
</button>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Submit API</button>
</div>
</div>
</form>
You can't output PHP values directly in HTML like this: value="$charID"
Try this instead:
value="<?php echo $charID; ?>"
i got a form.
<form id="site-contact-form">
<div>
<div class="wrapper"><span>Ձեր անունը:</span>
<div class="bg">
<div>
<input type="text" class="input" name="contactname" id="contactname" />
</div>
</div>
</div>
<div class="wrapper"><span>Ձեր E-mail-ը:</span>
<div class="bg">
<div>
<input type="text" class="input" name="email" id="email" />
</div>
</div>
</div>
<div class="textarea_box"><span>Տեկստ:</span>
<div class="bg">
<div>
<textarea cols="1" rows="1" name="message" id="message"></textarea>
</div>
</div>
</div>
<div style="clear:both;"></div>
<button id="sub" name="submit">ուղարկել</button>
</div>
</form>
As you see i got no action on it, no method. But when im clicking on button, its refreshing the page (like when it have action) and adding to URL ?contactname=&email=&message=&submit= ... I never met this problem before, why it is sending variables? I dont have any php on page yet...
Beacause the default method is GET and the URL is the same of the page. Use:
<form method="POST" action="/reactor">
<!-- .... -->
</form>
Actually, the action property is mandatory.
Please correct the code with:
<form id="site-contact-form" method="post">
And the submitted values will not be displayed on the URL.
If you do not specify the form method, it will "get" by default.
This is happening here.
Change the type of button as button
<button id="sub" name="submit" type="button">ուղարկել</button>