Can't get TextArea value in the Request, always empty - javascript

The Result of echo is always:
"Course Description Value is: ...Thanks"
with an empty value for Course_Desc
<?
if (isset($_REQUEST["saveEdites"])) {
$id = $_REQUEST['ProtocolID'];
$Course_Desc = $_REQUEST['Course_Descr'];
$Course_Desc = trim($Course_Desc);
$Course_Desc = stripslashes($Course_Desc);
$Course_Desc = htmlspecialchars($Course_Desc);
echo "Course Description Value is : ".$Course_Desc." ...Thanks";
}
?>
<form method="post" name="implantForm">
<table >
<input type="hidden" name="ProtocolID" id="Protocol">
<tr align="Left">
<td>
<label style="color:#ff6600;font-weight:bold">
Name
</label>
</td>
<td>
<label id="formLbl"></label>
</td>
</tr>
<tr align="Left" style="color:#ff6600;font-weight:bold">
<td>Protocol </td>
<td>
<textarea id="formTXT" rows="4" cols="50" name="Course_Descr" form="implantForm"></textarea>
</td>
</tr>
</table>
<table>
<tr align="center" >
<td>
<input type="submit" name="saveEdites" value="Save changes">
</td>
</tr>
</table>
</form>
Update
I was declaring the form="implantForm"
so I removed it and everything is working now

Please put <form> tag in your program and remove form=implantForm from <textarea>.Here I made some changes in your code then I get textarea value as output
<form>
<table >
<input type="hidden" name="ProtocolID" id="Protocol">
<tr align="Left">
<td>
<label style="color:#ff6600;font-weight:bold">
Name
</label>
</td>
<td>
<label id="formLbl"></label>
</td>
</tr>
<tr align="Left" style="color:#ff6600;font-weight:bold">
<td>Protocol </td>
<td>
<textarea id="formTXT" rows="4" cols="50" name="Course_Descr" ></textarea>
</td>
</tr>
</table>
<table>
<tr align="center" >
<td>
<input type="submit" name="saveEdites" value="Save changes">
</td>
</tr>
</table>
</form>
<?php
if (isset($_REQUEST["saveEdites"])) {
$id = $_REQUEST['ProtocolID'];
$Course_Desc = $_REQUEST['Course_Descr'];
$Course_Desc = trim($Course_Desc);
$Course_Desc = stripslashes($Course_Desc);
$Course_Desc = htmlspecialchars($Course_Desc);
echo "Course Description Value is : ".$Course_Desc." ...Thanks";
}
?>

form="implantForm"
that what was confusing the browser
textarea value was not even sent in the request .removed it and everything is working now

Please remove form="implantForm" from textarea, then it will work.

Related

Copy contents of textarea to input

