Laravel UpdateOrCreate method returns empty values - php

I have three tables: books, editions, and listings.
I have one form where a user can select a book, then a book edition and all of the fields (title, author, year, publisher, edition year, etc.) fill in automatically. If the user selects "My book isn't on this list", then he has to fill in the fields himself. The fields related to the listings table have to be filled by the user himself in any case:
this is how the form looks like
I'm trying to use the Laravel UpdateOrCreate method on submit, so only the new information is added to the database:
public function store(Request $request) {
Book::UpdateOrCreate([
'id' => $request->get('id'),
],
[
'book_title' => $request->get('book_title'),
'book_author' => $request->get('book_author'),
'book_description' => $request->get('book_description'),
'book_year' => $request->get('book_year'),
'book_language' => $request->get('book_language'),
]);
Edition::UpdateOrCreate([
'id' => $request->get('eid'),
],
[
'book_id' => $request->get('id'),
'image_url' => $request->get('image_url'),
'publisher' => $request->get('publisher'),
'edition_year' => $request->get('edition_year'),
'pages' => $request->get('pages'),
'cover_type' => $request->get('cover_type'),
]);
$listing = new Listing();
$listing->user_id = $request->get('user_id');
$listing->edition_id = $request->get('eid');
$listing->listing_description = $request->get('listing_description');
$listing->price = $request->get('price');
$listing->condition = $request->get('condition');
$listing->shipping_type = $request->get('shipping_type');
$listing->image_url = $request->get('listing_image');
$listing->save();
return redirect()->route('new-listing')->with('message', 'Listing added succesfuly!');
}
This is what automatically fills the input fields (just regular inputs with name attributes such as book_title, book_author and the rest that are in my UpdateOrCreate method above.
<div class="row">
<?php
header('Content-Type: text/html; charset=utf8');
$servername = "localhost";
$username = "thriftyourbook-user";
$password = "123";
$dbname="thriftyourbook";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = new mysqli($servername, $username, $password, $dbname);
mysqli_set_charset($conn, "utf8");
$qu = "SELECT book_title,book_author,book_description,book_year,book_language,id FROM books ORDER BY book_title";
$res = $conn->query($qu);
$q = "SELECT e.image_url,e.publisher,e.edition_year,e.pages,e.cover_type,e.id,b.book_title FROM editions as e JOIN books as b ON e.book_id = b.id ORDER BY b.book_title";
$re = $conn->query($q);
?>
<div class="form-group col-6">
<label for="book">{{ __('l.selectbook') }}</label>
<select id="book" class="form-control" name="book" onchange="bookInfo()">
<option value="no">{{ __('l.onthislist') }}</option>
<?php
while($r = mysqli_fetch_row($res))
{
echo "<option value=\"yes\" data-id=\"$r[5]\" data-ttl=\"$r[0]\" data-auth=\"$r[1]\" data-desc=\"$r[2]\" data-yr=\"$r[3]\" data-lang=\"$r[4]\" value=\"$r[5]\"> $r[0] </option>";
}
?>
</select>
</div>
<div class="form-group col-6" id="edition-field-div">
<label for="edition">{{ __('l.selectedition') }}</label>
<select id="edition" class="form-control" onchange="editionInfo()">
<option value="no">{{ __('l.editionnotlist') }}</option>
<?php
while($r = mysqli_fetch_row($re))
{
echo "<option value=\"yes\" data-img=\"$r[0]\" data-pblshr=\"$r[1]\" data-eyr=\"$r[2]\" data-pg=\"$r[3]\" data-cov=\"$r[4]\" data-eid=\"$r[5]\" data-titl=\"$r[6]\" value=\"$r[5]\">
$r[6] ($r[1], $r[2], $r[3] pages, ";
if ($r[4] == 'HC') {
echo "Hardcover) </option>";
} elseif ($r[4] == 'PB') {
echo "Paperback) </option>";
}
}
?>
</select>
</div>
</div>
No errors are returned, but every time I submit the form, every field related to the books or editions table becomes empty. Only the listing information is filled correctly.
Thanks in advance for any help! :)

Related

How to get multiple values from checkbox

I'm using Laravel 8 framework.
Using a query to get values from the table in and display it in the checkbox, but when I select more than one it just displays single, not multiple.
This is Blade PHP code with query.
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Students:</strong>
<div style="margin-top: 5px" >
<?php $conn = new mysqli('localhost', 'root', '', 'rp') or die ('Cannot connect to db');
$result = $conn->query("select users.id, users.name from users, model_has_roles where model_has_roles.model_id=users.id and model_has_roles.role_id=14;
");
echo "<html>";
echo "<body>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['name'];
echo '<form><input type=checkbox name="student_id[]" value="'.$id.'">'.$name.'</form>'; }
//echo "</select>";
echo "</body>";
echo "</html>";?>
He is my function code in Controller
public function update(Request $request, Ticket $ticket){
request()->validate([
'gpname' => 'required',
'detail' => 'required',
'semester' => 'required',
'gender' => 'required',
// 'status',
// 'Assigned',
]);
$users= Auth::user();
$rr= $users->roles->pluck('name')->toArray();
// dd($users->id);
// $data= $request->all();
//$ticket = new Ticket;
if($rr[0]=='Admin'){
$data= $request->all();
//dd($data['Assigned']) ;
$ticket->gpname=$data['gpname'];
$ticket->detail=$data['detail'];
$ticket->semester=$data['semester'];
$ticket->gender=$data['gender'];
//dd("hhh");
$student_id = array("student_id");
if(isset($_POST['submit'])){
if(!empty($_POST['student_id'])){
$student_id = $_POST['student_id'];
foreach($student_id as $id){
// echo $id.'<br/>';
dd($data['student_id']);
}
}
}
dd($data['student_id']);
//dd( $data['student_id[]']);
//$ticket->studentnames=$users->empid;
$ticket->user_id=$users->id;
//$ticket->Assigned=$data['Assigned'];
$ticket->save();
and as you see if I make dd($data['student_id']); as a comment it's never going to the previous one inside foreach()
How I can get multiple values from the checkbox?
dd(); is killing the loop and returning only the first value you should echo your results instead of dd(); them or use.
if(!empty($_POST['student_id'])){
$student_id = $_POST['student_id'];
$array_test = []
foreach($student_id as $id){
if($id == $data['student_id']){
array_push($id, $array_test)
}
}
dd($array_test);
}
Since i don't know what are you trying to do so i will drop the second thought
if(!empty($_POST['student_id'])){
$student_id = $_POST['student_id'];
$array_test = []
foreach($student_id as $id){
array_push($id, $array_test)
}
dd($array_test);
}

Adding values into database with the use of primary and foreign keys

Im trying to add the chosen values from my drop down menu into my database by using primary and foreign keys. Im trying to figure out how when the customer selects the drop down box option, the VALUE is entered into sql, which is the same number as room table primary. Would i somehow post the drop down box select id = rooID? Can anyone please help me with this.
Below is my makeabookingphp code:
<!DOCTYPE HTML>
<html><head><title>Make a Booking</title> </head>
<body>
<?php
//function to clean input but not validate type and content
function cleanInput($data) {
return htmlspecialchars(stripslashes(trim($data)));
}
//the data was sent using a formtherefore we use the $_POST instead of $_GET
//check if we are saving data first by checking if the submit button exists in the array
if (isset($_POST['submit']) and !empty($_POST['submit']) and ($_POST['submit'] == 'Book')) {
//if ($_SERVER["REQUEST_METHOD"] == "POST") { //alternative simpler POST test
include "config.php"; //load in any variables
$DBC = mysqli_connect("127.0.0.1", DBUSER, DBPASSWORD, DBDATABASE);
//prepare a query and send it to the server
$query = 'SELECT room.roomID, room.roomname, room.roomtype, booking.bookingID, booking.roomID, booking.roomname
FROM room
INNER JOIN booking
ON room.roomID = booking.roomID';
if (mysqli_connect_errno()) {
echo "Error: Unable to connect to MySQL. ".mysqli_connect_error() ;
exit; //stop processing the page further
};
//validate incoming data - only the first field is done for you in this example - rest is up to you do
$error = 0; //clear our error flag
$msg = 'Error: ';
if (isset($_POST['roomname']) and !empty($_POST['roomname']) and is_string($_POST['roomname'])) {
$fn = cleanInput($_POST['roomname']);
$roomname = (strlen($fn)>50)?substr($fn,1,50):$fn;
//check length and clip if too big
//we would also do context checking here for contents, etc
} else {
$error++; //bump the error flag
$msg .= 'Invalid'; //append eror message
$roomname = '';
}
$roomname = cleanInput($_POST['roomname']);
$checkindate = cleanInput($_POST['checkindate']);
$checkoutdate = cleanInput($_POST['checkoutdate']);
$contactnumber = cleanInput($_POST['contactnumber']);
$bookingextras = cleanInput($_POST['bookingextras']);
//save the customer data if the error flag is still clear
if ($error == 0) {
$query1 = "INSERT INTO booking (roomname, checkindate, checkoutdate, contactnumber, bookingextras) VALUES (?,?,?,?,?)";
$stmt = mysqli_prepare($DBC,$query1); //prepare the query
mysqli_stmt_bind_param($stmt,'sssss', $roomname, $checkindate, $checkoutdate,$contactnumber,$bookingextras);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
echo "<h2>Booking saved</h2>";
} else {
echo "<h2>$msg</h2>".PHP_EOL;
}
mysqli_close($DBC); //close the connection once done
}
?>
<h1>Make A Booking</h1>
<h2><a href='menu.php'>[Return to the main page]</a></h2>
<form method = "post" action = "processbooking.php">
<p>
<label for = "rooID">Room: (name, type, beds): </label>
<select id = "rooID" name = "rooID" required>
<option name = "" value = "" disabled selected>Select</option>
<option name = "1" value = "1">Kellie, S, 5</option>
<option name = "2" value = "2">Herman, D, 2</option>
<option name = "3" value = "3">Scarlett, D, 2</option>
<option name = "4" value = "4">Jelani, S, 5</option>
<option name = "5" value = "5">Sonya, S, 4</option>
<option name = "6" value = "6">Miranda, S, 2</option>
<option name = "7" value = "7">Helen, S, 2</option>
<option name = "8" value = "8">Octavia, D, 3</option>
<option name = "9" value = "9">Bernard, D, 5</option>
<option name = "10" value = "10">Dacey, D, 1</option>
</select>
</p>
<p>
<label for="checkindate">Check in date: </label>
<input type="date" name="checkindate"required>
</p>
<p>
<label for="checkout">Check out date: </label>
<input type="date" name="checkoutdate"required>
</p>
<p>
<label for="contactnumber">Contact number: </label>
<input type="tel" name="contactnumber" required>
</p>
<p>
<label for="bookingextras">Booking extras: </label>
<input type="text" name="bookingextras" size="100" minlength="5" maxlength="200" required>
</p>
<input type="submit" name="submit" value="Book">
[Cancel]
</form>
</body>
</html>
Room table:
roomID (PK)
roomname
description
roomtype
beds
Booking table:
bookingID (PK)
roomname
checkindate
checkoutdate
contactnumber
bookingextras
roomID (FK)
I've rewritten your code - hope it helps
<?php
//function to clean input but not validate type and content
function cleanInput($data) {
return htmlspecialchars(stripslashes(trim($data)));
}
// STEP 1 -test if form has been submitted
if (isset($_POST['submit']) && ($_POST['submit'] == 'Book')) {
// STEP 2. process the inputs
// get inputs - clean or set a default if not supplied
$roomID = isset( $_POST['rooID'] ) ? cleanInput($_POST['rooID']) : -1;
$checkindate = isset( $_POST['checkindate'] ) ? cleanInput($_POST['checkindate']) : "";
$checkoutdate = isset( $_POST['checkoutdate'] ) ? cleanInput($_POST['checkoutdate']) : "";
$contactnumber = isset( $_POST['contactnumber'] ) ? cleanInput($_POST['contactnumber']) : "";
$bookingextras = isset( $_POST['bookingextras'] ) ? cleanInput($_POST['bookingextras']) : "";
// STEP 3 validate/clean the inputs (don't trust anything coming in)
// validate all the inputs according to business rules
$error = 0;
$errMsg = [];
if( roomID == -1 ) {
$error++;
$errMsg[] = "Room not selected";
}
// do all other inputs
// proceed if no errors
if( $error != 0 ) {
// STEP 4 connect to the database
// connect to the database
include "config.php"; //load in any variables
$DBC = mysqli_connect("127.0.0.1", DBUSER, DBPASSWORD, DBDATABASE);
if (mysqli_connect_errno()) {
echo "Error: Unable to connect to MySQL. ".mysqli_connect_error() ;
exit; //stop processing the page further
};
// STEP 5 check if the roomID is valid
// if roomID is valid then continue
$query = "SELECT roomID FROM roomTable WHERE roomID=".$roomID;
$result = $DBC->query( $query ); // ???? check the syntax of this line
if( $result ) { // something returned ???? check syntax
// STEP 5 update the relevant table(s)
$query1 = "INSERT INTO booking (roomID, checkindate, checkoutdate, contactnumber, bookingextras) VALUES (?,?,?,?,?)";
$stmt = mysqli_prepare($DBC,$query1); //prepare the query
mysqli_stmt_bind_param($stmt,'issss', $roomID, $checkindate, $checkoutdate,$contactnumber,$bookingextras);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
echo "<h2>Booking saved</h2>";
}
} else {
// STEP 3.1 show user messages of what went wrong
echo $errMsg;
}
mysqli_close($DBC); //close the connection once done
}
?>

Data not being inserted mysql

I am building a custom CMS for myself and its going great but for some reason the system is not inserting a certain field called categories. I have a table called categories and i am able to insert those categories with no problems.
On my addnewpost.php page I have this form field that lets me select an added Category..
<select name="Category" id="categorytitle" class="form-control">
<?php
$sql = "SELECT id,title FROM category";
$stmt = $conn->query($sql);
while ($DataRows = $stmt->fetch()){
$id = $DataRows["id"];
$CategoryName = $DataRows["title"];
?>
<option value=""><?php echo $CategoryName; ?></option>
<?php } ?>
</select>
above all that I have this to inset the data into the database in a table called posts...
<?php
if(isset($_POST["Submit"])){
$posttitle = $_POST["posttitle"];
$Category = $_POST["Category"];
$image = $_FILES["image"]["name"];
$target = "../uploads/".basename($_FILES["image"]["name"]);
$posttext = $_POST["postdescription"];
$admin = "phillip";
date_default_timezone_set("Europe/London");
$CurrentTime=time();
$DateTime=strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
if(empty($posttitle)){
$_SESSION["ErrorMessage"] = "Post title cannot be empty";
redirect_to("addnewpost.php");
} elseif (strlen($posttitle)<10){
$_SESSION["ErrorMessage"] = "Post title should be greater than 10 characters";
redirect_to("addnewpost.php");
} else {
//All is good insert into the database
$sql = "INSERT INTO posts(datetime,title,category,author,image,post)";
$sql .= "VALUES(:dateTime,:postTitle,:categoryName,:adminName,:imageName,:postDescription)";
$stmt = $conn->prepare($sql);
$stmt->bindValue(':dateTime',$DateTime);
$stmt->bindValue(':postTitle',$posttitle);
$stmt->bindValue(':categoryName',$Category);
$stmt->bindValue(':adminName',$admin);
$stmt->bindValue(':imageName',$image);
$stmt->bindValue(':postDescription',$posttext);
$Execute=$stmt->execute();
move_uploaded_file($_FILES["image"]["tmp_name"],$target);
if($Execute){
$_SESSION["SuccessMessage"]="Post with id : ".$conn->lastInsertId()." Added Successfully";
redirect_to("addnewpost.php");
} else {
$_SESSION["ErrorMessage"]="Something went wrong. Try again";
redirect_to("addnewpost.php");
}
}
}
?>
Here is a screengrab showing that the category fields are empty. I do have display errors enabled but none are showing up. Any thoughts appreciated...
Thank you Nigel and Felippe. I just took out the option value so it's just this instead...
<option><?php echo $CategoryName; ?></option>
That's made it all work perfectly. Been looking at this for hours as well.
Thank you both.
<select name="Category" id="categorytitle" class="form-control">
<?php
$sql = "SELECT id,title FROM category";
$stmt = $conn->query($sql);
while ($DataRows = $stmt->fetch()){
$id = $DataRows["id"];
$CategoryName = $DataRows["title"];
?>
<option value="<?php echo $CategoryName; ?>"><?php echo $CategoryName; ?></option>
<?php } ?>
</select>
This is more like it

Inserting to DB via foreach

So I have these code below. The first one is a loop which echos all the requirements came from the database and write it in a checkbox form. So what I did is named it in an array form which is requirementItems[].
The next code is all about checking and inserting. If the checkbox is checked, the $state variable will have the value of 1 else, 0.
My problem is that, when I tried to leave a checkbox unchecked, it doesn't record into the database. But if it is checked, it successfully insert the data.
FIRST
<?php
$query = $db->prepare("SELECT * FROM tbl_requirements WHERE reqStatus = 1");
$query->execute();
while($result = $query->fetch(PDO::FETCH_ASSOC)){
$requirementID = $result['reqID'];
$requirementName = $result['reqName'];
echo "
<div class='row'>
<div class='col-md-5'>
<div class='checkbox'>
<label>
<input type='checkbox'value='$requirementID' title='$requirementID' name='requirementItems[]'>
$requirementName
</label>
</div>
</div>
</div>
";
}
?>
SECOND
<?php
if(isset($_POST['passSubmit'])){
$rsrvReqID = trim($_POST['reqID']);
$customerID = $_GET['cusID'];
$reservedProperty = $_GET['propertyID'];
$paymentID = $_GET['paymentID'];
$requirementItems = $_POST['requirementItems'];
foreach($requirementItems as $reqItem) {
$state = (isset($reqItem)) ? 1 : 0;
$query = $db->prepare("INSERT INTO tbl_rsrvrequirements (rsrvReqID, customerID, propertyID, paymentID, reqID, rsrvReqState)
VALUES (:rsrvReqID, :customerID, :reservedProperty, :paymentID, :reqID, :state)");
$query->execute(array(
":rsrvReqID" => $rsrvReqID,
":customerID" => $customerID,
":reservedProperty" => $reservedProperty,
":paymentID" => $paymentID,
":reqID" => $reqItem,
":state" => $state
));
$reqNEW = str_replace('REQ','',$rsrvReqID);
$requireID = str_pad(trim($reqNEW) +2,7,0,STR_PAD_LEFT);
$rsrvReqID = 'REQ'.$requireID;
}//foreach()
echo"<meta http-equiv='refresh' content='0; url=summary.php?reqID=$rsrvReqID' >";
}//if(isset())
?>

Textarea not reading any input

The textarea is not reading any input that is typed into the box. Initially, I was using PHP to check if the textarea was empty, and was recieveing an error there. So I removed that check, to see if it was php that was causing the issue, and added the required="required" attribute to the textarea tag, and even that is coming back with Please fill out this field. I am not quite sure where I am going wrong with my code, I had it working previously, then all of a sudden it stopped working, and I am completely confused as to why. I also looked at various other posts about the textarea not submitting, and ensured that I was checking the post with the name, not the ID; and making sure the textarea was submitting to the same form as the submit button. I have also tried it without specifying the form on the textarea tag.
HTML Code:
<form action="" method="post" id="CreateTopicForm">
<input type="hidden" name="create-topic" />
<span class="secondary radius label"><strong>Title</strong></span>
<input type="text" name="title" id="title" />
<span class="secondary radius label"><strong>Message</strong></span>
<textarea name="content" id="content" required="required" form="CreateTopicForm"></textarea>
<?php if($_SESSION['user']['account_type'] >= 3): ?>
<span class="secondary radius label"><strong>Sticky Topic</strong></span>
<input type="checkbox" name="sticky" /><br />
<?php endif ?>
<input type="submit" value="Post Topic" class="topic-post" />
</form>
PHP Code:
/* Retrieve necessary variables */
$fid = $_GET['fid'];
/* Get Forum Information */
$query = "SELECT * FROM bkg_forums where forum_id = :id";
$query_params = array(
':id' => $fid
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch(PDOException $e) {
$error[] = $pdoerror;
}
$forum = $stmt->fetchAll();
/* Begin the database upload */
if(!empty($_POST)){ /* Plan to change to if($_REQUEST['submit']) */
/* Check if data was actually submitted */
$db->beginTransaction();
/* DO SOME ERROR CHECKING. MAKE SURE FIELDS ARE NOT EMPTY. */
if(empty($_POST['title'])){
$error[] = "Sorry! You must enter a title!";
}
/* Previously had a check if $_POST['content'] */
/* GENERATE SOME VARIABLES NEEDED TO INSERT INTO TABLES. ACCOUNT_TYPE IS TEMPORARY*/
if($_SESSION['user']['account_type'] == 0) {
$account_type = "Normal";
$color = "white";
} elseif($_SESSION['user']['account_type'] == 1) {
$account_type = "Donator";
$color = "#F4FA58";
} elseif($_SESSION['user']['account_type'] == 2) {
$account_type = "Moderator";
$color = "#2EFE2E";
} elseif($_SESSION['user']['account_type'] == 3) {
$account_type = "Community Manager";
$color = "#0000FF";
} elseif($_SESSION['user']['account_type'] == 4) {
$account_type = "Administrator";
$color = "#DF0101";
}
if(isset($_POST['sticky'])){
$sticky = 1;
} else {
$sticky = 0;
}
if(!isset($error)){
/* INSERT INTO TOPICS TABLE */
$query = "INSERT INTO bkg_topics (
forum_id,
icon_id,
topic_approved,
topic_title,
topic_text,
topic_poster_id,
topic_poster,
topic_poster_color,
topic_post_time,
topic_status,
topic_type
) VALUES (
:forumid,
:iconid,
:topicapproved,
:topictitle,
:topictext,
:topicposter_id,
:topicposter,
:topicposter_color,
:topicpost_time,
:topicstatus,
:topictype
)";
$query_params = array(
':forumid' => $fid,
':iconid' => 1,
':topicapproved' => 1,
':topictitle' => $_POST['title'],
':topictext' => $_POST['content'],
':topicposter_id' => $_SESSION['user']['id'],
':topicposter' => $_SESSION['user']['displayname'],
':topicposter_color' => $color,
':topicpost_time' => time(),
':topicstatus' => 0,
':topictype' => $sticky
);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$lastid = $db->lastInsertId();
/* Retrieve the last id of a topic, used to generate some links. */
/* UPDATE FORUM TABLE */
$query = "UPDATE bkg_forums SET
`forum_last_post_id` = :lastpostid,
`forum_last_post_topic_id` = :lastposttopicid,
`forum_last_post_title` = :lastposttitle,
`forum_last_poster_id` = :lastposterid,
`forum_last_post_time` = :lastposttime,
`forum_last_poster_name` = :lastpostername,
`forum_last_poster_color` = :lastpostercolor
WHERE `forum_id` = :forumid
";
$query_params = array(
':lastpostid' => null,
':lastposttopicid' => $lastid,
':lastposttitle' => $_POST['title'],
':lastposterid' => $_SESSION['user']['id'],
':lastposttime' => time(),
':lastpostername' => $_SESSION['user']['displayname'],
':lastpostercolor' => $color,
':forumid' => $fid
);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
if($fid == 13){
$query = "INSERT INTO updates (
title,
content,
`date`,
`user`,
`topic_id`
) VALUES (
:title,
:content,
:date_posted,
:user_posted,
:topic_id
)";
$query_params = array(
':title' => $_POST['title'],
':content' => $_POST['content'],
':date_posted' => time(),
':user_posted' => $_SESSION['user']['displayname'],
':topic_id' => $lastid
);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
try {
$db->commit();
$post_ok = 1;
} catch(PDOException $e) {
$erroradmin[] = $e->getMessage();
$db->rollback();
}
if(isset($post_ok)): ?>
<script>
location.href = "http://www.boundlessknights.com?viewtopic&fid=<?php echo $fid; ?>&tid=<?php echo $lastid; ?>";
</script>
<?php else: ?>
<?php $error[] = "Your topic did not post."; ?>
<?php endif; ?>
<?php
}
}
?>
Questions I looked at:
Form Post Not Reading Any Value
Cannot Get the Value of a Textarea via Post Method
Textarea Not Posting with Form
Textarea Returns Empty Value in PHP Post
TinyMCE does not keep the underlying textarea in sync at all times. Normally, when you post the form, TinyMCE will update the textarea before the form is posted but the process seems to be stopped by the required attribute. You can use the following API call to force TinyMCE to update the textarea:
tinymce.triggerSave();
This will force TinyMCE to update the textarea when its called. You can either:
Do this in the onsubmit event of the form
Do this in the TinyMCE init:
tinymce.init({
selector: "textarea",
setup: function (editor) {
editor.on('change', function () {
tinymce.triggerSave();
});
}
});
Your page is using TinyMCE editor. It is giving the following error in the console: An invalid form control with name='content' is not focusable.
Fixing that will fix your problem.
Hmmm, did you try to remove this "form" attribute from your Textarea ?
<textarea name="content" id="content" required></textarea>
Tell us what it do when u try.
Change this
<textarea name="content" id="content" required="required" form="CreateTopicForm"></textarea>
to this
<textarea name="content" id="content" required="required" ></textarea>
You might not be able to post anything because you've NOT specified the action attribute of your form.
<form action="" method="post" id="CreateTopicForm">
Set it to the name of the php file (with the proper path to the file),
and it should work.
Note: To make sure the the $_POST array contains your form submitted values, do a var_dump($_POST).

Categories