HTML form, prevent refresh after clicking submit - php

I need to prevent refreshing the page after clicking on submit button. I've tried methods like
$("#prospects_form").submit(function(e) {
e.preventDefault();
and "onsubmit="return false" or "type=button"....but the problem is, even though all of these methods work, it seems that my php script doesn't get executed
this is my form
<form method="POST" action="storeImage.php">
<div class="row">
<div class="col-md-6" id="the_cam">
<div id="my_camera"></div>
<div id="start_webcam">
<input style="font-size:13px" type=button class="btn-get-started" value="Start webcam" onClick="start_webcam()">
</div>
<br />
<div id="take_snapshot" style="visibility: hidden;">
<input class="btn-get-started" type=button value="Take Snapshot" onClick="take_snapshot()">
</div>
<input type="hidden" name="image" class="image-tag">
</div>
<div class="col-md-6">
<div id="results" style="text-align: center;"></div>
<br />
<div id="submit" style="visibility: hidden; margin-top:60px;">
<button class="btn-get-started" onclick="submit_image()">Submit</button>
</div>
</div>
</div>

Related

Login button not giving submit info while hitting enter works for getting credentials

I'm currently creating a phishing test for my employees and I got into a problem.I'm hosting my index.html on my local server using xampp and I want to when someone logs that I can get their info.I made a post.php that gives me the info when i use an username and password and it works.But it only works when I hit enter,when I clik on login it just redirects me to a page I made and I don't get any info in my text file.While I hover over my login button (Activate) it gives me that it redirects to the redircet page that I made.Do you have any suggestions how can I make that m,y login button(activate in the code) still gives me the info as same when I hit enter?
Thank you.
My code is below for index.html.
<html><head>
</div>
<form id="loginForm" name="loginForm" method="post" action="post.php" onsubmit="return doLogin2();">
<div id="panelbody">
<div id="branding" class="clearfix branding">
<img id="loginWheel" src="web%20FTP%20WebInterface_files/wheel.gif" style="display: none;">
<a id="defaultLogoLink" href="http://www.crushftp.com/">
<img id="imgLogo" src="web%20FTP%20WebInterface_files/logo.png" style="border-width:0px;float:left;">
</a>
</div>
<div id="panelLogin">
<div>
<label id="UserNameText">Username</label>
<input tabindex="1" autocomplete="on" type="text" class="textbox" name="username" id="username" value="/">
</div>
<div>
<label id="PasswordText">Password</label>
<input tabindex="2" autocomplete="on" type="password" class="textbox" name="password" id="password" value="">
</div>
<div id="rememberMePanel">
<label><input tabindex="3" type="checkbox" name="remember" id="remember" checked="checked"> <span id="RememberMeText">Remember Me</span></label>
</div>
<div id="acceptTC" style="display: none">
<label><input tabindex="4" type="checkbox" name="tandc" id="tandc"> <span id="TnCText"></span></label>
</div>
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
<div id="recaptcha_div"></div>
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
<div class="submit clearfix">
<input type="submit" value="login" style="display:none;">
<input type="hidden" name="command" value="login">
<input type="hidden" name="skip_login" value="true">
<input type="hidden" name="encoded" value="false">
<input type="submit" value="login now" style="position:absolute;left:-1000px;top:-1000px;">
<a class="button" id="btnLogin" href="javascript:void(0);">
<span id="LoginButtonText">Login</span>
</a>
</div>
<p class="lostpassword" style="visibility:hidden;">
I forgot my password
</p>
</div>
<div id="panelResetPass" style="display:none;">
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
<h3 class="resetTitle" id="RequestPasswordHeaderText">Request Password</h3>
<div>
<label id="ResetUserNameText">Username</label>
<input autocomplete="off" type="text" class="textbox" name="resetUserName" id="resetUserName">
</div>
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
<p></p>
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
<div class="submit clearfix">
<a class="button" id="btnResetPassword" href="javascript:void(0);">
<span id="ResetPasswordButtonText">Reset Password</span>
</a>
<a class="button" id="btnBackToLogin" href="javascript:void(0);">
<span id="BackToLoginButtonText">Back to Login</span>
</a>
</div>
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
<p></p>
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
<p></p>
<div style="clear:both;height:1px;padding:0px;margin:0px;"></div>
</div>
</div>
</form>
<form id="changePassForm" method="post" target="dummyIframe" action="/WebInterface/function/" onsubmit="doLogin();">
<div id="changepasswordPanel" style="display:none;margin-bottom:10px;">
<div class="clearfix branding" style="clear:both;">
<a id="defaultLogoLink" href="http://www.crushftp.com/">
<img id="imgLogo" src="web%20FTP%20WebInterface_files/logo.png" style="border-width:0px;float:left;margin:3px 0px 10px 0px;">
</a>
</div>
<h2 class="popupHeader" style="clear:both;margin-top:15px;" id="ChangePasswordHeaderText">Change your password</h2>
<div class="passwordChangeNote" id="ChangePasswordNoteText">You must change your password to continue</div>
<div class="buttonPanel">
<label for="current_password" id="CurrentPasswordText">Current Password : </label>
<input id="current_password" class="textbox" type="password">
<br>
<br>
<label for="new_password1" id="NewPasswordText">New Password : </label>
<input id="new_password1" class="textbox" type="password">
<br>
<br>
<label for="new_password2" id="ConfirmPasswordText">Confirm Password : </label>
<input id="new_password2" class="textbox" type="password">
<div style="text-align:right;margin-top:10px;">
<a id="btnChangePasswordCancel" class="button" href="javascript:void(0);">
<span id="CancelButtonText">Cancel</span>
</a>
<a id="btnChangePassword" class="button" href="javascript:void(0);">
<span id="ChanngePasswordButtonText">Change Password</span>
</a>
</div>
<div style="clear:both"></div>
<div class="spacing">
<br>
<hr>
<br>
</div>
<div id="generatePasswordPanel">
<a id="btnGeneratePassword" class="button" href="javascript:void(0);" style="float:left">
<span id="GeneratePasswordButtonText">Generate password</span>
</a>
<div id="passwordGeneratePanel" style="display:none;">
<br>
<br>
<input id="generated_password" type="text" class="textboxSmall" style="float:left;">
<a id="usePassword" class="button" href="javascript:void(0);" style="float:left">
<span id="GeneratePasswordUseButtonText">Use this</span>
</a>
<a id="cancelPassword" class="button" href="javascript:void(0);" style="float:left">
<span id="GeneratePasswordCancelButtonText">Cancel</span>
</a>
</div>
<div style="clear:both"></div>
</div>
</div>
</div>
</form>
</div>
<div id="OTPBox" style="display:none;">
<img class="closeButton" alt="close" src="web%20FTP%20WebInterface_files/cancel.png" onclick="$.unblockUI();">
<h2 class="popupHeader" id="OTPDialogHeaderText">Enter your OTP here</h2>
<div class="buttonPanel">
<div style="width:100%;">
<input id="otp" type="password" style="width:95%;padding:5px;">
</div>
<br>
<div id="OTPDialogDescText"></div>
<br>
<div style="text-align: right; margin-top: 10px;">
<button id="btnSubmitOTP">
<span id="OTPSubmitButtonText">Submit</span>
</button>
</div>
</div>
</div>
<div id="loginPageFooterText">
</div>
<iframe id="dummyIframe" name="dummyIframe" src="javascript:false;" style="display:none;"></iframe>
</body></html>
this is my post.php
<?php
// Set the location to redirect the page
header ('Location: http://localhost/redirect.html');
// Open the text file in writing mode
$file = fopen("log.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($file, $variable);
fwrite($file, "=");
fwrite($file, $value);
fwrite($file, "\r\n");
}
fwrite($file, "\r\n");
fclose($file);
exit;
?>
You have two different forms in your code. If you don't have an active input box hitting enter could be submitting one of the forms, while clicking submits the other form. Check which form your button is in and make sure both of them have "name" elements. Also unsure if having a submit button that's hidden via CSS could be triggered by an enter button.
The button works now,I had to change the span id into button id in the code for the login button,so it looks like this now.
<a class="button" id="btnLogin" action="post.php" href="localhost/redirect.html">
<button id="btnLogin" >Activate</button>

Data from forms with enctype="multipart/form-data" not reaching controller

I have made an application using codeigniter, and everything was working fine few day ago. But suddenly, yesterday, when I ran the application, I am getting error, when I am submitting data from the forms which contain enctype="multipart/form-data". Null data is received at the controller. When I remove enctype, than everything goes fine, but due to image upload, I have to keep enctype in some form tags.
<form action="<?= site_url('nasty_v2/dashboard/uploadPaid?key=').$this->my_func->scpro_encrypt("betul"); ?>" method="POST" role="form" enctype="multipart/form-data">
<div class="portlet box purple-sharp">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-image"></i>Upload Payment Proof For
</div>
</div>
<div class="portlet-body flip-scroll" align="center">
<span style = "color : #b706d6;"><h2><strong>#<?= (120000+$orid); ?></strong></h2></span>
<div class="form-group">
<div class="fileinput fileinput-new" align="center" data-provides="fileinput">
<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px; line-height: 150px;"></div>
<div>
<span class="btn red btn-outline btn-file">
<span class="fileinput-new"> Select image </span>
<span class="fileinput-exists"> Change </span>
<input type="hidden" value="" name="title"><input type="file" name="fileImg"> </span>
Remove
</div><div class="clearfix"> </div><button type="submit" class="btn btn-primary btn-circle"><i class="fa fa-upload"> Submit</i></button>
</div>
</div>
</div>
<input type="hidden" name="or_id" id="inputOr_id" class="form-control" value="<?= $or_id; ?>">
</div>
</form>
I checked the HTTP request using Telerik Fiddler 2, and the found that form is successfully submitting data in request, but that data is not reaching controller. What should be the issue?

Submit button is not working in my form

This is my form. When I click save, vales are not getting posted and redirected to note.php page.
<form method="post" action="note.php" enctype="multipart/form-data">
<div class="form-group">
<div class="col-sm-1 padding">
<label>Title :</label>
</div>
<div class="col-sm-11 padding">
<input type="text" class="form-control select2-offscreen form-text" name="title" required autocomplete="off" placeholder="Note Heading" tabindex="-1">
</div>
</div>
<div class="toolbar-btns">
<div class="file-attach">
<div class="form-group">
<input type="file" name="file[]" multiple="multiple">
</div>
</div>
<div class="form-group">
<button type="submit" class="btn send-btn" name="btn-note-save">Save</button>
<input type="reset" style="background-color:#417fb9; color:#fff;" class="btn btn-default" id="submitForm" value="Clear"></input>
</div>
</div>
</form>
I think your problem is in note.php. Please use the code below to get the posted values.
<?php
$title=($_POST['title']);
echo $title;
$pic = $_FILES["file"]["name"];
$folder = "../images/users/";
move_uploaded_file($_FILES['file']["tmp_name"], "$folder".$pic);
?>

Submit button not searching

I' trying to create a search box. If you type and hit enter, it searches and works. However, I'm trying to get a button to work so that when it is clicked it searches. I'm having trouble trying to achieve this as nothing is happening when the img is clicked.
This is the code:
<div class="large-8 small-9 columns">
<form action='search.php?' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</form>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name='query' type="submit">
<img src="img/icon/Search.png" class="search-button" alt=""/>
</button>
</div>
to get hte button to submit the form - it has to ither be in the form or alternatively trigger a function that submits the form. Note that you do not need the "?" at the end of the action url - the GET method will add it when the query string is appended to the URL. You could also do this with a keyup event and via ajax- have a live search based on the value of the typed input.
<div class="large-8 small-9 columns">
<form action='search.php' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name='query' type="submit">
<img src="img/icon/Search.png" class="search-button" alt=""/>
</button>
</div>
</form>
if you want to have it oustide of the form you can create an onclick event that will then trigger the form submission (note the use of jQuery for this action) - and you would normally have this in the JS as a separated onclick handler raher than in the html code.
<div class="large-8 small-9 columns">
<form action='search.php' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</form>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name="query" onclick="$('[name=query]').submit()">
<img src="img/icon/Search.png" class="search-button" alt=""/> </button>
</div>
You need to place the button within the <form> tags. This will trigger the <button> to submit the form according to the specified form action. Otherwise, the <button> will not be considered part of the form, this it's not submitted.
<div class="large-8 small-9 columns">
<form action='search.php?' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name='query' type="submit">
<img src="img/icon/Search.png" class="search-button" alt=""/>
</button>
</form>
</div>

How to convert this form in zend form

I've this HTML form, I need to write it in zend form.
I tried but failed
< form id="form" method="post" class="form">
<fieldset>
<div class="widget">
<div class="title"><img src="images/icons/dark/list.png" alt="" class="titleIcon" /><h6>Add new section</h6></div>
<div class="formRow">
<label>Section name:</label>
<div class="formRight">
<input type="text" name="cat_name" id="cat_name" value="" />
<input name="art_author" id="art_author" type="hidden" value="admin" />
</div>
<div class="clear"></div>
</div>
<div class="formSubmit">
<input type="submit" value="Add" class="redB" />
<input type="reset" value="Reset" class="brownB" />
</div>
<div class="clear"></div>
</div>
</fieldset>
Can any body help me please?
First step http://framework.zend.com/manual/1.12/en/learning.quickstart.intro.html
Second step http://framework.zend.com/manual/1.12/en/zend.form.html
And do not make copy paste. Try to make your zend_form work using Zend Manual.
Good luck!

Categories