Jump to content

help: Convert to alert box

- - - - -

  • This topic is locked This topic is locked
5 replies to this topic

#1
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
i have here a php code that shows a form validation.
this code have no problem, but i dont want it to show in the upper part of the form,
i want it to show as alertbox, but showing all the message that are empty not one by one.

Example:
alertbox
You are required to complete the following fields: First name, Contact no., Job title, First guess.

Thank you.


$problem = FALSE; //no problem

	

	//check value

	$themessage = "You are required to complete the following fields: ";

	if (empty($fguess)){

	$problem = TRUE;

	print '<br/>Pls. enter a valid First guess';

	}

	if (empty($sguess)){

	$problem = TRUE;

	print '<br/>Pls. enter a valid Second guess';

	}

	if (empty($tguess)){

	$problem = TRUE;

	print '<br/>Pls. enter a valid Third guess';

	}

	if (empty($_POST['f_name'])){

	$problem = TRUE;

	print '<br/>Pls. enter your First name';

	}

	if (empty($m_name)){

	$problem = TRUE;

	print '<br/>Pls. enter your Middle name';

	}

	if (empty($l_name)){

	$problem = TRUE;

	print '<br/>Pls. enter your Last name';

	}

	if (empty($h_address)){

	$problem = TRUE;

	print '<br/>Pls. enter your Home address';

	}

	if (empty($email)){

	$problem = TRUE;

	print '<br/>Pls. enter your Email Address';

	}

	if (empty($contact)){

	$problem = TRUE;

	print '<br/>Pls. enter your Contact no.';

	}

	if (empty($job)){

	$problem = TRUE;

	print '<br/>Pls. enter your Job title';

	}

	


#2
rhossis

rhossis

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Hi there. You may need some javascript for this. This is a just a simple example to show you how you may go about it. I have done using the php code sample you have given.

<?php

$problem = FALSE; //no problem

    

    //check value

    $themessage = "You are required to complete the following fields: ";

    if (empty($fguess)){

    $problem = TRUE;

    $themessage.= 'First guess';

    }

    if (empty($sguess)){

    $problem = TRUE;

    $themessage.=',Second guess,';

    }

    if (empty($tguess)){

    $problem = TRUE;

    $themessage.=',Third guess';

    }

    if (empty($_POST['f_name'])){

    $problem = TRUE;

    $themessage.=',First Name';

    }

    if (empty($m_name)){

    $problem = TRUE;

    $themessage.=',Middle Name';

    }

    if (empty($l_name)){

    $problem = TRUE;

    $themessage.=',Last Name';

    }

    if (empty($h_address)){

    $problem = TRUE;

    $themessage.=',Home Address';

    }

    if (empty($email)){

    $problem = TRUE;

    $themessage.=',Email Address';

    }

    if (empty($contact)){

    $problem = TRUE;

    $themessage.=',Contact No';

    }

    if (empty($job)){

    $problem = TRUE;

    $themessage.=',Job Title';

    }


    //Print alert box with error message if there is a problem

    if($problem) {

	print("<script>alert('$themessage')</script>");

    }

?>


#3
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
thanks for your help. i will try this out.

#4
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
i have fix this solution, but now im having problem including checking email if duplicate. how do i include it in my form validation? thanks.

#5
sam001123

sam001123

    Newbie

  • Members
  • Pip
  • 1 posts
Use array and then implode it and then echo that variable in alert !!!!!!

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
The poster has created a new thread to acquire information about email checking, further using this for that question will just duplicate threads, it is located here:
http://forum.codecal...n-checking.html
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users