I have a problem with $_POST. I am adding data to my mysql database with this code and it is working.;
if (isset($_POST["d_kayit"])){
$denetci=$dbpdo->prepare("INSERT INTO denetciler(name,pass) VALUES(:name, :pass)");
$denetci->bindParam(":name",$_POST["denad"],PDO::PARAM_STR);
$denetci->bindParam(":pass",$_POST["sif"],PDO::PARAM_STR);
$denetci->execute();
}
But in the same form i want to use $_POST["denad"] for another insert. It is giving me "Notice: Undefined index: denad in" error. Sample code that giving error is;
if (isset($_POST["add"]))
{
echo "Person: ".$_POST["denad"];
}
Can you help me please?
If this:
if (isset($_POST["add"]))
{
echo "Person: ".$_POST["denad"];
}
is yielding notice: Undefined index: denad then you probably don't have inputs "add" and "denad" on the same form. Or it is an unchecked checkbox.
Edit based on the code of your HTML form. You'll need something like this, you can't end your form with </form> like you did until you included all needed input fields:
<form action="" method="post">
<!-- content here -->
<input name="denad" id="denad" type="text" style="margin-top:2px; width:200px; height:30px;"></input>
<input type="submit" class="get_file" id="K_ekle" name="add" onclick="test()" value="Kişiye Ekle" style="float:left;"></input>
<!-- more content here -->
</form>
Related
I have a form with id theForm which has the following div with a submit button inside:
<div id="placeOrder"
style="text-align: right; width: 100%; background-color: white;">
<button type="submit"
class='input_submit'
style="margin-right: 15px;"
onClick="placeOrder()">Place Order
</button>
</div>
When clicked, the function placeOrder() is called. The function changes the innerHTML of the above div to be "processing ..." (so the submit button is now gone).
The above code works, but now the problem is that I can't get the form to submit! I've tried putting this in the placeOrder() function:
document.theForm.submit();
But that doesn't work.
How can I get the form to submit?
Set the name attribute of your form to "theForm" and your code will work.
You can use...
document.getElementById('theForm').submit();
...but don't replace the innerHTML. You could hide the form and then insert a processing... span which will appear in its place.
var form = document.getElementById('theForm');
form.style.display = 'none';
var processing = document.createElement('span');
processing.appendChild(document.createTextNode('processing ...'));
form.parentNode.insertBefore(processing, form);
It works perfectly in my case.
document.getElementById("form1").submit();
Also, you can use it in a function as below:
function formSubmit()
{
document.getElementById("form1").submit();
}
document.forms["name of your form"].submit();
or
document.getElementById("form id").submit();
You can try any of this...this will definitely work...
I will leave the way I do to submit the form without using the name tag inside the form:
HTML
<button type="submit" onClick="placeOrder(this.form)">Place Order</button>
JavaScript
function placeOrder(form){
form.submit();
}
You can use the below code to submit the form using JavaScript:
document.getElementById('FormID').submit();
<html>
<body>
<p>Enter some text in the fields below, and then press the "Submit form" button to submit the form.</p>
<form id="myForm" action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="button" onclick="myFunction()" value="Submit form">
</form>
<script>
function myFunction() {
document.getElementById("myForm").submit();
}
</script>
</body>
</html>
HTML
<!-- change id attribute to name -->
<form method="post" action="yourUrl" name="theForm">
<button onclick="placeOrder()">Place Order</button>
</form>
JavaScript
function placeOrder () {
document.theForm.submit()
}
If your form does not have any id, but it has a class name like theForm, you can use the below statement to submit it:
document.getElementsByClassName("theForm")[0].submit();
I have came up with an easy resolve using a simple form hidden on my website with the same information the users logged in with. Example: If you want a user to be logged in on this form, you can add something like this to the follow form below.
<input type="checkbox" name="autologin" id="autologin" />
As far I know I am the first to hide a form and submit it via clicking a link. There is the link submitting a hidden form with the information. It is not 100% safe if you don't like auto login methods on your website with passwords sitting on a hidden form password text area...
Okay, so here is the work. Let’s say $siteid is the account and $sitepw is password.
First make the form in your PHP script. If you don’t like HTML in it, use minimal data and then echo in the value in a hidden form. I just use a PHP value and echo in anywhere I want pref next to the form button as you can't see it.
PHP form to print
$hidden_forum = '
<form id="alt_forum_login" action="./forum/ucp.php?mode=login" method="post" style="display:none;">
<input type="text" name="username" id="username" value="'.strtolower($siteid).'" title="Username" />
<input type="password" name="password" id="password" value="'.$sitepw.'" title="Password" />
</form>';
PHP and link to submit form
<?php print $hidden_forum; ?>
<pre>Forum</pre>
I am trying to make a simple creation of account and when create button is clicked it should perform the action "create" but I get an error saying that
HTTP Status 404 - "/WEB-INF/grails-app/views/users/create.gsp" not found.
Here is my code block for the index.gsp
<!-- CREATEFORM -->
<div id="id02" class="modal">
<g:form class="modal-content animate" controller="users" action="create">
<div class="imgcontainer">
<span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">×</span>
<div class="container" style="text-align:center">
<b><h style="font-family: Arial, Helvetica, sans-serif; font-size: 30px">CREATE AN ACCOUNT</h></b><br/>
<input type="text" placeholder="Enter Username" name="uname" required/>
<input type="password" placeholder="Enter Password" name="psw" required/>
<input type="text" placeholder="First Name" name="firstName" required/>
<input type="text" placeholder="Last Name" name="lastName" required/>
<input type="text" placeholder="Age" name="age" required/>
<br/>
<input type="date" placeholder="Birth Date" name="birthdate" required/>
<br/>
<input type="text" placeholder="Student Number" name="studno" required/><br/>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me</input>
</label>
<br/>
<button type="submit" style="width: 100px; margin-right:10px;" >Create</input>
<button type="button" onclick="document.getElementById('id02').style.display='none'" class="cancelbtn">Cancel</button>
</div>
</div>
</g:form>
</div>
and Here is my code block for the usersController.
class usersController {
def index(){}
def create()
{
new Users(userid:params.uname,password:params.psw).save()
new UserInfo(studentno:params.studno,age:params.age,birth_date:params.birthdate,first_name:params.firstName,last_name:params.lastName,user_id:params.uname).save()
}
}
And here's the error
HTTP Status 404 - "/WEB-INF/grails-app/views/users/create.gsp" not found.
Because you are saving data using create action but after saving data there is no redirect option or create.gsp available. So grails will look first is there any redirect option available and try to redirect create.gsp
Check bellow code changes which will save user id to userInfo table and redirect to index page
So change your usersController
class usersController {
def index() {}
def create() {
def user = new Users(userid: params.uname, password: params.psw).save()
def userInfo = new UserInfo(studentno: params.studno, age: params.age, birth_date: params.birthdate, first_name: params.firstName, last_name: params.lastName, user_id: user.id).save()
if (user && userInfo) {
flash.message = "User created successfully"
redirect action: 'index'
} else {
flash.message = "Problem in user creation"
redirect action: 'index'
}
}
}
And add bellow code to your index.gsp
${flash.message}
There are many ways to redirect to pages. You can use render, redirect, chain, forward ..etc
Please check grails documentation for more information
In Grails for action (non gsp) you need to render something to the client,
otherwise it executes everything inside that action, but returns 404 gsp not found response, if there is no render / redirection statement it consider that action as a gsp but it is not gsp actually, therefore it responds 404.
You could render something data like list / JSON or simple string as follows.
def create() {
//your business logic is here
render "operation performed successfully"
}
First of all what grails version do you use? If the latest one (3.3.4) so this link might be helpful.
Speaking shortly: if you don't specify what to render explicitly - grails tries to find the view to display the result of action execution as:
grails-app/views/<controllerName>/<actionName>.gsp
Looks like you don't have one.
UPD
There are several ways to render action's output in grails controller.
Define explicit content as:
def myAction() {
...
render "Hello World!"
}
That will result in "white screen" with "Hello world!" text in top-left corner.
Another option is to create a gsp view in the conventional location as grails-app/views//.gsp - it will automatically be rendered after action execution if no specifying the render method invocation (like in the sample you've given)
The third option is to specify the model map:
def myAction() {
...
[param1key: param1value, param2key: param2value, ...]
}
The model will be taken into account when rendering your gsp view.
Please read the documentation I gave link to. It's incredibly helpful.
I'm trying to get the results from a g:uploadForm action I have in my GSP file. I need to upload the file, then after it's successfully uploaded I need to tell if the upload was successful, then display another area in the GSP file.
<g:uploadForm action="save" method="post">
<h1>
<g:message code="upload"/>
</h1>
<h5>
<g:message code="upload.message"/>
</h5>
<br/>
<input type="file" id="Upload" name="Upload" class="input"/>
<br/>
<g:formButton type="submit" buttonClass="btn-primary btn-lg" buttonTextCode="upload.button" />
</g:uploadForm>
I just need something to say if it was successful or not.
Is this something I need to handle in the controller and just post to the GSP after that? I'm new to grails and groovy.
It's pretty common to use flash scoped variables for these types of messages. In fact, if you look at the Grails documentation about uploading files you will see it does just that.
def upload() {
def f = request.getFile('myFile')
if (f.empty) {
flash.message = 'file cannot be empty'
render(view: 'uploadForm')
return
}
f.transferTo(new File('/some/local/dir/myfile.txt'))
redirect(render: 'uploadForm')
}
Using the above example you could then include the following in your uploadForm GSP page.
${flash.message} to display this.
I am working on an application using Classic ASP and SQL Server 2008 R2. We are using SSRS for the reports. Now the datasource changes depending on the user. I have been using a parameter for the connectionstring. It is working fine but the problem is the connectionstring shows in the URL. Is there a way to hide it? Or is there a better way.
Please Help.
Yes - change the method on your form to POST and use the Request.Form syntax instead of Request.QueryString:
<form id="myForm" method="post" action="myPage.asp">
<label for="txtBox">Type something</label>
<input type="text" id="txtBox" name="txtBox" />
</form>
<%
Dim value
value = Cstr(Request.Form("txtBox"))
If value <> "" then
'Do your processing
End if
%>
-- EDIT --
To be honest, though, I would not store my connection string on my form like this. You'd be far better off storing it in an Application level variable, like so:
Application("CON_STRING") = "...blahblahblah..."
This should be stored in the Application_OnStart event of the Global.asa* file.
*
Apologies for the link to w3schools - it was the best at the time!
-- EDIT 2 --
Try using an iframe to display the info...
<form id="frmRender" action="ABCD/ReportServer?/Reports/rptSalesReport.rpt"; method="post" target="_blank">
<input type="hidden" name="rs:Command" value="Render">
<input type="hidden" name="rc:LinkTarget" value="_blank">
<input type="hidden" name="rs:Format" value="HTML4.0">
<input type="hidden" name="rc:Parameters" value="False">
<input type="hidden" name="ConnectionString" value="<%=Session("ConnectionString")%>">
<input type="hidden" name="StartDate" value="<%=StartDate%>">
<input type="hidden" name="EndDate" value="<%=EndDate%>">
<a id="linkInfo" href="javascript:generateSsrs();">Generate Report</a>
<iframe id="ssrsReport" class="reportHeightWidth"></iframe>
</form >
<script language="javascript">
function genreateSsrs() {
document.getElementById("ssrsReport").src = "ABCD/ReportServer?/Reports/rptSalesReport.rpt?rs:Command=Render&rc:LinkTarget=top&rs:Format=HTML4.0&rc:Parameters=False&ConnectionString=<%=Server.URLEncode(Session("ConnectionString"))%>&StartDate=<%=StartDate%>&EndDate=<%=EndDate%>";
}
</script>
That's a rough version, but it's untested, so may need some tweaks.
In you code, use the below code
="Data Source="+Parameters!DatabaseServerName.Value+";Initial Catalog="&Parameters!DatabaseCatalogName.Value
I try to build a grails webflow containing a step which has a file upload field in it. Can't find a clear example. How can I do it?
The form looks like this:
<g:form method="POST" action="upload" enctype="multipart/form-data">
<input type="file" name="myFile" />
<input type="submit" value="Upload! " />
</g:form>
The flow looks like this:
def rgdpsRequestFlow = {
chargeCheck{
on("upload"){
println "Hello file upload"
}.to("uploadSuccess")
}
uploadSuccess{
}
}
When I submit the form I get
HTTP Status 404 - /webflowTest/mortgage/upload
It's a little unclear which part you're struggling with. If you need help with the file upload, you may want to try the Grails File Uploader plugin, or otherwise check out this step-by-step tutorial or use the uploadForm tag that James Kleeh has pointed out.
Namely, in the gsp you can add:
<g:uploadForm controller='yourControllerName' action='save'>
<input type='file' name='file'/>
<input type='submit'/>
</g:uploadForm>
Then handle it in the controller:
def save = {
def file = request.getFile('file').inputStream.text
file.transferTo(new File('someLocation/filename'))
}
The problem was I used g:form action attribute.
The correct way to use file upload with webflow is using g:submitButton
Here is the form code that works fine with my webflow:
<g:form method="POST" enctype="multipart/form-data">
<input type="file" name="myFile" />
<g:submitButton class="save" name="upload" value="Upload!"/>
</g:form>