In this table each row has a text area wd. I want to copy the contents of #wd to #wdi.
That is the user types in wd and the wdi value becomes wd value.
I am assuming I need to use onkeyup function but not sure.
<tbody>
while(rs1.next())
{ %>
<tr>
<td>
<textarea id="wd" rows="4" cols="50" name="wd" ></textarea>
</td>
<td>
<form method='POST' action="actonissue.jsp" id='form1'>
<input id='issue_id' name ='issue_id' value='<%=rs1.getString(1)%>' class='disable' type="hidden">
<input id='wdi' name ='wdi' class='disable' type="hidden" >
<button type="submit" >Resolve Issue</button> </form>
</td>
</tr>
<% } %>
</tbody>
You can use keyup function as, note that you need get #wdi within each tr.
$('[name ="wd"]').keyup(function(){
//console.log($(this).val())
$(this).closest("tr").find("#wdi").val($(this).val());
})
$('[name ="wd"]').keyup(function(){
//console.log($(this).val())
$(this).closest("tr").find("#wdi").val($(this).val());
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>
<textarea id="wd" rows="4" cols="50" name="wd" ></textarea>
</td>
<td>
<form method='POST' action="actonissue.jsp" id='form1'>
<input id='issue_id' name ='issue_id' value='test1' class='disable' type="hidden">
<input id='wdi' name ='wdi' class='disable' type="hidden" >
<button type="submit" >Resolve Issue</button> </form>
</td>
</tr>
<tr>
<td>
<textarea id="wd" rows="4" cols="50" name="wd" ></textarea>
</td>
<td>
<form method='POST' action="actonissue.jsp" id='form1'>
<input id='issue_id' name ='issue_id' value='test2' class='disable' type="hidden">
<input id='wdi' name ='wdi' class='disable' type="hidden" >
<button type="submit" >Resolve Issue</button> </form>
</td>
</tr>
</tbody>
</table>

javascript: Auto calculate price upon entering quantity in input box

In my program I am trying to auto calculate total price when user enter quantity in input box. For that I performed below script. but due to some error my script doesn't working as per expectation and when I enter quantity, total price doesn't get updated. Can anyone tell me what's wrong in my code. I want to perform this script without jquery.
code:
<!DOCTYPE html>
<html>
<head>
<title>form</title>
</head>
<body>
<form action="" method="POST" name="myForm" id="myForm">
<table bgcolor="pink" align="center" border="2px">
<tbody>
<tr>
<th> Category </th>
<th> Description </th>
<th> Unit Price </th>
<th> Quantity </th>
<th> Total Price</th>
</tr>
<tr>
<td rowspan="2">1</td>
<td> Paneer </td>
<td name="priceQ1"> $10 </td>
<td> <input type="text" size="4" id="q1" name="qty1" onkeyup="calculate()"> </td>
<td> <input type="text" id="total1" name="total1"> </td>
</tr>
<tr>
<td> Rice </td>
<td name="priceQ2"> $30 </td>
<td> <input type="text" size="4" id="q2" name="qty2" onkeyup="calculate()"> </td>
<td> <input type="text" id="total2" name="total2"> </td>
</tr>
<tr align="right">
<td colspan="4"> Subtotal $ </td>
<td> <input type="text" id="sub_total" name="sub_total"> </td>
</tr>
<tr>
<td rowspan="2">2</td>
<td> Chicken Palak </td>
<td name="priceQ3"> $20 </td>
<td> <input type="text" size="4" id="q3" name="qty3" onkeyup="calculate()"> </td>
<td> <input type="text" id="total3" name="total3"> </td>
</tr>
<tr>
<td> Aloo Tikki </td>
<td name="priceQ4 "> $14 </td>
<td> <input type="text" size="4" id="q4" name="qty4" onkeyup="calculate()"> </td>
<td> <input type="text" id="total4" name="total4"> </td>
</tr>
<tr align="right">
<td colspan="4"> Subtotal $ </td>
<td> <input type="text" id="sub_total2" name="sub_total2"> </td>
</tr>
</tbody>
</table>
<p align="center">
<input type="submit" value="Submit">
<input type="reset">
</p>
</form>
<script>
function calculate() {
var f = document.forms['myForm'];
for(var i=0;i<4;i++){
var qty = document.getElementByName('qty'+i);
document.getElementById('total'+i).value = newValue;
}
}
</script>
</body>
</html>
There is no document.getElementsById, you should name your different quantities and total price fields with distinct names and traverse thru them using document.getElementById('qty'+i);

How to validate password with atleast one numeric, one Uppercase letter and 6-20 characters?

I have added this script to my form and its working with alpha numeric.The problem is when i click on wrong format on click function it will updated the data in database with submit button.How can i block? I need to update data with correct alert function.
function CheckPassword(inputtxt) {
var passw = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/;
if (inputtxt.value.match(passw)) {
alert('Congratulations You have successfully changed your password!..Plz Logout and signin again.');
return true;
} else {
alert('Wrong Format...!')
return false;
}
}
<script src="check-password-2.js"></script>
<?php
if(isset($_POST['submit']) )
{
$password = $_POST['newpassword'];
$sql = mysql_query("UPDATE tbl_login SET str_password='$password',status='1' where str_username='$user'");
}
?>
<body onload='document.form1.newpassword.focus()'>
<form name="form1" action="" method="post" id="form1" onClick="CheckPassword(document.form1.newpassword)">
<table width="388" align="center"></br>
</<tr>
<td align="right">Enter Username</td>
<td align="center">
<input type="username" name="username" value="<?php echo ucwords($_SESSION['username']); ?> " class="TxtBox" disabled="disabled" />
</td>
</tr>
<h5>Input Password and Submit [6 to 20 characters which contain at least one numeric digit, one uppercase and one lowercase letter]</h5>
<tr>
<td align="right">New Password</td>
<td align="center">
<input type="password" name="newpassword" class="TxtBox" />
</td>
</tr>
<tr>
<td align="center">
<div align="center">
<input type="submit" name="submit" value="submit" />
</div>
</td>
</tr>
</table>
</form>
</body>
Firstly you need to use the onsubmit attribute of the form, not onclick. Secondly, you need to use a return statement within the attribute to provide the value returned by the function to the event handler to prevent or allow the form submission. You also need to fix several errors in your HTML. Try this:
<body onload='document.form1.newpassword.focus()'>
<form name="form1" action="" method="post" id="form1" onsubmit="return CheckPassword(document.form1.newpassword)">
<table width="388" align="center"></br>
<tr>
<td align="right">Enter Username</td>
<td align="center">
<input type="username" name="username" value="<?php echo ucwords($_SESSION['username']); ?> " class="TxtBox" disabled="disabled" />
</td>
</tr>
<tr>
<td colspan="2">
<h5>Input Password and Submit [6 to 20 characters which contain at least one numeric digit, one uppercase and one lowercase letter]</h5>
</td>
</tr>
<tr>
<td align="right">New Password</td>
<td align="center">
<input type="password" name="newpassword" class="TxtBox" />
</td>
</tr>
<tr>
<td align="center">
<div align="center">
<input type="submit" name="submit" value="submit" />
</div>
</td>
</tr>
</table>
</form>
</body>

how to insert multiple rows from array values with input

I have my table named i_table with columns:
id name req_qty req_date rcv_qty rec_date
1 metal 1 2014-03-04
2 spring 5 2014-03-04
in my html/php:
<form action="insert.php" method="post">
<?php $resource2=mysql_query("SELECT * FROM i_table",$con);
while($result2=mysql_fetch_array($resource2))
{
?>
<table>
<tr>
<td>
<input type="text" name="id" value="<?php echo $result2['id'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="name" value="<?php echo $result2['name'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="rcv[]" value="" />
</td>
</tr>
<tr>
<td>
<input type="date" name="rcv_date[]" value="" />
</td>
</tr>
</table>
<?php };?>
</form>
how can I insert in multiple arrays from an input according to their unique ID from db? pls help me here... huhu
In your form, add the id as the key -
<form action="insert.php" method="post">
<?php $resource2=mysql_query("SELECT * FROM i_table",$con);
while($result2=mysql_fetch_array($resource2))
{
?>
<table>
<tr>
<td>
<input type="text" name="id[<?php echo $result2['id'];?>]" value="<?php echo $result2['id'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="name[<?php echo $result2['id'];?>]" value="<?php echo $result2['name'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="rcv[<?php echo $result2['id'];?>]" value="" />
</td>
</tr>
<tr>
<td>
<input type="date" name="rcv_date[<?php echo $result2['id'];?>]" value="" />
</td>
</tr>
</table>
<?php };?>
</form>
Then on your insert.php where you post your form, get the id in your foreach -
<?php
if(isset($_POST['id'])){
foreach($_POST['id'] as $id=>$value){
$sql = "UPDATE `i_table` SET `name` = '".$_POST['name'][$id]."', `rcv_qty` = '".$_POST['rcv'][$id]."', `rec_date` = '".$_POST['name'][$id]."' WHERE `id` = ".$id."";
mysql_query($sql,$con);
}
}
?>
note the foreach() is just an example. You will want to sanitize your data before inserting/updating to prevent sql injection. see How can I prevent SQL injection in PHP?

how to move previous page and show values in fields?

i make two web page,i want to get data from first page on second page,if user click edit message then move first page and show the entered data of user,here is my code:
first.php
<h1>Compose Message</h1>
<script type="text/javascript" src="<?=MURL?>/js/ckeditor/ckeditor.js"></script>
<script src="//ticket_inspector_new.com/js/tooltip.js" type="text/javascript"> </script>
<form action="" method="post" id="form" enctype="multipart/form-data">
<table class="form">
<tr class="heading">
<th style="width: 25%;">Recipients</th>
<th style="width: 75%;"> </th>
</tr>
<tr>
<td>
<label for="campaigns">Campaigns</label>
</td>
<td>
<select name="events[]" multiple size="10" >
<?
$select = sprintf ("SELECT event_id,event_name
FROM `events`
WHERE (`user_id` = '%s') order by event_name",
$GLOBALS ['mysqli']->real_escape_string ($_SESSION['user_id']));
$res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__);
if ($res->num_rows > 0)
{
while($row = $res->fetch_assoc ())
{
?>
<option value="<?=$row['event_id']?>"><?=$row['event_name']?></option>
<?
}
}
?>
</select>
</td>
</tr>
<tr>
<td style="padding-left:95px;">
<label for="fromdate">Registrants From</label>
</td>
<td style="padding-left:10px;">
<input name="fromdate" type="text" value="" class="calendar time" id="fromdate" size="30" />
<label for="todate">To</label>
<input name="todate" type="text" value="" class="calendar time" id="todate" size="30" />
</td>
</tr>
<tr>
<td>
<label for="upload">Upload CSV</label>
<span class="helptip">
Select CSV file for upload.
</span>
</td>
<td>
<input name="uploadcsv" type="file" />
</td>
</tr>
<tr class="heading">
<th style="width: 25%;">Message</th>
<th style="width: 75%;"> </th>
</tr>
<tr>
<td>
<label for="description">Description(optional)</label>
</td>
<td>
<input name="description" type="text" value="" id="description" size="35" />
</td>
</tr>
<tr>
<td>
<label for="subject">Subject</label>
</td>
<td>
<input name="subject" type="text" value="" id="subject" size="35" />
</td>
</tr>
<tr>
<td>
<label for="fromname">From Name</label>
</td>
<td>
<input name="fromname" type="text" value="" id="fromname" size="27" />
</td>
</tr>
<tr>
<td>
<label for="replyto">Reply To</label>
</td>
<td>
<input name="replyto" type="text" value="" id="replyto" size="27" />
</td>
</tr>
<tr>
<td>
<label for="senddatetime">Send Date/Time</label>
<span class="helptip">
Click the calender to select the date you wish ans select time zone from select box.
</span>
</td>
<td>
<input name="senddatetime" type="text" value="" class="calendar time" id="senddatetime" size="30" />
<select name="timezone" id="timezone">
<option value="Pacific/Honolulu">Hawaii-Aleutian Time (Honolulu, no DST)
</option><option value="America/Anchorage">Alaska Time (Anchorage)</option><option value="America/Los_Angeles"
selected="selected">Pacific Time (Los Angeles)</option><option value="America/Denver">Mountain Time (Denver)</option><option
value="America/Phoenix">Mountain Time (Phoenix, no DST)</option><option value="America/Chicago">Central Time (Chicago)
</option><option value="America/Regina">Central Time (Regina, no DST)</option><option value="America/New_York">Eastern Time
(New York)</option><option value="America/Halifax">Atlantic Time (Halifax)</option>
</select>
<script>
var list = document.getElementById('timezone');
var selval = "0";
for(var i = 0; i < list.options.length; ++i)
{
if(list.options[i].value==selval)
{
list.options[i].selected = true;
i=list.options.length;
}
}
</script>
</td>
</tr>
<tr>
<td>
<label for="message">Message</label>
</td>
<td colspan="2">
<textarea name="message" class="ckeditor" id="message" cols="90" rows="15" style="width: 100%;"></textarea>
</td>
</tr>
</table>
<table class="form">
<tr class="heading">
<th style="width:100%; background-color:#C4C4FE; font-size:10px; font-weight:normal;">Emails can take upto 30 minutes to Send.We have zero tolerance for spam messages.Every message sent out is reviewed for spam.Any spam messages sent will result in termination of account.</th>
</tr>
</table>
<p class="center_align">
<input type="submit" class="button arrow" name="submit_skip" value="Continue" />
</p>
</form>
and here is my second page:
<h1>Confirm Message</h1>
<?
$recepients=0;
$count=count($_POST['events']);
?>
<input type="button" class="button edit" name="submit_skip" value="Edit Message" />
<input type="submit" class="button email" name="submit_email" value="Send Message" />
i want when user click on edit massage it moves previous page and values shown in fields
?>
Since you want to send form to a two different scripts I suggest that you use 2 forms:
<form action="formfilling.php">
<?php
//prepare the recived POST to send back:
foreach( $_POST as $key => $value ){
if( is_array($_POST[$key]) ){ //if post is array e.g. your events[]
foreach( $_POST[$key] as $subvalue ){
echo '<input type="hidden"'
.' name="'.htmlspecialchars($key).'[]"'
.' value="'.htmlspecialchars($subvalue).'">'."\n";
}
} else{
echo '<input type="hidden"'
.' name="'.htmlspecialchars($key).'"'
.' value="'.htmlspecialchars($value).'">'."\n";
}
}
?>
<input type="submit" class="button edit" name="submit_skip" value="Edit Message" />
</form>
<form action="submitemail.php">
<?php //possibly show message? ?>
<input type="submit" class="button email" name="submit_email" value="Send Message" />
</form>
And then in formfilling check if input is not empty if not => echo its value
if( !empty($_POST['inputName']) ) echo htmlspecialchars($_POST['inputName']);
And for the array something like
if( !empty($_POST['inputName']) ){
foreach( $_POST['inputName'] as $val ){
//Test if the current option has the value of $val if so:
echo /*OPTION with SELECTED*/;
}
}
ALWAYS USE HTML ESCAPING when printing/echoing $_POST/$_GET
=> dont trust the users!
=> in PHP there is a htmlspecialchars() function
go to the previous page with javascript
window.history.go(-1)

Categories