Submit button for my contact form is not submitting and redirecting - forms

I'm working on my second website and throughout creating this one and my first the people here on StackOverflow have been an amazing help.
I can just browse and find almost anything I wan't to know.
99% of problems I've had, I fixed with answers I've read on here.
So first of thank you all so much!
This is the first time I'm posting something because I'm not able to find the specific answer for my code.
There are people one here with the same problems but when I look at their code I'm just lost.
I know html a fair bit by now. It's the php that I'm clueless about.
I'm not looking for something fancy, I'm just trying to create a simple contact form.
So here is my question and code, I hope some of you are able to help me.
I used an PHP code from a youtube tutorial and it's deadeasy (as said before: first time PHP) yet I can't get it to work. Although I'm doing everything the same as the man in the clip. He shows his is working so I'm extremely curious as to way mine is not?
My form does not 'send' and after clicking the submit button I don't get the 'thank you' line.
here is the html:
<form method="post" action="contactform" name="contactform" id="contactform">
<ol>
<li>
<label for="voornaam">Voornaam</label>
<input type="text" name="voornaam" />
</li>
<li>
<label for="achternaam">Achternaam</label>
<input type="text" name="achternaam" />
</li>
<li>
<label for="telefoon">Telefoon Nummer</label>
<input type="text" name="telefoon" />
</li>
<li>
<label for="email">E-mail Adres</label>
<input type="text" name="email" />
</li>
<li>
<label for="bericht">Type hier je bericht</label>
<textarea name="bericht"></textarea>
</li>
<li>
<input name="submit" type="submit" value="submit" />
<input name="reset" type="reset" value="reset" />
</li>
</ol>
</form>
and the PHP:
<?php
$voornaam = $_POST ['voornaam'];
$achternaam = $_POST ['achternaam'];
$telefoon = $_POST ['telefoon'];
$email = $_POST ['email'];
$bericht = $_POST ['bericht'];
$to = "felicevancuyk#gmail.com";
$subject = "dkl groep bericht";
mail ($to, $subject, $bericht, "From " . $voornaam . $achternaam . $telefoon};
echo "Bedankt. We nemen zo snel mogelijk contact met u op.";
?>

It could be that your action is not set correctly:
<form method="post" action="contactform" name="contactform" id="contactform">
This action tag is the URL that the form is sent to. In the above example you gave, it doesn't appear to be a file name. You want it to be something like this:
<form method="post" action="http://mysite.com/process-form.php" name="contactform" id="contactform">
Also note that in your example PHP code you are emailing responses to the form without cleaning those responses. Someone could send malicious code to your server if you don't clean the data first.
Something like:
$cleaned_voornaam = preg_replace("/[^ 0-9a-zA-Z]/", "_", $_POST['voornaam']);
Good luck!

You have to just change your action attribute of first line of code to the page where you want to process your form. It may be the same page but it is recommend to be on another page. Here is an example to submit the form in the same page:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="contactform" id="contactform">
Don't forget if you are submitting on the same page as like the above example then your page should be in .php extension otherwise it will not work.

Another case for submit not submitting is that html is malformed.
Just happened that my code was inserting a php error in the middle of my html form.
fixed the error, the submit is working again.
In my case, no js involved at all

Related

Not able to post magento reviews, request looks right

We are using magento 1.8.1 and hosting it both locally in an iis/mysql environment and also testing in an ubuntu lamp environment, so we can verify it is not an iis issue. It happens on both environments.
I got up to the point of integrating the product listing page, where we want to show product reviews and the product review fonts, so users can give their reviews without clicking on a link to go to a different page to add it. I managed to load the product reviews blocks. At first the form element of the add to product button was mixing up with the product review form, which i solved by closing the previous form before starting the review form. I can see in Fiddler the request going through and the action on the form element looks like this
http://localhost/index.php/review/product/post/id/2/
While this will actually make the browser send the request (as seen on fiddler, with the right amount of parameters), the review is never stored in the database, so i cannot see it in the pending reviews part of the admin section. After examining both my store's html source and the online demo, i could see there was a hidden form field on the official demo storing the form_key , which i added since, but it still will not work.
Any hints where to look at?
the whole reviews form block looks like this:
<form action="http://localhost/index.php/review/product/post/id/2/" method="post" id="review-form">
<fieldset class="">
<h3>You're reviewing: <span>Powermonkey extreme 2</span></h3>
<ul class="form-list">
<li>
<label for="nickname_field" class="required"><em>*</em>Nickname</label>
<div class="input-box">
<input type="text" name="nickname" id="nickname_field" class="input-text required-entry" value="">
</div>
</li>
<li>
<label for="summary_field" class="required"><em>*</em>Summary of Your Review</label>
<div class="input-box">
<input type="text" name="title" id="summary_field" class="input-text required-entry" value="">
</div>
</li>
<li>
<label for="review_field" class="required"><em>*</em>Review</label>
<div class="input-box">
<textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"></textarea>
</div>
</li>
</ul>
</fieldset>
<div class="buttons-set">
<button type="submit" title="Submit Review" class="button"><span><span>Submit Review</span></span></button>
</div>
</form>
We have the same problem, and I solved it.
Magento has a form key when submitting any information to the database. To generate the form key, add this code:
<?php echo $this->getBlockHtml('formkey') ?>

