AngularJs File Upload in asp.net mvc - html

here is what I've tried till now
I cant send that file to my action result, its showing me null,
<form ng-show="divPatient" name="PatientForm" ng-submit="AddUpdatePatient()">
<table>
<tr>
<td>
<input class="form-control" type="text" readonly placeholder="Key (Automatic)" ng-model="PatientID" />
</td>
<td>
<input id="FormFocus" name="FirstName" class="form-control" type="text" placeholder="FirstName" ng-model="FirstName" ng-minlength="3" required />
</td>
<td>
<input name="LastName" class="form-control" type="text" placeholder="LastName" ng-model="LastName" ng-minlength="3" required />
</td>
<td>
<input class="form-control" type="text" placeholder="Disease" ng-model="Disease" name="Disease" ng-minlength="3" required />
</td>
<td>
<input class="form-control" type="number" placeholder="Phone No." ng-model="PhoneNo" name="PhoneNo" ng-pattern="/^[789]\d{9}$/" required />
</td>
<td>
<input type="file" onchange="angular.element(this).scope().selectFileforUpload(this.files)" accept="image/*" class="form-control" ng-model="PhotoURL" value="{{PhotoURL}}" required />
</td>
<td colspan="2">
<input type="submit" value="save" class="btn btn-success" ng-disabled="PatientForm.PhoneNo.$dirty && PatientForm.PhoneNo.$invalid || PatientForm.LastName.$dirty && PatientForm.LastName.$invalid || PatientForm.FirstName.$dirty && PatientForm.FirstName.$invalid || PatientForm.Disease.$dirty && PatientForm.Disease.$invalid" />
<input type="button" value="cancel" class="btn btn-primary" ng-click="CancelForm()" />
</td>
</tr>
<tr>
<td></td>
<td><span class="eror-text" ng-show="PatientForm.FirstName.$error.minlength">min 3 letters</span></td>
<td><span class="eror-text" ng-show="PatientForm.LastName.$error.minlength">min 3 letters</span></td>
<td><span class="eror-text" ng-show="PatientForm.Disease.$error.minlength">min 3 letters</span></td>
<td><span class="eror-text" ng-show="PatientForm.PhoneNo.$error.pattern">Invalid phone no</span></td>
</tr>
</table>
</form>
$scope.selectFileforUpload = function (files) {
$scope.selectedFile = files;
}
$scope.AddUpdatePatient = function () {
var file = $scope.selectedFile[0];
var Patient = {
FirstName: $scope.FirstName,
LastName: $scope.LastName,
Disease: $scope.Disease,
PhoneNo: $scope.PhoneNo
};
var getData = angularService.AddPatient(Patient,filee);
getData.then(function (msg) {
GetAllPatients();
alert(msg.data);
$scope.divPatient = false;
}, function () {
alert('Error in adding record');
});
}
here is my service code
this.AddPatient = function (patient, file) {
// this showing me file object thats fine
alert("in services" + filee);
// i think something wrong here we shouldn't or can't send the file to actionresult like this
var response = $http({
method: "post",
url: "AddPatient",
data: JSON.stringify(patient),
dataType: "json",
// something wrong here ??
file : file
});
return response;
}
amd last my method in my controller
public string AddPatient(Patient patient,HttpPostedFileBase file)
{
// I'm getting patient data that is fine, but file is showing me null
}
is anything wrong with my service method ??? or do you know how to send form along with files to actionresult or any method in the mvc controller, i heard some pleople do it by using "new FormData", but i dont know that, but i'm willing to learn it or use it, if that solves my problem

Related

The post method is not supported for this route

