Results 1 to 4 of 4

Thread: [RESOLVED] Form validating issues; form action to php file negates validation, why?

  1. #1
    Join Date
    Oct 2009

    resolved [RESOLVED] Form validating issues; form action to php file negates validation, why?


    I really could use some help. I realize there are probably lots of posts on validating forms with Javascript, but I have been at this all day and been pouring through Google and I havenít found what Iím looking for Ė I feel like my validation is close, but I just canít get it to work in two areas. They may be related; they may not, but Iím really stuck. I have a contact form (only three fields, name, email, and message). I want to make sure that there is something in each field and that the email is at least sort of legit before the message is sent through.

    Iíve been trying to mesh tutorials and this is what Iíve come up with. However, my ďYour message has been sentĒ alert which I was trying to apply at the end (if everything was verified) never comes through and Iím absolutely stumped. Any pointers would be greatly appreciated.

    <script type="text/javascript">
    function checkform()
    	if (document.contactAPC.name.value == '')
    		alert('Please enter a name.');
    		return false;
    	else if(document.contactAPC.email.value == '')
    		alert('Please enter an email address.');
    		return false;
    	else if(document.contactAPC.message.value == '')
    		alert('Please write a message.');
    		return false;
    	else if(document.contactAPC.email.value != '')
    	emailpattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
    			 alert("Please enter a valid email address");
    			 return false;
    		//Why can't I get this message to show?
    				return true;
    				alert("Your message has been sent.");
    <h2>Contact Us</h2>
    	<form name="contactAPC" method="post" action="" onSubmit="return checkform()"> 
    	Name <input type="text" size="26" id="name" name="name" class="txtfield_details"> 
    	<br /> 
    	<br />Email <input type="text" size="26" id="email" name="email" class="txtfield_details"> 
    	<br /> 
    	<br /> 
    	<br /><textarea cols="24" rows="4" class="txtfield_details" name="message" id="message"></textarea> 
    	<br /> 
    	<br /><input type="submit" value="Submit" name="submit" class="btns" /> 
    	<input type="reset" value="Clear" name="clear" class="btns" /> 
    Now my other issue is that when I attach the php file (below) to the form action (ie. action=Ēmyfile.phpĒ) Ė the form no longer even bothers to remotely try to validate. It just sends the contents straight through and I get my ďYour message has been sent messageĒ and this also confuses me. I thought checkform() needed to come back as true for the submit button to move the user forward.

    $email = $_REQUEST['email'] ;
    $message = 
    $_POST["name"] ."\n". 
    $_POST["email"] ."\n<>".
    $_POST["message"] ."<>";
    mail( "myemail@yahoo.com "From my Website",
    $message, "From: $email" ); 
    header("Location: http://www.mywebsite.org");
    If anyone could shed some light on this, it would make my day. Itís just been over a year since Iíve done Javascript and I never quite got the form validation to work right and it just a bit frustrating.


  2. #2
    Join Date
    Oct 2009

    Problem Solved!

    I knew it was something simple (and quite possibly stupid). A mentor helped me catch the error(s), which resolved both issues.

    For anyone else who might ever have a similar problem. In the last, else-statement, I need to have return true; come AFTER the alert box so that the script does exit before I need the last action to run.

    Also I had (although not on this copy) a comment to hide the javascript from older browsers at the bottom of the script:

     //stop hiding script -->
    I didn't have the comment on it and it was spitting out a error (apparently in Firefox), although IE8 was reading everything fine/no errors, so that's why I was just really confused.

    I love helpful people. Fixing this did really make my evening so much better. : )

  3. #3
    Join Date
    Mar 2010
    //Why can't I get this message to show?
    return true;
    alert("Your message has been sent.");
    I haven't looked at the rest of your code, but your alert() needs to be above the return statement.

    As it is now if the return is executed, the function returns to the calling statement without displaying "Your message has been sent.").

    **** OK you beat me to it ***** My 2 typing fingers aren't quick enough

    We need a DELETE button for posts..!!!!
    Last edited by tirna; 03-22-2010 at 09:38 PM.

  4. #4
    Join Date
    Oct 2009
    [QUOTE]In the last, else-statement, I need to have return true; come AFTER the alert box so that the script does exit before I need the last action to run.

    I mistyped. The part in bold should be does not.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12995 seconds
  • Memory Usage 2,876KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates