Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

JavaScript .send() not posting form


ShadowGate's Avatar
Member
0 0

I have a form that has an anchor styled as a button and I am trying to submit the form via javascript. I am able to send the form using an input tag or a button tag. The button comes the closest to matching the anchors style but I have not been able to get them to look the same. I would really like to use the anchor if I can, please help.

<?php
	require_once("../content/includes/validation.php");
?>

<!DOCTYPE html>
<html lang="en">
    <head>
    	<title>Contact | Buffalo Bridal Association</title>
        
        <meta charset="utf-8" />
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <meta name="author" content="" />
        <meta name="robots" content="" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
        
        <!--<base href="http://localhost/buffalobridalassociation/" />-->
		<base href="http://hooksshoes.com/bbatest/" />

        <link rel="icon" href="content/images/favicon2.png" />
        <link rel="stylesheet" href="content/styles/reset.css" media="all">
        <link rel="stylesheet" href="content/styles/layout.css" media="screen" />
        <link rel="stylesheet" href="content/styles/site.css" media="screen" />
        
        <script src="content/scripts/jquery.js"></script>
        <script src="content/scripts/document_ready.js"></script>
    	<script src="content/scripts/cufon-yui.js"></script>
    	<script src="content/scripts/cufon-replace.js"></script>  
    	<script src="content/scripts/Josefin_Sans_400.font.js"></script>
    	<script src="content/scripts/Tangerine_700.font.js"></script>
    	<script src="content/scripts/atooltip.jquery.js"></script> 
    	<script src="content/scripts/jquery.nivo.slider.pack.js"></script>
    	<script src="content/scripts/script.js"></script>
    	<!--[if lt IE 9]>
        	<script type="text/javascript" src="js/html5.js"></script>
        	<style type="text/css">
            	.aToolTip, .box1, .box1 .inner { behavior: url(js/PIE.htc); }
        	</style>
    	<![endif]-->
    	<!--[if lt IE 7]>
        	<div style='clear:both;text-align:center;position:relative'>
            	<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"><img src="http://www.theie6countdown.com/images/upgrade.jpg" border="0" alt="" /></a>
            </div>
    	<![endif]-->
    </head>

    <body id="page6">
        <div class="body1">
            <div class="main">
                <header>
                    <div class="wrapper">
                        <h1><a href="site/index.php" id="logo"></a></h1>
                        <nav>
                            <ul id="menu">
                                <li class="first"><a href="site/index.php">Home</a></li>
                                <li><a href="site/members.php">Members</a></li>
                                <li><a href="site/shows.php">Bridal Shows</a></li>
                                <li id="menu_active"><a href="site/contact.php">Contact</a></li>
                            </ul>
                        </nav>
                    </div>
                </header>
            </div>
        </div>
        
        <div class="body3">
            <div class="main">
                <article id="content">
                    <div class="wrapper">
                        <div class="pad">
                            <div class="wrapper">
                                <section class="col1">
                                    <h2>Contact <span>Form</span></h2>
                                    
                                    <?php include("../content/includes/contact-email.php"); ?>
                                                                        
                                    <form id="ContactForm" action="site/contact.php" method="post">
                                        <div>
                                            <div class="wrapper">
                                                <span><label for="name">Name:</label></span>
                                                <input type="text" class="input" id="name" name="name" />
                                            </div>
                                            <div class="wrapper">
                                                <span><label for="email">Email:</label></span>
                                                <input type="text" class="input" id="email" name="email" />								
                                            </div>
                                            <div class="textarea_box">
                                                <span><label for="message">Message:</label></span>
                                                <textarea name="message" id="message" cols="1" rows="1" placeholder="Tell us about your experience with our Member businesses."></textarea>								
                                            </div>
                                            <button type="submit" value="submit" name="submit" class="button" id="submit"><strong>Send</strong></button>
											<a href="javascript:document.getElementById('ContactForm').submit();" class="button" name="submit" id="submit"><strong>Send</strong></a>
                                            <a href="javascript:document.getElementById('ContactForm').reset();" class="button"><strong>Clear</strong></a>
                                        </div>
                                    </form>
                                    <p style="margin-top:75px;"><strong>Wedding professionals, not a member of the BBA, what are you waiting for?</strong><br /><a href="http://www.buffalobridalassociation.com/BBA_Application.pdf">Get your membership application today!</a></p>
                                </section>
                                
                                <section class="col2 pad_left2">
                                    <h2>Our <span>Info</span></h2>

                                    <div class="wrapper pad_bot1">
                                        <p class="address">
                                            Telephone:<br>
                                            Fax:<br>
                                            E-mail:
                                        </p>

                                    </div>
                                    <h2>Your <span>Feedback</span></h2>
									<p class="pad_bot1">All Members of Buffalo Bridal Association subscribe to a <a href="site/ethics.html">Code of Ethics</a> by which they pledge themselves to honesty and integrity.<br /><br />BBA Members acknowledge that their customers rely on their knowledge, experience and recommendations, and pledge not to betray the trust of their customers.</p>
                              </section>
                            </div>
                        </div>
                    </div>
                </article>
            </div>
		</div>
        
        <?php
			include("../content/includes/footer.php");
		?>
    </body>
