How do I add a comment into an IIS Log file? - forms

I have a simple html file on an IIS server that asks a user to enter a code:
<form action="educational_page.html" onsubmit="myFunction()">
Enter CODE: <input type="text" CODEVal="CODEVal">
<input type="submit" value="Submit">
</form>
<script>
function myFunction() {
alert("The form was submitted");
}
</script>
I specifically DON'T want to log what they enter, rather, I just want to know that they clicked the submit button.
This can be easily inferred by reviewing the IIS Logs, but the people I will be providing the logs to may not find it that easy.
What would be helpful is if there was a way for me to add a comment into the IIS Log that said something like:
"User clicked the 'submit' button."
Preferably on the same line the associated line in the log, so they can easily associate the user who clicked.
Is this possible without running code on the server?
I've read some posts doing something similar (Writing to a text file on the server) which appeared to require my running code on the server. I'd rather leave the solution as simple as possible, and not server side.
The rest of the page does what I want. (Loading the educational_page.html)
I just want to have an easy to parse file that the end user can search for usernames that clicked on the submit button thereby indicating they possibly entered the code.

I agree with the suggestion given by Lex Li.
Client-side JS code could not help writing the logs to the Server side. You need to use Server side code in your app to write logs on the Server-side.
Further, you will not be able to edit/modify IIS logs to append some information in it from your app code.
To achieve your requirement, you could try to write Server-side code that could create/write custom logs files and write data to them.
What you are trying to achieve is not possible using JS code and IIS logs.

Related

Send email when submit button is pressed

I have a really simple form that allows a user to input an email address here:
<form method="post" action="http://www.mydomain.com/page2/">
<input type="email" name="email">
<input type="submit" value="Submit">
</form>
This works correctly and it takes the visitor to www.mydomain.com/page2 when the submit button is clicked.
I am trying to get it to email me this input email address also when the submit button is clicked. I understand how to email using PHP but can the action have two urls?
Or is there a simpler way of doing this?
On /page2/ access the email in the global variable $_POST['email']. And then you can send it to yourself with PHP mail(). Example:
mail('myemail#domain.com', 'Someone submitted my form', 'Their email was: ' . $_POST['email']);
If you are stuck somewhere else, let me know and I can update the answer.
Once a form is submitted, you are no longer on that page. You've navigated away.
The other way you can do this is submit the first action via AJAX, then submit the form naturally to the second destination. I would suggest using jQuery to make your AJAX calls since most of the AJAX code is already there for you to use.
Another option is to have page2 be a php script, and have it perform the two actions once it receives the form data. See: Post to another page within a PHP script
I understand how to email using PHP
Then I would recommend writing some PHP code that sends the email to you.
but can the action have two urls?
No. A web browser can't make two requests at the same time. Which response would take precedence?
Nor does it need to. Now, you have a target already:
http://www.mydomain.com/page2/
Don't you control that page? That would be the page on which you'd put your PHP code for sending an email. If you don't control that page, then you would want an intermediary page. Something like:
sendmailandredirect.php
(Named solely to illustrate intent, you can call it what you like.) What this page would do is send the email, then issue a redirect to your final target. Something like:
header('Location: http://www.mydomain.com/page2/');
In effect, there would be "two urls" but they're invoked in serial instead of in parallel.
If you wanted to keep the code seperate and the action url as /page2/ you could fire off an ajax request on submit to your sendmail handler.

Prevent double form submission when coding in wordpress

