Reputation:
I have a domain name check form that i have in a container. After I submit the form the availability of the domain name is checked and a message is shown in the same container as the form. When the message is shown, I want the form and first H2 to disappear. How can i do this?
My code:
<div id="domain-name-check">
<h2>Is uw domeinnaam nog vrij?</h2>
<form method='post' class="clearfix">
<input type=text name=domain>
<select name="suffix">
<option value=".nl">.nl</option>
<option value=".be">.be</option>
<option value=".com">.com</option>
<option value=".net">.net</option>
<option value=".org">.org</option>
<option value=".biz">.biz</option>
<option value=".info">.info</option>
<option value=".mobi">.mobi</option>
<option value=".ws">.ws</option>
<option value=".cc">.cc</option>
</select>
<input type=submit name=proses value=Check>
</form>
<?php
if(isset($_POST['proses'])){
$domain_name = "$_POST[domain]"."$_POST[suffix]";
$arrHost = @gethostbynamel("$domain_name");
$date = date('y-m-d');
if(empty($arrHost)){
echo "<h2>$domain_name is beschikbaar</h2> <a href='/offerte-aanvragen/".$domain_name."/'>Vraag een offerte aan</a>";
$availability = "yes";
}else{
echo "<h2>$domain_name is helaas bezet</h2> <a href='/offerte-aanvragen/".$domain_name."/verhuizen/'>Verhuis uw domein</a>";
$availability = "no";
}
mysql_query("INSERT domainnames SET dns='".$domain_name."', available='".$availability."', timestamp='".$date."'")or die(mysql_error());
}
?>
</div>
Upvotes: 5
Views: 22173
Reputation: 307
Use the following:
<?php
if ( isset( $_POST['field_name'] ) )
{
.... // submit
exit();
}
?>
<html>
<form ... action="" method="POST">
....
....
</form>
</html>
Upvotes: 0
Reputation: 23948
Corrected code:
Display form only when we do not have form values submitted.
So, write your HTML code in else
tag as following:
<div id="domain-name-check">
<?php
if(isset($_POST['proses'])){
$domain_name = "$_POST[domain]"."$_POST[suffix]";
$arrHost = @gethostbynamel("$domain_name");
$date = date('y-m-d');
if(empty($arrHost)){
echo "<h2>$domain_name is beschikbaar</h2> <a href='/offerte-aanvragen/".$domain_name."/'>Vraag een offerte aan</a>";
$availability = "yes";
}else{
echo "<h2>$domain_name is helaas bezet</h2> <a href='/offerte-aanvragen/".$domain_name."/verhuizen/'>Verhuis uw domein</a>";
$availability = "no";
}
mysql_query("INSERT domainnames SET dns='".$domain_name."', available='".$availability."', timestamp='".$date."'")or die(mysql_error());
}
else {
?>
<h2>Is uw domeinnaam nog vrij?</h2>
<form method='post' class="clearfix">
<input type=text name=domain>
<select name="suffix">
<option value=".nl">.nl</option>
<option value=".be">.be</option>
<option value=".com">.com</option>
<option value=".net">.net</option>
<option value=".org">.org</option>
<option value=".biz">.biz</option>
<option value=".info">.info</option>
<option value=".mobi">.mobi</option>
<option value=".ws">.ws</option>
<option value=".cc">.cc</option>
</select>
<input type=submit name=proses value=Check>
</form>
<?php
}
?>
</div>
Upvotes: 8
Reputation: 1635
replace <h2>Is uw domeinnaam nog vrij?</h2>
with
if (!isset($_POST)){
echo '<h2>Is uw domeinnaam nog vrij?</h2>';
}
this will make sure if form is not submitted then h2
will visible to user
alternatively you can use Javascript
Upvotes: 0
Reputation: 4736
HTML code may be wrapped with PHP to conditionally show it.
Consider the following as a template for this type of functionality:
<?php if (condition) { ?>
<p>HTML</p>
<?php } ?>
It's that simple.
In this instance, your condition will probably be
if (isset($_POST['proses'])
Upvotes: 0
Reputation: 95
Under your form tag,insert a hidden form field like this:
<form method='post' class="clearfix">
<input type="hidden" name="action" id="action" value="hideme" />
.................................
.............................
</form>
Now under your $_POST section,use the following logic:
if (isset($_POST['action'])&& ($_POST['action']=='hideme'))
{
//perform your intended task on submission
}else {
//Show My form code again
}
Simple!
Upvotes: 0
Reputation: 76646
This can be done by restructuring the current code a bit:
<?php
if(isset($_POST['proses'])){
# code ...
}
else {
?>
<div id="domain-name-check">
<!-- your form code goes here -->
</div>
<?php
} //end of else block
?>
Full code:
<?php
if(isset($_POST['proses']))
{
$domain_name = "$_POST[domain]"."$_POST[suffix]";
$arrHost = @gethostbynamel("$domain_name");
$date = date('y-m-d');
if(empty($arrHost)){
echo "<h2>$domain_name is beschikbaar</h2> <a href='/offerte-aanvragen/".$domain_name."/'>Vraag een offerte aan</a>";
echo "AVAILABLE";
$availability = "yes";
}else{
echo "<h2>$domain_name is helaas bezet</h2> <a href='/offerte-aanvragen/".$domain_name."/verhuizen/'>Verhuis uw domein</a>";
echo "NOT AVAILABLE";
$availability = "no";
}
mysql_query("INSERT domainnames SET dns='".$domain_name."', available='".$availability."', timestamp='".$date."'")or die(mysql_error());
}
else
{
?>
<div id="domain-name-check">
<h2>Is uw domeinnaam nog vrij?</h2>
<form method='post' class="clearfix">
<input type=text name=domain>
<select name="suffix">
<option value=".nl">.nl</option>
<option value=".be">.be</option>
<option value=".com">.com</option>
<option value=".net">.net</option>
<option value=".org">.org</option>
<option value=".biz">.biz</option>
<option value=".info">.info</option>
<option value=".mobi">.mobi</option>
<option value=".ws">.ws</option>
<option value=".cc">.cc</option>
</select>
<input type=submit name=proses value=Check>
</form>
</div>
<?php
}
?>
Upvotes: 0
Reputation: 15711
<div id="domain-name-check">
<?php if(!isset($_POST['proses'])){ ?><h2>Is uw domeinnaam nog vrij?</h2>
<form method='post' class="clearfix">
<input type=text name=domain>
<select name="suffix">
<option value=".nl">.nl</option>
<option value=".be">.be</option>
<option value=".com">.com</option>
<option value=".net">.net</option>
<option value=".org">.org</option>
<option value=".biz">.biz</option>
<option value=".info">.info</option>
<option value=".mobi">.mobi</option>
<option value=".ws">.ws</option>
<option value=".cc">.cc</option>
</select>
<input type=submit name=proses value=Check>
</form>
<?php } //endif form submitted
if(isset($_POST['proses'])){
$domain_name = "$_POST[domain]"."$_POST[suffix]";
$arrHost = @gethostbynamel("$domain_name");
$date = date('y-m-d');
if(empty($arrHost)){
echo "<h2>$domain_name is beschikbaar</h2> <a href='/offerte-aanvragen/".$domain_name."/'>Vraag een offerte aan</a>";
$availability = "yes";
}else{
echo "<h2>$domain_name is helaas bezet</h2> <a href='/offerte-aanvragen/".$domain_name."/verhuizen/'>Verhuis uw domein</a>";
$availability = "no";
}
mysql_query("INSERT domainnames SET dns='".$domain_name."', available='".$availability."', timestamp='".$date."'")or die(mysql_error());
}
?>
</div>
Upvotes: 1