Can you tell me how to find out where form info goes?

Thank you for taking a look at my post. I have this newsletter form and it appears to be working fine, but I don't know where the information goes!
<form id="subscribe-form" name="sibscribe" method="post">
<label>
<input class="subscribetext" type="text" onFocus="if(this.value =='Enter E-mail:' ) this.value=''" onBlur="if(this.value=='') this.value='Enter E-mail:'" value="Enter E-mail:" name="keyword" />
</label>
<a onClick="document.getElementById('subscribe-form').submit()" class="button" href="Thank You.html">subscribe</a>
</form>
The best way to figure out for you is to go to Firebug Net bug while the page/form submits and inspect the tabs like:
Params| Headers|Responses|XML|Cookies

How do I get this Newletter Form to work?

I'm not sure what to put in for href:\ Should I reference a mailhandler.php or use a mailto: command? Or is there something better?
<h3 class="margin-bot">Newsletter!</h3>
<form id="subscribe-form" name="sibscribe" method="post">
<label><input class="subscribetext" type="text" onFocus="if(this.value =='Enter E-mail:' ) this.value=''" onBlur="if(this.value=='') this.value='Enter E-mail:'" value="Enter E-mail:" name="keyword" /></label>
<a onClick="document.getElementById('subscribe-form').submit()" class="button" href="#">subscribe</a>
</form>
I think it is meant for the site to which you get after pressing the subscribe button. Preferably the page the form was implemented in (for example to return to the index.html).
You can try it by testing it here on jsfiddle (http://jsfiddle.net). Just put an URL in the field where now is the # and after pressing subscribe you will see that you'll be redirected to that page.

Clicking submit clears file field instead of submitting the form (IE9)

I got a weird error I hope you guys can help with.
Sometimes when the user tries to submit a form the file upload field image just clears and nothing happens. I doesn't seems like the form get submitted at all.
Then the day after everything works fine. The error occurs on random days/times.
First I thought it was a problem with the users computer but this happens on two different computers the customer has. One of the computers has Windows 7 professional & Internet Explorer 9. I don't have the setup on the other one.
I have tried with Google Chrome, Firefox 6.0.2, Internet Explorer 9, 8 (browser compatibility mode), 7 (browser compatibility mode) on windows 7 home with no problems at all on my computer.
Here is the form:
<form action="/user/image" method="post" accept-charset="utf-8" class="form_default" enctype="multipart/form-data">
<fieldset>
<ol>
<li>
<button type="submit" name="save" value="submit" class="button">Save</button>
</li>
<li>
<label for="image">Profile image</label><input type="file" id="image" name="image" />
</li>
<li>
<button type="submit" name="save" value="submit" class="button">Save</button>
</li>
</ol>
</fieldset>
</form>
There should be only 1 submit button per form.
So keep 1 save button as type="submit" ,change another to type="button"
Try using input instead of button, good luck!
ex
<input type="submit" name="mysubmit" value="Click!" />
you should use:
<input type="button" onclick="customFunction" />
write what you want to do in customFunction(javascript)
There is no clever workarounds for this, IE9 does not allow a file to be tampered with via JavaScript probably for security reasons.
First of all, pls let us see your php coding to send this form....
Usually form submission errors such as this have server-side coding errors..
Maybe you should check out your PHP coding and see what happens in your
$_POST['save']
area....
Hope this helps... :)

PHPSESSID appears in form arbitrarily

I have a login form written in PHP and each time I start the browser and go to the respective page, the first field of the form is this:
<input type="hidden" name="PHPSESSID" value="session_id_code" />
If I close the window, but I don't restart the browser, this doesn't happen. Any idea what's happening and why?
Thanks!
Form's code:
<?php
if (condition) {
?>
<form method="post" action="">
<dl>
<dt>Email:</dt>
<dd><input type="text" name="useremail" /></dd>
<dt>Password:</dt>
<dd>
<input type="password" name="userpass" /></dd>
<dt class="dt-buttons"><input type="submit" name="button_login" value="Login" class="button" /></dt>
</dl>
<input type="hidden" name="formkey" id="formkey" value="224ca00155w2fcda8906e1e40af03a71" />
</form>
<?php
}
?>
The form is simple HTML and is not dynamically generated.
EDIT2:
As I was saying, when I access the page for the first time after I started the browser, this thing happens. If I refresh the page afterwards, the hidden field doesn't show up.
Is it possible to have something to do with the SSL certificate? And if yes, why some pages/forms behave like this and some don't?
Sounds like you've got trans_sid enabled (transparent session id). Using trans_sid can be a security issue, especially if your site links to external content, or you allow link sharing - it lets a user's session ID leak out as part of the URL, meaning the session is highly vulnerable to hijacking.