I'm currently using wordpress 3.5 and creating a page template of my own. I have my own form in that template and when I click the submit button, it is successfully saved the data to my database. Unfortunately, when I click F5 or refresh button on my browser, It prompts an alert which says there will be a double form submission if I continue.
Usually I prevent this by using "redirect to the same page after submitting" technique. But I can't use header("location: ") to redirect because it generates error: Warning: Cannot modify header information - headers already sent by. Probably there are echos on other wordpress file that prevent redirecting.
Does anyone know how to solve this? Or does anybody know other technique to prevent double form submission beside redirecting?
I've always done this with Javascript:
<?php if(isset($_POST['submit_flag'])){ ?>
<script type='text/javascript'>
window.location='URL';
</script>
<?php } ?>
But now that I think about it, you could easily create another PHP page somewhere in your theme that's not included by the rest of your theme to handle the form data and re-direct back to your form.
I'm also about 98% sure that you can include $wpdb without sending headers by simply requiring "wp-blog-header.php".
There is no output besides in your template file. What would that be? Look at the source code of your website, it's only exactly what you tell Wordpress to create.
So that's first: you can use header("Location: ") at the top of the template file that's called on first. Usually header.php.
Secondly, you can (and usually should) use hooks to handle forms. For example:
add_action( 'init', function() {
// Handle stuff
} );
But perhaps with a different hook (I don't recall any best practice). Tutorials here and there will give you suggestions. In this case you will definitely call header("Location: " ) before there is any output. Your theme hasn't even been involved yet.

Simple ASP Textbox Call

i am a front-end coder, so i don't know much about ASP
one of my clients called me for a simple help and i didn't refuse him.
What he wants is a simple text box with a submit button, and when he submits a text, lets say "Sample", he wants the server to call http://example.com/Sample.pdf after submission.
Simply, that is what i have at the moment:
<form action="form_action.asp">
<input type="text" name="pdf" value="enter pdf id" />
<input type="submit" value="Submit" />
</form>
It would be better if i can get a working answer as i don't have asp server on my computer, i will not be able to test it.
Any help will be appreciated. Thanks.
This is a very bad idea, especially when the implementer doesn't have an understanding of back-end coding. You are opening up the server to a whole heap of security issues.
If you allow anything to be put in this box, what would stop me entering ../includes/dbsettings.asp for example and getting access to files I really shouldn't have access to?
How will you handle if the file doesn't exist?
Actual Answer: This is a Q&A site, so here is the answer you requested, be careful what you do with it!
The following in it's own ASP page should do what you want:
<%
Response.Redirect("/" & Request.Form("pdf") & ".pdf")
%>
You can (and should) get more complex by setting mime type, designating it as an attachment (so a download box is spawned), streaming the file and above all adding security and error checking.

Joomla module submit form can't access database

I've been searching the net for an answer to my question but I just can't seem to find one, even though it's probably pretty simple.
I have a joomla module that signs up users to a newsletter, when clicking the submit button I navigate to submitsignup.php file. I do this using the form action value like so:
form action="modules/mod_cmsnewslettersignup/otherfiles/submitsignup.php" method="post" id="subForm"
Within this submitsignup.php file I can not access any joomla classes, such as:
$db = JFactory::getDBO();
I know that I can't access any joomla classes because I made direct access to the submitsignup.php file, but I was wondering how do I access this file so that I can have access to all the Joomla classes?
Thanks.
If you are reloading the page when you submit the form, then there is a simple solution that solves both the problem of using a direct URL and of having to load the Joomla framework in that file. Basically change your module code to something like this -
if ($_POST["formsubmitted"]){
the code you run when the form is submitted
echo success or failure message
} else {
the code you run to display the form
<form action="<?php echo JURI::current(); ?>" method="post">
<input type="hidden" value="true" name="formsubmitted">
}
Basically, you submit the form to the page that displays it. Then in your module you add a hook to either process the submitted form or display the form depending on what you find in $_POST. You can add some simple security to make sure that the form is being submitted from your site.

using form buttons for spamproof email-addresses

I have been looking at some methods for spamproof email methods here. I'd like to propose a more simple approach: Since I need a couple of different email addresses I considered just using a selectbox with JS or serverside redirect, as per examples on here.
Because google doesn't spider forms (dixit Matt Cutts), and spam-harvester script don't either (I think????) this would make sense to do.
I would love to be able to do this without using a script. So why not use one form per email?
<form action="mailto:test#domain.tld" method="get">
<input type="submit" value="test#domain.tld"/>
</form>
It seems the button text can be copied but not pasted, so that's a disadvantage.
Is this approach any good? or any other recommendations?
A robot uses the text of the page to get the email. It does not care if that text is in a button or within the body so using a button will not help.
Outside of using javascript, the only solution I know of would be written text, an image or Flash.
Create an image with your email or write out the email like: "test at domain dot tld"
Flash could provide you with a more secure (but not 100%) way of allowing people to click on an email but would not work on iPhone browsers and those that do not have the plug-in.
Another way is to use a simple captcha to before displaying the email in the PHP code.
Email: (1+2 = ?) then test#domain.tld
Because:
The email address is still in the page, and thus easily harvestable
mailto: URIs as form actions often fail
The reason server side form handlers stop email addresses being harvested is because the email address is not exposed to the user.