I'm new to laravel and I want to submit a form which have three attachments plus some arrays
but when I click submit button laravel says
"The POST method is not supported for this route. Supported methods: GET, HEAD."
I've searched a lot but couldn't find any errors
My View
<div>
<form action="insertquotation" method="post" enctype="multipart/form-data">
#csrf
<table border="1" id="formTable">
<thead>
<tr>
<td>procurment_request_number</td>
<td>quotationer</td>
<td>shop_name</td>
<td>shop_account_number</td>
<td>shop_permit</td>
<td>shop_quatation</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" name="procurment_request_number" id="procurment_request_number" value="{{$result->first()->request_number}}">
{{--<select name="procurment_request_number[]" id="procurment_request_number">--}}
{{--#foreach($result as $results)--}}
{{--<option value="{{$results->request_number}}">{{$results->request_number}}</option>--}}
{{--#endforeach--}}
{{--</select>--}}
</td>
<td><input type="text" id="quotationer1" name="quotationer1"></td>
<td><input type="text" name="shop_name1" id="shop1_name"></td>
<td><input type="text" name="shop_account_number1" id="shop1_account_number"></td>
<td><input type="text" name="shop_permit1" id="shop1_permit"></td>
<td><input type="file" accept="application/pdf" name="shop_quatation1" id="shop_quatation"></td>
</tr>
<tr>
<td></td>
<td><input type="text" id="quotationer" name="quotationer2"></td>
<td><input type="text" name="shop_name2" id="shop1_name"></td>
<td><input type="text" name="shop_account_number2" id="shop1_account_number"></td>
<td><input type="text" name="shop_permit2" id="shop1_permit"></td>
<td><input type="file" accept="application/pdf" name="shop_quatation2" id="shop_quatation"></td>
</tr>
<tr>
<td></td>
<td><input type="text" id="quotationer" name="quotationer3"></td>
<td><input type="text" name="shop_name3" id="shop1_name"></td>
<td><input type="text" name="shop_account_number3" id="shop1_account_number"></td>
<td><input type="text" name="shop_permit3" id="shop1_permit"></td>
<td><input type="file" accept="application/pdf" name="shop_quatation3" id="shop_quatation"></td>
</tr>
<tr>
<td>Item_ID</td>
<td>Quantity</td>
<td>Unit_ID</td>
<td>description</td>
<td>Shop1_price</td>
<td>Shop2_price</td>
<td>Shop3_price</td>
</tr>
#foreach($result as $results)
<tr>
<td><input type="text" name="itemid[]" id="itemid" value="{{$results->id}}"></td>
<td><input type="text" name="quantity[]" id="quantity" value="{{$results->quantity}}"></td>
<td><input type="text" name="units_id[]" id="units_id" value="{{$results->units_id}}"></td>
<td><input type="text" name="description[]" id="description" value="{{$results->description}}"></td>
<td><input type="text" name="shop1_price[]" id="shop1_price"></td>
<td><input type="text" name="shop2_price[]" id="shop2_price"></td>
<td><input type="text" name="shop3_price[]" id="shop3_price"></td>
</tr>
</tbody>
#endforeach
</table>
{{--<input value="addrow" type="button" id="addrow" onclick="javascript: addRow();">--}}
<input type="submit" value="submit">
</form>
</div>
My Controller
public function insertquotation(request $request)
{
if ($file = $request->file('shop1_quatation')) {
$name = $file->getClientOriginalName();
$file->move('procurement_files', $name);
$file2 = $request->file('shop2_quatation');
$name2 = $file2->getClientOriginalName();
$file2->move('procurement_files', $name2);
$file3 = $request->file('shop2_quatation');
$name3 = $file2->getClientOriginalName();
$file3->move('procurement_files', $name3);
$procurment_request_number = $request->input('procurment_request_number');
$quotationer1 = $request->input('quotationer1');
$quotationer2 = $request->input('quotationer2');
$quotationer3 = $request->input('quotationer3');
$shop_name1 = $request->input('shop_name1');
$shop_account_number1 = $request->input('shop_account_number1');
$shop_permit1 = $request->input('shop_permit1');
$shop_name2 = $request->input('shop_name2');
$shop_account_number2 = $request->input('shop_account_number2');
$shop_permit2 = $request->input('shop_permit2');
$shop_name3 = $request->input('shop_name3');
$shop_account_number3 = $request->input('shop_account_number3');
$shop_permit3 = $request->input('shop_permit3');
$numbers = $request->input('itemid');
for ($i = 0; $i < count($numbers); $i++) {
$itemid = $request->input('itemid');
$shop1_price = $request->input('shop1_price');
$shop2_price = $request->input('shop2_price');
$shop3_price = $request->input('shop3_price');
DB::insert("INSERT INTO procurment_quotations (`procurment_request_number`, `itemid`, `quotationer1`, `quotationer2`, `quotationer3`, `shop1_name`, `shop1_account_number`, `shop1_permit`, `shop1_quatation`, `shop1_price`, `shop2_name`, `shop2_account_number`, `shop2_permit`, `shop2_quatation`, `shop2_price`, `shop3_name`, `shop3_account_number`, `shop3_permit`, `shop3_quatation`, `shop3_price`, `created_at`, `updated_at`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,)", [$procurment_request_number, $itemid[$i],$quotationer1,$quotationer2,$quotationer3,$shop_name1,$shop_account_number1,$shop_permit1,$name,$shop1_price,$shop_name2,$shop_account_number2,$shop_permit2,$name2,$shop2_price,$shop_name3,$shop_account_number3,$shop_permit3,$name3,$shop3_price]);
}
}
}
and my route
Route::Post('insertquotation','Home#insertquotation');
The error is
"The POST method is not supported for this route. Supported methods: GET, HEAD."
Give the route a name in your routes/web.php file:
Route::post('insertquotation','Controllername#methodname')
->name('insertquotation');
And then change the form action in your blade file to point to that route:
<form action="{{ route('insertquotation') }}" method="post" enctype="multipart/form-data">
Couple of things which I need to point out on your code
It is always better to use route names while creating routes so that when you need to change the route URL to something else, you only need to change it inside routes file (not view files)
Route::post('insertquotation','Home#insertquotation')->name('insertquotation');
Now inside your view, you need to do this
<form method="POST" enctype="multipart/form-data" action="{{ route('insertquotation') }}"> ... </form>
In the future when you want (maybe not) to change the URL to /quotation/insert, all you have to do is to change it inside the routes file.
Now, inside your controller,
There is a function to check whether the file exists $request->hasFile('shop1_quatation') which more correct to use inside an if condition rather passes in the file.
Also, it is much better to use Laravel eloquent for inserting data into the database. Learn more here
I think from action="insertquotation", you should make it into action="{{url('insertquotation')}}"
And may I see the codes in your routes/web.php file? you should declare the route insertquotation there
For example:
Route::post('insertquotation', 'YourController#yourMethod');

Transfer table row data to html form page in angular

Using Angular JS I am trying to pass the data in a table row that is populated dynamically to an html page. The page would then use that object
that is passed to populate form data.
My html looks like below:
<form data-ng-submit="submit()" name="empRegForm" method="post">
<input type="hidden" type="text" ng-model="employee.employeeId" />
<fieldset class="table-striped">
<input placeholder="Employee Project Id" type="text" ng-model="employee.projectId" tabindex="1" required autofocus>
</fieldset>
<fieldset>
<input placeholder="Employee Name" type="text" ng-model="employee.employeeName" tabindex="2" required>
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit">Submit</button>
</fieldset>
</form>
Method that I have created on the controller is as follows:
$scope.updateEmployee = function(employee) {
var response = $http.put('localhost:8080/employeeManagement/employee', employee);
response.success(function(data, status, headers, config) {
$scope.result = data;
});
response.error(function(data, status, headers, config) {
alert( "Exception details: " + JSON.stringify({data: data}));
});
};
EmployeeList html table appears as below:
<tr ng-repeat="employee in result.listOfEntities">
<td>{{employee.employeeId}}</td>
<td>{{employee.employeeName}}</td>
<td><a ng-click="updateEmployee(employee)"> <span class="fa fa-pencil-square-o" aria-hidden="true"></span></a></td>
</tr>
I want to redirect the page to the Update html page that contains the form when this button on the row is clicked.
Thanks
Added ng-include to load different html page in your table page itself and to toggle it on need basis as like example below,
In controller:
$scope.loadEmployee = function(employee){
$scope.employee=employee;
$scope.employee.visible=true;
};
$scope.updateEmployee = function(employee) {
var response = $http.put('localhost:8080/employeeManagement/employee', employee);
response.success(function(data, status, headers, config) {
$scope.result = data;
});
response.error(function(data, status, headers, config) {
alert( "Exception details: " + JSON.stringify({data: data}));
});
$scope.employee.visible=false;
};
In Template:
<tr ng-repeat="employee in result.listOfEntities">
<td>{{employee.employeeId}}</td>
<td>{{employee.employeeName}}</td>
<td><a ng-click="loadEmployee(employee)"> <span class="fa fa-pencil-square-o" aria-hidden="true"></span></a></td>
</tr>
<div ng-include src="'/employee-update.html'" ng-controller="employeeController" ng-show="employee.visible"></div>
employee-update.html:
<form data-ng-submit="updateEmployee()" name="empRegForm" method="post">
<input type="hidden" type="text" ng-model="employee.employeeId" />
<fieldset class="table-striped">
<input placeholder="Employee Project Id" type="text" ng-model="employee.projectId" tabindex="1" required autofocus>
</fieldset>
<fieldset>
<input placeholder="Employee Name" type="text" ng-model="employee.employeeName" tabindex="2" required>
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit">Submit</button>
</fieldset>
</form>

Contact form doesnt send email, Error page

Hi I really need help with this.
I have just finished a design for a client and her website went live on Thursday, however the contact form doesn't work. I do know things about HTML/CSS but I am very basic with stuff with script. When you fill in the form and press send a 'not found' page appears.
Whats gone wrong?
I have tried looking at other posts about this kind of thing but I think the code needs looking at.
Much appreciated
//email form validation
function everif(str) {
var at="#"
var punct="."
var lat=str.indexOf(at)
var lstr=str.length
var lpunct=str.indexOf(punct)
if (str.indexOf(at)==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct)==-1 || str.indexOf(punct)==0 || str.indexOf(punct)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Valid email must be entered")
return false
}
if (str.substring(lat-1,lat)==punct || str.substring(lat+1,lat+2)==punct){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct,(lat+2))==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(" ")!=-1){
alert("Valid email must be entered")
return false
}
return true
}
function evalid(){
var emailID=document.contact_form.mail
if (everif(emailID.value)==false){
emailID.focus()
return false
}
//empty field validation
var fname=document.contact_form.fname
if ((fname.value==null)||(fname.value=="")){
alert("Fields marqued with * must be entered")
fname.focus()
return false
}
var lname=document.contact_form.lname
if ((lname.value==null)||(lname.value=="")){
alert("Fields marqued with * must be entered")
lname.focus()
return false
}
var message=document.contact_form.message
if ((message.value==null)||(message.value=="")){
alert("Fields marqued with * must be entered")
message.focus()
return false
}
return true
}
</script>
<form name="contact_form" method="post" action="mailer.php" onSubmit="return evalid()">
<table border="0"><tr>
<td colspan="2"><input name="fname" type="text" value="First Name" size="40" /></td>
</tr><tr>
<td colspan="2"><input name="lname" type="text" value="Last Name" size="40" /></td>
</tr><tr>
<td colspan="2"><input type="text" value="Email" name="mail" size="40" /></td>
</tr><tr>
<td colspan="2"><textarea name="message" value="Your Message" onkeyup="return limitarelungime(this, 255)" cols="35" rows="5"></textarea></td>
</tr><tr>
<td></td>
<td colspan="2"></td>
</tr>
<tr>
<td align="right">
<input type="image" src="images/send.png" value="Submit" alt="submit" name="submit"/>
</td>
<td align="right"><alt="Valid Contact Form" width="20" height="20" border="0" /></a></td>
</tr>
</table>
</form>
</div>
Page not found error suggests that there is some problem with the URL redirect quite simply or the file does not exist. In your case if the form is sending the data to a mailer.php script, just make sure that the path of the file is entered correctly and that the file is there in a particular folder according to the path. Your problem should be solved.

Retaining values of variables after successive form submission in JSP [duplicate]

This question already has answers here:
How can I retain HTML form field values in JSP after submitting form to Servlet?
(2 answers)
Closed 7 years ago.
I have written following two jsp files. First file i.e. submit.jsp has form where user submits her query and her city and latitude and longitude are recorded and she is forwarded to another jsp page which also has a form where she can again submit her query as many times as she wants and I want the values of city , latitude and longitude to be retained but they are getting reset. The code of the two files are as follows:
submit.jsp
<%# page contentType="text/html; charset=iso-8859-1" language="java" %>
<html>
<head>
<script type="text/javascript">
function getLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function displayLocation(latitude,longitude){
var request = new XMLHttpRequest();
var method = 'GET';
var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+latitude+','+longitude+'&sensor=true';
var async = true;
request.open(method, url, async);
request.onreadystatechange = function(){
if(request.readyState == 4 && request.status == 200){
var data = JSON.parse(request.responseText);
var address = data.results[0];
//document.write(address.formatted_address);
var city=document.getElementById("city");
var n = address.formatted_address.split(",");
city.value = n[n.length-3];
}
};
request.send();
};
function showPosition(position){
//var x = document.getElementById("demo");
var latitude=document.getElementById("latitude"),longitude=document.getElementById("longitude");
//x.innerHTML="+" + position.coords.latitude + "+" + position.coords.longitude;
latitude.value = position.coords.latitude;
longitude.value = position.coords.longitude;
displayLocation(latitude.value,longitude.value);
}
</script>
</head>
<body onload="getLocation()">
<form name="frm" method="post" action="process.jsp">
<input type="text" name="myQuery" placeholder="Type here">
<input name="latitude" id="latitude" type="hidden">
<input name="longitude" id="longitude" type="hidden">
<input name="city" id="city" type="hidden">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
process.jsp
<%# page contentType="text/html; charset=iso-8859-1" language="java" %>
<%! String city; String latitude; String longitude; %>
<form name="frm" method="post" action="process.jsp">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%"> </td>
<td width="78%"> </td>
</tr>
<tr>
<td> </td>
<td><input type="text" name="myQuery" placeholder="Type here"></td>
</tr>
<tr>
<td> </td>
<input name="latitude" id="latitude" type="hidden" value="${latitude}" >
<input name="longitude" id="longitude" type="hidden" value="${longitude}" >
<input name="city" id="city" type="hidden" value="${city}" >
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<%
String query=request.getParameter("myQuery");
String city=request.getParameter("city");
String latitude=request.getParameter("latitude");
String longitude=request.getParameter("longitude");
%>
<html>
<body>
<p>Query phrase is : <%=query%></p>
<p>User's city : <%=city%></p>
</body>
</html>
I am new to JSP. So can anyone please help me to fix the given code.
<%# page contentType="text/html; charset=iso-8859-1" language="java" %>
<%! String city; String latitude; String longitude;String query; %>
<%
query=request.getParameter("myQuery");
city=request.getParameter("city");
latitude=request.getParameter("latitude");
longitude=request.getParameter("longitude");
%>
<html>
<body>
<form name="frm" method="post" action="process.jsp">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%"> </td>
<td width="78%"> </td>
</tr>
<tr>
<td> </td>
<td><input type="text" name="myQuery" placeholder="Type here"></td>
</tr>
<tr>
<td> </td>
<input name="latitude" id="latitude" type="hidden" value="<%=latitude%>" >
<input name="longitude" id="longitude" type="hidden" value="<%=longitude%>>" >
<input name="city" id="city" type="hidden" value="<%=city%>" >
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<p>Query phrase is : <%=query%></p>
<p>User's city : <%=city%></p>
</body>
</html>
try to get the parameters at the beginning of the file.
<%
String query=request.getParameter("myQuery");
String city=request.getParameter("city");
String latitude=request.getParameter("latitude");
String longitude=request.getParameter("longitude");
%>
like this ...
<%# page contentType="text/html; charset=iso-8859-1" language="java" %>
<html>
<head>
<script type="text/javascript">
function getLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function displayLocation(latitude,longitude){
var request = new XMLHttpRequest();
var method = 'GET';
var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+latitude+','+longitude+'&sensor=true';
var async = true;
request.open(method, url, async);
request.onreadystatechange = function(){
if(request.readyState == 4 && request.status == 200){
var data = JSON.parse(request.responseText);
var address = data.results[0];
//document.write(address.formatted_address);
var city=document.getElementById("city");
var n = address.formatted_address.split(",");
city.value = n[n.length-3];
}
};
request.send();
};
function showPosition(position){
//var x = document.getElementById("demo");
var latitude=document.getElementById("latitude"),longitude=document.getElementById("longitude");
//x.innerHTML="+" + position.coords.latitude + "+" + position.coords.longitude;
latitude.value = position.coords.latitude;
longitude.value = position.coords.longitude;
displayLocation(latitude.value,longitude.value);
}
</script>
</head>
<body onload="getLocation()">
<%! String city; String latitude; String longitude; %>
<%
String query=request.getParameter("myQuery");
String city=request.getParameter("city");
String latitude=request.getParameter("latitude");
String longitude=request.getParameter("longitude");
%>
<form name="frm" method="post" action="submit.jsp">
<input type="text" name="myQuery" placeholder="Type here">
<input name="latitude" id="latitude" type="hidden">
<input name="longitude" id="longitude" type="hidden">
<input name="city" id="city" type="hidden">
<input type="submit" name="submit" value="Submit">
</form>
<p>Query phrase is : <%=query%></p>
<p>User's city : <%=city%></p>
</body>
</html>

Why i am getting Undefined index?

i am developing an application using CodeIgniter. In my application when i submit the form in firefox 10.0, i got this error
Message: Undefined index: adcopy_response
But when i submits the form in IE 9. It's working fine my application. No errors found in IE. Can any one. My HTML code is
<table>
<form action="" method="post">
<tr id="row">
<td><b>Title:</b></td>
<td>
<input type="text" style="width:450px;" name="title" value="" />
</td>
</tr>
<tr id="row">
<td><b>Description:</b></td>
<td>
<textarea style="width:450px;" name="desc" cols="35" rows="10"></textarea>
</td>
</tr>
<tr id="row">
<td><b>URL:</b></td>
<td>
<input type="text" style="width:450px;" name="url" value="" />
</td>
</tr>
<tr id="row">
<td><b>Category:</b></td>
<td>
<select name="cat">
<option value="">Select Category</option>
<option value="ajax-tutorials">AJAX Tutorials</option><option value="asp-tutorials">ASP Tutorials</option><option value="asp.net-tutorials">ASP.NET Tutorials</option><option value="codeigniter-tutorials">CodeIgniter Tutorials</option><option value="css-tutorials">CSS Tutorials</option><option value="html-tutorials">HTML Tutorials</option><option value="javascript-tutorials">JavaScript Tutorials</option><option value="jquery-tutorials">jQuery Tutorials</option><option value="ms-sql-tutorials">Ms SQL Tutorials</option><option value="mysql-tutorials">MySQL Tutorials</option><option value="php-tutorials">PHP Tutorials</option><option value="programming-tutorials">Programming Tutorials</option><option value="wordpress-themes">Wordpress Themes</option><option value="wordpress-tutorials">WordPress Tutorials</option><option value="xml-tutorials">XML Tutorials</option> </select>
</td>
</tr>
<tr id="row">
<td><b>Prove you're not a robot</b></td>
<td>
<script type="text/javascript" src="http://api.solvemedia.com/papi/challenge.script?k=hse4RWPEOMayq3QzRQiUZTnTtVkI8Jmf"></script>
<noscript>
<iframe src="http://api.solvemedia.com/papi/challenge.noscript?k=XXXX" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="adcopy_challenge" rows="3" cols="40"></textarea>
<input type="hidden" name="adcopy_response" value="manual_challenge"/>
</noscript> </td>
</tr>
<tr id="row">
<td>
<input type="hidden" name="ok" value="1" />
<input type="hidden" name="by" value="seekphp" />
<input type="submit" name="submit" value="Submit Tutorial" />
</td>
</tr>
</form>
</table>
and CI code is
function submit(){
$privkey="XXXX";
$hashkey="XXXX";
$data['err'] = "";
$this->form_validation->set_rules('title', 'Title', 'required|trim|xss_clean|htmlentities');
$this->form_validation->set_rules('desc', 'Description', 'required|trim|xss_clean|htmlentities');
$this->form_validation->set_rules('url', 'URL', 'required|trim|xss_clean');
$this->form_validation->set_rules('cat', 'Category', 'required|trim|xss_clean');
if($this->form_validation->run() == FALSE){
} else {
$title = $this->input->post('title');
$desc = $this->input->post('desc');
$url = $this->input->post('url');
$cat = $this->input->post('cat');
$by = $this->input->post('by');
$ok = $this->input->post('ok');
$solvemedia_response = $this->Captcha_model->solvemedia_check_answer($privkey,
$_SERVER["REMOTE_ADDR"],
$_POST["adcopy_challenge"],
$_POST["adcopy_response"],
$hashkey);
if ($solvemedia_response->is_valid) {
if($this->Tutorial_model->add_tut($title, $desc, $url, $cat, $by, $ok) == TRUE){
$this->session->set_flashdata('msg', "Tutorial has been added successfully.");
redirect(base_url().'user/submit', 'refresh');
} else {
$this->session->set_flashdata('err', "Tutorial may already exist or there is an error while submitting tutorial.");
redirect(base_url().'user/submit', 'refresh');
}
} else {
$data['err'] = "Incorrect Captcha.";
}
}
$data['cats'] = $this->Category_model->get_all_cats();
$this->load->view("user/submit_view", $data);
}
and when i print_r($_POST);
i got the following
Array ( [title] => test title [desc] => test desc [url] => test url [cat] => javascript-tutorials [adcopy_challenge] => 2#hse4RWPEOMayq3QzRQiUZTnTtVkI8Jmf#Szx1Cc29gNUENU8bgrSwY39APTC4lJjoCYJjyXvIJi2gPnq5tZIMpr0JgoGocL4bVHKrYt6Zyx3w-DAv2nYsjYiaeT-0C9Ec297zPussZKqXHDAdWTWT7ZcC1MklNV75-TPQzGDGu0yUgkDQWcRup.sNAOGBvK0cXCac1RzQ7T6adyI4bmcrNTpt7ANEEq2-1QcBgS8Uky6FxFHeFyGMDgzlJvqGyrBJfDRBNwroHBUXGHC1Jza9b54IS1.0E9kwlqZUOeBX9EomSEVcgrS6gA [ok] => 1 [by] => seekphp [submit] => Submit Tutorial ) 1
Even if you think you know what should be in the $_POST array, don't assume it if you want to avoid notices. Codeigniter has the Input class to make this easier:
$_POST['doesnt exist']; // generates undefined index notice
$this->input->post('doesnt exist'); // returns FALSE, no notice
Most importantly, you have the input in a <noscript> tag, so the browser may not send the value.
But when I submit the form in IE9 it's working fine, no errors found.
Chances are you either have javascript turned off, or IE is misbehaving (quite likely).
I think $_POST["adcopy_response"] is being used on Captcha Model but it is not in $_POST
Finally i resolved the problem by removing <table> <tr> <td> tags
Place your hidden tag out of <noscript> tag. only When script is disabled in your browser, code inside the <noscript> will work. Disable script in your browser and then run it will perfectly work.