</html>```

lolly's Avatar
Member
0 0

HAI THERE

https://maps.google.com/maps?q=94+Muskingum+Depew,+New+York+14043&layer=c&z=17&iwloc=A&sll=42.908565,-78.686541&cbp=13,282.8,0,0,0&cbll=42.908562,-78.686521&hl=en&ved=0CAoQ2wU&sa=X&ei=gW0RUfCZD4PlwAGYqIHQBA

http://www.facebook.com/travusgonzalez

</creepy>//lulzzzz

Edit: but to answer your question, you can't use: markup&lt;a href=&quot;javascript:document.getElementById(&#39;ContactForm&#39;).submit();&quot; class=&quot;button&quot; name=&quot;submit&quot; id=&quot;submit&quot;&gt;

you would have to do something like onClick='document.form[0].submit()'


ShadowGate's Avatar
Member
0 0

Ok first off not sure what the point of posting my facebook was but ok.

secondly I have tried both the inline javascript link and the onclick function, neither work.


lolly's Avatar
Member
0 0

if you put the onclick attribute on the anchor, not the <a> tag, it will work.


ShadowGate's Avatar
Member
0 0

Please explain (code example maybe) as I was under the impression that the <a> tag is an anchor. In fact I believe the 'a' stands for anchor.


lolly's Avatar
Member
0 0

I meant the button tag, not anchor.

Anyways, as long as you're linking to the correct form, this WILL work:

<a href="#" onclick="document.forms[0].submit();">Submit</a>


ShadowGate's Avatar
Member
0 0

I am linking to the correct form and it does not work.


lolly's Avatar
Member
0 0

what does

<a href="#" onclick="alert(1);">Submit</a>

do?

If it doesn't alert anything, then there is some weird CSS or something that's blocking the event.

If it does alert 1, then you're not linking the form correctly.

Just play around with it in firebug and you'll figure it out.


Euforia33's Avatar
philalethes
0 0

I've come across this before, the problem is the name of the button. You can not call it submit while using submit() as you are basically overriding the method. Change it to something like: <button id="formsubmit" class="button" name="formsubmit" value="submit" type="submit"> and it should work.

Edit: Pen testing new fetures.


ShadowGate's Avatar
Member
0 0

Ok so I believe the javascript is working fine, and as it should. I think the problem is how I expected the php to pick up the submit.

 ... Send email ...
}```

I don&#39;t think the POST varable is being set to submit. Why is this and how can I fix my php to work with the way javascript submits the form?

ynori7's Avatar
Future Emperor of Earth
0 0

ShadowGate wrote: Ok so I believe the javascript is working fine, and as it should. I think the problem is how I expected the php to pick up the submit.

 ... Send email ...
}```

I don&#39;t think the POST varable is being set to submit. Why is this and how can I fix my php to work with the way javascript submits the form?
Try putting this before the if statement:
```markupvar_dump($_POST[&#39;submit&#39;]);die; ```
Then try again. If it shows you something like &quot;NULL&quot; then your post parameter wasn&#39;t set. If you have a value, then there was something wrong with your emailing function (such as trying to send emails without having an SMTP server). If you see nothing at all then you probably never even reached that point in the code and your problem is somewhere else.

By the way, your initial problem could have been related to the fact that Firefox no longer allows javascript to be executed through the URL by prefixing it with &quot;javascript:&quot;.