0

hi guys, this is the scenario, i have two textboxes, then a submit button.
now, when the user clicks the submit button, it will verify if both textboxes have values,
otherwise, if only one of them is empty, an alert box will be displayed prompting the user to complete the information. this scenario is perfect and is working out fine. now, what i want to happen is that, the alert box will be displayed then the value inputted by the user on the textboxes will not be erased. how is that so?

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by happytogether
0

depending on the method you use the submit the (if it's post or get) you can do something like this

<form action='index.php' method = 'post'>
   <input type = 'text' name = 'text1' value = '<?php 
       echo ( isset( $_POST['text1'] ) ?
       $_POST['text1'] : '' ) ?>' />

      // isset( $_POST['text1'] ) ? $_POST['text1'] : '' ) is the same as 
      // if(isset($_POST['text1'])){ echo $_POST['text1'] }else {}
</form>
0

Try this

<?php


if($_POST['submit']=="Submit")
{
	$text1 = $_POST['text1'];
	$text2 = $_POST['text2'];
		
	if($text1 =="" || $text2=="")
	{
	?>
	<head>
		<script type='text/javascript'>
			alert('Some text here.');
		</script>
	</head>
	<?php
	}
       else
       {
       //what do you want when the two textbox have value
       }

}

echo "<form action='index.php' method='post'>";
echo "<input type='text' name='text1' value='$text1'>";
echo "<input type='text' name='text2' value='$text2'>";
echo "<input type='submit' name='submit' value='Submit'>";

?>
0

you can try this

<?php
if(isset($_POST['submit'])) {
	if(!empty($_POST['text1']) and !empty($_POST['text2'])){
	 //do what you want
        }
       else
       {
       /do youre alert
       }
}
?>

hope this help

Edited by happytogether: fogot to close if

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.