Page 1 of 1
HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 7:16 am
by Phantom
Hi guys,
Okay, this is at least 30 hours worth of trying different combinations of things to discover that for some reason when I apply the CSS rules, it prevents PHP from firing. I've tried nearly all the combinations I can and now need to turn to the professionals.
So I have a simple email script at the top of the page
Code: Select all
<?php
if (isset($_POST['submit']))
{
$field_name = $_POST['name'];
$field_message = $_POST['message'];
$mail_to = 'testaccount@isgaust.net.au';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_name."\r\n";
$headers .= 'Reply-To: '.$field_message."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert($field_name);
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to 'testaccount@isgaust.net.au');
</script>
<?php
}
}
?>
So simple emailing script, and then the form to match.
<h2>Contact form</h2>
<form id="contact-form" action="#?name=test" method="POST">
<div class="success"> Contact form submitted! We will be in touch soon.</div>
<fieldset>
<label class="name">
<input name="name" type="text" value="Name:">
<span class="error">*This is not a valid name.</span>
<span class="empty">*This field is required.</span>
</label>
<label class="message">
<textarea name="message">Message:</textarea>
<span class="error">*The message is too short.</span>
<span class="empty">*This field is required.</span>
</label>
<div class="btns"><a class="button" data-type="reset">clear</a></div>
<input type="submit" name="submit" value="Submit" />
</fieldset>
</form>
So, in the HTML, I have ID="contact-form". The PHP works perfectly with that property removed, but, obviously I want it in there AND the PHP working.
Any ideas???
Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 7:20 am
by Phantom
Oh, and the reason my reset and submit buttons aren't in the same div is because I was testing whether the 'data-type' property of that button originally was the problem as apposed to just 'type'.
As it seems, not a whole lot of difference.
Thanks, all.
Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 9:13 am
by social_experiment
It works for me with and without the value you refered to; by "prevents the PHP from firing" do you mean you cannot send the email if this value is present in the script?
Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 9:59 am
by Phantom
That's correct. Even if I modify the php and remove everything and just have echo 'hello world' it won't fire if I have the ID="contact-form" in the HTML. Any ideas what could be running interference?
I did get the original code as a template. I want to keep the designer's original css scheme but anything I do to get the email functionality working mucks up the desired stylesheet properties.
Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 10:02 am
by Phantom
Or the other answer that might be easier to ask is how do you think the designer anticipated getting the email to send? I'm assuming through PHP but is there another method? I know javascript can't do it. HTML only launches outlook and that's not what I'm after.
*Sigh* ASPX is simple. I'll give that to Microsoft! They've got a simple emailing framework.
Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 1:11 pm
by twinedev
Do you have any JS acting upon the form? Do you have anything else on the page with the same ID? Without seeing the actual page (or you posting the entire contents of doing View>Source here to see what all is working on the page and what items exist), will be tough to tell.
I'm willing to bet that when you find the solution, you will see it isn't a matter of comparing ASPX vs PHP, as like you said, even if you just change it to an simple echo statement that isn't working, so has nothing to do with the "mail" part. (and I'm one of those who doesn't argue one is better than the other like some people, just saying I believe it to not be relevant here)
If you want, PM the url.
-Greg
Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 4:24 pm
by Phantom
Hey, thanks Greg. I don't mind directing you straight there. It's
http://www.isgaust.net.au/contact.php.
If it's a matter of a control with the same ID you'd think Dreamweaver would alert you to that. So anyway, that's the page with the said php script...having said that, 'view source' won't show you the PHP so you'll have to trust me it says this:
Code: Select all
<?php
if (isset($_POST['submit']))
{
$field_name = $_POST['name'];
$field_message = $_POST['message'];
$mail_to = 'testaccount@isgaust.net.au';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\r\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_name."\r\n";
$headers .= 'Reply-To: '.$field_message."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
}
?>
Now what I want it to behave like is on this url:
http://www.isgaust.net.au/OriginalContact.html
For the repetitive nature of my tests, I took out the 'mobile' and 'email' fields in the former form.
Thanks for your input.
- Oliver
Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 4:27 pm
by Phantom
Oh, if the css in the 'Source' is contrary to what I indicated originally, I've been playing around with it, trying to see if another way of referencing the css would help it work.
No dice.

Re: HELP! CSS prevents PHP script firing
Posted: Wed Jul 04, 2012 4:43 pm
by social_experiment
Below is the code i used; try it without any stylesheets linked to the page although i doubt that a problem with styling and css could effect a php script in this manner
Code: Select all
<?php
if (isset($_POST['submit']))
{
$field_name = $_POST['name'];
$field_message = $_POST['message'];
$mail_to = 'your@mail.addy';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_name."\r\n";
$headers .= 'Reply-To: '.$field_message."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert($field_name);
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to 'testaccount@isgaust.net.au');
</script>
<?php
}
}
?>
<h2>Contact form</h2>
<form id="contact-form" action="#?name=test" method="POST">
<div class="success"> Contact form submitted! We will be in touch soon.</div>
<fieldset>
<label class="name">
<input name="name" type="text" value="Name:">
<span class="error">*This is not a valid name.</span>
<span class="empty">*This field is required.</span>
</label>
<label class="message">
<textarea name="message">Message:</textarea>
<span class="error">*The message is too short.</span>
<span class="empty">*This field is required.</span>
</label>
<div class="btns"><a class="button" data-type="reset">clear</a></div>
<input type="submit" name="submit" value="Submit" />
</fieldset>
</form>
Re: HELP! CSS prevents PHP script firing
Posted: Thu Jul 05, 2012 1:18 am
by twinedev
I did a test submit, and using fiddler, see the following WAS submitted to the form:
name: Thuis is a test
message: My Message
submit: Submit
Then on the raw code from your site the word "alert" was no where in the code, so based upon what you put it is never getting into the
if (isset($_POST['submit']))
line (as that will hit a point where one or the other alert is echoed out, so I should see the it in the source.
Can you post everything in the .php file up to and including that if statement?
-Greg