• Hi,

    How would I retain the value if a user submits a form and makes an error in the submission. For example, a user fills out his first, last, name but forgets his email address. I don’t want the user to have to fill out his first, last name again.

    My question is, I’m having a hard time figuring out the above logic in WP. In the below code if a user submits his name and presses submit and forgets a part of the form his first name won’t be avail. and he has to write it again. In my below code, how do I fix this?

    if(trim($_POST['contactName']) === '') {
    
    			$nameError = __('You forgot to enter your name.','language');
    			$error_message .= 'Your Name\n';
    			$hasError = true;
    
    		} else {
    
    			$name = trim($_POST['contactName']);
    
    		}
    <div class="pro_fields">
              <li>
                <label for="contactName">
                  <?php _e('Name','language');?>
                </label>
                <br/>
                <?php $contactName = $_POST['contactName'];
    					if($contactName != '' && $contactName !='Please enter your name'){
    						$contactName = $_POST['contactName'];
    					}else{
    						$contactName = 'Please enter your name';
    					}
    				?>
                <input type="text" name="contactName" id="cs_contactName" class="field" value="<?php echo $contactName; ?>" class="requiredField" onblur="if(this.value == '') { this.value = 'Please enter your name'; }"  onfocus="if(this.value == 'Please enter your name') { this.value = ''; }" />
                <?php if($nameError != '') { ?>
                <span class="error">
                <?=$nameError;?>
                </span>
                <?php } ?>
              </li>
            </div>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Form submission and retaining information the user has submitted’ is closed to new replies.