• Problem:
    I have a switch statement to check if form field names are empty. There’s one form that if it’s not empty, and it has an illegal file name (contains apostrphes, commas, etc…) I’d like to display a popup alert box telling them to use a different file name. I tried using this code below to create the alert box,

    echo '<script type="text/javascript">alert("Your message has been sent!");</script>';

    and it took down my whole site.

    More Info.:
    I’m using the resume submissions and job postings plugin, and here is the code/psuedocode of what I would like to happen

    function formErrorCheck( $fields ) {
    
    	$array = get_option( 'resume_input_fields' );
    
    	foreach ( $array as $item => $key) {
    
    		switch($item){
                            case 'attachment':
                                                    //if field is empty, error = true
    						if ( !$fields['attachment'][0]['name'][0] && $key[1] == 1 )
    							$error = true;
                                                            break;
    		                                //else field is not empty, check for invalid characters and throw alert box if field contains invalid chars.
                                                    else ( //parse field string for invalid chars
                                                             if(invlid chars found)
                                                                     //throw alert box

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been damaged by the forum’s parser.]

Viewing 1 replies (of 1 total)
  • The best way to do this is a bit different to what you want to do.

    What you should do is not worry about validating file names before the file is uploaded, and then when it’s saved, save it with a file name that replaces or removes and “illegal” characters. That way you’re removing one big block from people uploading their files to your site. (I’ve seen lots of people, myself included, leave sites because of over-active field validation that’s not really needed)

Viewing 1 replies (of 1 total)
  • The topic ‘Alert box on condition’ is closed to new replies.