SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot keira's Avatar
    Join Date
    Aug 2005
    Location
    QLD - Australia
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Form not sending (javascript validator)

    Sorry, I am a novice at javascript, and this script was mostly put together by my programmer friend, who isn't currently available to help me with this so i'm stumped!

    This form I have has a validator and that part is all working, so that's good, but while I was testing I didn't have it actually submitting and now that I've added the action and the email address to send it to I realise it doesn't even send..

    I think it's actually lacking anything that tells it to send. im using a regular button instead of a submit button. i just need to know where to put the 'submit' function and how!



    here is the HTML for the form:

    Code:
    <form id="form1" name="form1" method="post" action="http://mailgate.server-mail.com/cgi-bin/mailgate"> 
    <input type=hidden name="recipient" value="mail@domain.com">
    <input type=hidden name="subject" value="Radio Survey">
    <input type="radio" name="Group1" value="3AW" />3AW<br>
    <input type="radio" name="Group1" value="2GB" /> 2GB <br>
    <input type="radio" name="Group1" value="None" />N/A, I didn't hear your ad</p>
    <input name="button" type="button" onclick="(doValidate() ? hideModal() : showModal());" value="Submit">
    </form>
    here is the javascript

    Code:
    <script language="javascript" type="text/javascript">
    
        //setup initial modal properties
        var modal = document.getElementById('modalWdw');
     
       
        function showModal()
        {
           modal.style.display='block';
        }
    
        function hideModal()
        {
           modal.style.display='none';
           return true;
        }
    	
    	function doValidate()
    	{
    		var group1Checked;
    
    		for (var i=0; i<document.getElementsByName('Group1').length; i++)
    		{
    	
    			if (document.getElementsByName('Group1')[i].checked)
    			{
    				group1Checked = document.getElementsByName('Group1')[i].value;
    			}
    		}
    
    	
    		if(!group1Checked)
    		{ //if group1Checked does not equal null
    			alert("You did not make a selection.")
    		}
    		else
    		{
    			alert('Thankyou, your selection was: ' + group1Checked);
    			return true;
    		}
    	}	
    
    	showModal();
    	
    
    function checkOnLoad()
    //essentially, this function just scans the current page url and looks
    //  for the querystring (after the '?'), then checks to see if "modal=true"
    //  was included as a querystring key-value pair
    {
        var arr = window.location.href.split(/\?/g);
        if (arr.length >= 2)
        {
           var vals = arr[1].split(/=/g);
           if (vals.length >= 2)
           {
              for (var i = 0; i<vals.length; i++)
              {
                 if (vals[i] == 'modal')
                 {
                    if (vals[i+1] == 'true')
                    {
                       return true;
                    }
                 }
              }
           }
        }
        else
        {
           //no modal
           hideModal();
        }
    
        return false;
    }
    
    (checkOnLoad() ? showModal() : hideModal());
    
    </script>
    
    all that modal=true stuff is to show or hide the div in which the form is in, it only shows if the page is directed from a certain address, and it only disappears if the form is validated.
    
    Can anyone see where I need to insert something to make the form actually SEND to the email adress?
    All it seems to do onclick is check to see if it is validated..
    Last edited by keira; Nov 25, 2005 at 03:14.

  2. #2
    d^_^b Iain G's Avatar
    Join Date
    Nov 2005
    Location
    Gloucester, UK
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just glancing at the form code, change the type of your button to 'submit'. When the script returns 'true', the form doesn't know that it should be submitting itself and does nothing anyway.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The submit should go in place of hideModal of you want to keep the form unusable to those without Javascript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot keira's Avatar
    Join Date
    Aug 2005
    Location
    QLD - Australia
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Iain G
    Just glancing at the form code, change the type of your button to 'submit'. When the script returns 'true', the form doesn't know that it should be submitting itself and does nothing anyway.
    hmm, but the guy who put it together for me had changed it back from a submit button to get the validator to work. before that it was trying to hide the div it lies in before validating it

  5. #5
    SitePoint Zealot keira's Avatar
    Join Date
    Aug 2005
    Location
    QLD - Australia
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall
    The submit should go in place of hideModal of you want to keep the form unusable to those without Javascript.
    does that matter either way though? will it just not do anything if they don't have javascript?

    and how would I make the hideModal work, like where would I move it to?

    sorry for my complete lack of know-how


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •