Results 1 to 6 of 6

Thread: On Page Alert v Go Back

  1. #1
    Join Date
    Jul 2011
    Irish Republic

    Arrow On Page Alert v Go Back

    My contact form validates in a basic php way as shown at www.webitry.net/contact.html
    How could I go about having the validate alerts, to present at/on the Contact Page so that visitors do not have to use Go Back ?

  2. #2
    Join Date
    Jul 2011
    Irish Republic
    Some additional info further to my earlier submission.

    This is the code that I have been using to work the Go Back validate requirement in the Contact Form!

    || empty($visitormail)
    || empty($visitorphone)
    || empty($notes ))
    echo "<h2>Go Back and fill in all fields </h2>\n";
    echo '<a href="javascript:history.go(-1)"><h3>Go Back to the Contact Form</h3></a><br />'; /*GO BACK BUTTON*/
    die ("Use the Go Back to Contact Form button !! ");

    The question being..... what upgrade is needed to this code to present the alerts on the Contact page?

  3. #3
    Join Date
    Dec 2010
    Have a look at jQuery and the form validation tools for jQuery. Remember, you need to have both validations - javascript to ensure that there are visual reminders for the user to fill in forms in a certain format, and server side validation to ensure they're not trying to do anything nasty to your server.

  4. #4
    Join Date
    Jul 2011
    Irish Republic
    Quote Originally Posted by ralphchadkirk View Post
    ........and server side validation to ensure they're not trying to do anything nasty to your server.
    What nasty things might they try to do?
    What nasty things should we be trying to prevent?
    Is this something to do with sanitizing and what is sanatizing?

  5. #5
    Join Date
    Aug 2004
    One common strategy is to have the form and the form processing in the same file, so that the action attribute of the <form> tag points to itself:
    HTML Code:
    <form method='post' action=''>
    Then you do a check to see if the form was submitted, and if so process it, else, display the form. If there are any errors, display the form instead of continuing to process the inputs.
    PHP Code:
    = array();
    $_POST['submit'])) {  // or whatever other form field you want to use
       // sample validation:
    if(!isset($_POST['name']) or trim($_POST['name'] === '') {
    $errors[] = "You must enter your name.";
    $_POST['email']) or trim($_POST['email'] === '') {
    $errors[] = "You must enter your email.";
    // see if there were any errors
    if(count($errors) == 0) {
    // finish processing form, then redirect to success page:
    header('Location: http://yoursite.com/order/success.php');
    if(count($errors)) {
    $errors as $err) {
    "<p class='error'>".htmlspecialchars($err)."</p>\n";
    <form method='post' action=''>
    <!-- form fields here -->
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  6. #6
    Join Date
    Jul 2011
    Irish Republic
    Now trying to master the single page form processor arrangement. It works until I begin to introduce the captcha! (developed from a randomimage script which combines a background image with text) The script installed into the two page form fairly easily.

    I wish to install and display the following type of error message into the one page processor/form below:

    if (md5($captcha) == $_SESSION['image_random_value']) 
            {/*  echo "<h2>Code $captcha valid </h2>\n"; */}
    	       echo "Link cannot be sent because you entered an invalid Code. Please validate again!\n";
    I am not having any luck with the installation! The first array of error messages (name, email & captcha) work fine, but the captcha processing is snagging and preventing the call or display of the thanku.html.The code is as follows and I have added color to some of the components of the code to facilitate.

    Can I be put back on the right track ?

    /////////// LINK FORM AND PROCCESOR (All on one page) VALIDATION STARTS HERE ////////////////////	
    	$errors = array();
    	function validate_form_items()
    	$form_items = array(		   
    	"name"  => array(
    		"regex" => "/^([a-zA-Z '-]+)$/",
    		"error" => "<i> Appears in an improper format!</i>",),
    	"email" => array(
    		"regex" =>
    		"error" => "<i> Enter a valid Email address!</i>",),
    	"captcha" => array(
    		"regex" =>  "/md5$captcha/",
    		"error" => "<i> Please enter a Validate Code!</i>",),);		
    	global $errors;		
    		if(!preg_match($form_items["name"]["regex"], $_POST["m_name"]))
    			$errors[] = "<b>Your Name:</b> ".$form_items["name"]["error"];
    		if(!preg_match($form_items["email"]["regex"], $_POST["m_email"]))
    			$errors[] = "<b>Your Email:</b> ".$form_items["email"]["error"];		
    		if(!preg_match($form_items["captcha"]["regex"], $_POST["captcha"]))
    			$errors[] = "<b>Validate Code:</b> ".$form_items["captcha"]["error"];
    				return count($errors);	   
    /////////FORM MAIL STARTS HERE//////////////////////////////////////////////////////////////////////////////////	
    	function email($from, $from_name, $to, $message)
    		//header("Location: thanku.html");return;
    		$headers .= "From: ".$from."\r\n";
    		$headers .= "Content-type: text/plain; charset=ISO-8859-1";		
    		$domian_name = "www.domain.net";
    		$subject = $from_name."- An invitation to view $domian_name";
    		$your_message = "Hi!\r\n";
    		$your_message.= ucfirst($from_name);
    		$your_message.= "would like you to check out this website at $domian_name\r\n";
    		if (mail($to,$subject,$message,$headers) ) {
    			return true;
    		} else {
    			return false;
    	function print_error($errors)
    	{foreach($errors as $error)
    		echo "<div style=\"font-size:14px; font-weight:normal; color:red;\"><span style=\"background-color:yellow\">$err</span><div>";		
    //////////////POSTING AND THANK YOU STARTS HERE///////////////////////////////////////////////////////////////////////////	
    	function form_process()
           $captcha = $_POST['captcha'];//validate code		             $from_name = $_POST["m_name"];
    		$fromm_email = $_POST["m_email"];
    		$to = $_POST["f_email"].",".$_POST["f_email"];
    		$message = $_POST["message"];		
    		$error_count = validate_form_items();
    		if($error_count == 0)		
    		{if(email($fromm_email, $from_name, $to,)) header("Location: thanku.html");
    		{global $errors; $errors[] = "Email could not be send at this time. <br />Please report this to the Webmaster.";} }		
    		if(isset($_POST["submit"])) form_process();
    <html><body><fieldset><legend>Link to my Friend/s.</legend><br />
    Install your friend/'s email details to forward link to this website.<br /><br />
    <i>Required *</i>
        <form id="link" method="post" action="<?php echo $PHP_SELF?>" >
        <div><?php global $errors; if(count($errors) != 0){ print_error($errors);} ?></div>	
    	<label>My Name:*</label><input type="text" name="m_name" value="<?php echo $_POST["m_name"]?>" />
        <label>My Email:*</label><input type="text" name="m_email" value="<?php echo $_POST["m_email"]?>" />
        <label>Friend's Email:*</label><input type="text" name="f_email" value="<?php echo $_POST["f_email"]?>" />
    	<img src="randomImage.php"/><input type="text" name="captcha" size="5" />	
        <input type="submit" name="submit" value="Send Website Link" />

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