1

My submit button with an image/style does not work. But the test button but I created in addition kinda does something at least.

Background story: I want to use a contact formular on my website. It has a specific style, that I would like to keep. Especially the submit button.

Behaviour of the actual submit button: When I click it, nothing happens.

Test button behaviour: When I click it, it should run my php file and send 2 mails out. To the creator and the webmaster. But it actually just shows me the content of my php file in a new tab. I am not sure if that is because I am running it locally. I have no access to my webserver right now, so I woul appreciate if you can answer me that.

Here is a part of my html code: (If you need more code, just lemme know.) I apologize for all the german words in there.

<form enctype="multipart/form-data" action="kontakt.php" method="POST">
<div style="text-align:left; margin-top:10px; margin-bottom:10px;">
<input type="hidden" name="form_version" value="2" />
<input type="hidden" name="wsite_approved" id="wsite-approved" value="approved" />
<input type="hidden" name="ucfid" value="469466791613027794" />
<input type="submit" value="testabsenden"</input>
<input type="submit" style='position:absolute;top:0;left:-9999px;width:1px;height:1px' /><a class='wsite-button'><span class='wsite-button-inner'>Absenden</span></a>
</div>
</form>

And of course the php part: (i'll just give you the full code, since its not super long)

<?php 
$anrede = $_REQUEST['anrede'];
$name = $_REQUEST['name'];
$nachname = $_REQUEST['nachname'];
$mail = $_REQUEST['mail'];
$nachricht = $_REQUEST['nachricht'];

$empfaenger = "info@input-recordings.de ";
$absender = $mail;

$betreffwebmaster="Kontaktanfrage ($name $nachname)";
$inhaltwebmaster = "$name $nachname hat &uuml;ber die Webseite folgende Kontaktanfrage gestellt: \n\n".
"\n\n
Kontaktdaten: \n
\tName: $anrede $name $nachname \n
\teMail: $mail \n
\n\n".
$nachricht;

$betreffkunde="Kontaktanfrage ($name $nachname)";
$inhaltkunde = "$name $nachname hat &uuml;ber die Webseite folgende Kontaktanfrage gestellt: \n\n".
"\n\n
Kontaktdaten: \n
\tName: $anrede $name $nachname \n
\teMail: $mail \n
\n\n".
$nachricht;

$abgesandt = "<h1> Kontaktbest&auml;tigung</h1><p>Vielen Dank f&uuml;r Ihre Anfrage. Wir werden uns in K&uuml:rze bei Ihnen melden.<br><br>Thank you for your inquiry. We will get back in touch with you shortly!<br><br><br></p>";

mail("$empfaenger","$betreffwebmaster","$inhaltwebmaster","FROM: $absender");
mail("$mail","$betreffkunde","$inhaltkunde","FROM: $absender");
echo $abgesandt;

?>
Quatsch
  • 361
  • 1
  • 8
  • 29
  • your submit button is invalid html -> `` should be `` – Sean Dec 20 '14 at 05:22
  • `But it actually just shows me the content of my php file in a new tab` - I guess your server doesn't run php scripts. – potashin Dec 20 '14 at 05:23
  • see - [PHP code is not being executed (i can see it on source code of page)](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page) – Sean Dec 20 '14 at 05:25
  • @Sean I did that. Same behaviour though. My php text appears in the browser. – Quatsch Dec 20 '14 at 05:26
  • @notulysses I am running it from local right now. Server is able to run php scripts. – Quatsch Dec 20 '14 at 05:27
  • when you say that you are running it locally, does that mean you are running it using `localhost` or are you loading the page as a local file - `file://C:...`? – Sean Dec 20 '14 at 05:35
  • @Sean as local file. That's why it would be good to know if showing my php code is a normal behaviour when running it as a local file. – Quatsch Dec 20 '14 at 05:37
  • @Sean I also checked the link that you sent in your 2nd comment. Nothing there could help me. – Quatsch Dec 20 '14 at 05:42
  • 1
    Yes, it is normal behavior for php to show in your browser if you are accessing it as a local file. You have to set up a local server if you want it to execute/run php code. – Sean Dec 20 '14 at 05:49

1 Answers1

1

You are lacking a web server.

By deafult, your computer cannot read PHP, unlike javascript and html. You will need something to interpret your PHP code into readable markup.

You can easily download either WAMP or MAMP and be up and running in minutes.

Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
  • Alright, I am downloading XAMPP right now since I already worked with that program in the past. Should work, too. Will give feedback as soon as I successfully tested it. Though, is the output of the content of the php file normal, if you don't have a server running? – Quatsch Dec 20 '14 at 05:52
  • Yes, it's interpreted as text/plain in this case which is why you're seeing just the text. Press "F12" to open your developer console, and then check the network tab (may have to refresh). Look at the response from the server, it will tell you the header type. – Ohgodwhy Dec 20 '14 at 05:54
  • I set up an apache XAMPP Server and let everything run. It seemed good. Showed me some error messages at first in the php script. I fixed the errors and it did nothing anymore then. Which means my submit button is working but I didnt get any mail. Any more ideas? – Quatsch Dec 21 '14 at 07:28