0

I have set up a custom form in my locally hosted WP and I made a page where user goes after successfully done with the form but I got two issues :

1- the form validation code appears on the interface how can I hide it

2- there's no data sent to my DB and I've been directed to a blank page

when I run the php file that does the data storage process I land on the page that show the user the success of the forum filling

here is my html code+ form validation code(WP side) :

<?php
function validateForm()
{
/* Validating name field */
var x=document.forms["myForm"]["name"].value;
if (x==null || x=="")
{
alert("Name must be filled out");
return false;
}
/* Validating email field */
var x=document.forms["myForm"]["telephone"].value;

if (x==null || x=="")
{
alert("telephone must be filled out");
return false;
}
} 
?>

<form action="C:\xampp\htdocs\wordpress\process.php" method="post" name="myForm">
Name <input id="name" type="text" name="name" />
Telephone <input id="telephone" type="text" name="telephone" />
Fax <input id="fax" type="text" name="fax" />
Web address <input id="webaddress" type="text" name="webaddress" />
State <input id="state" type="text" name="state" />
Address <input id="address" type="text" name="address" />
<input type="submit" value="Submit" /></form>



<script type="text/javascript">// <![CDATA[
/* JS validation code here */
...
...
// ]]></script>

and this is the php for the Data storage function:

<?php 
//establish connection
$con = mysqli_connect("localhost","xxx","xxx","android_app"); 
//on connection failure, throw an error
if(!$con) {  
die('Could not connect: '.mysql_error()); 
} 
?>

<?php 
//get the form elements and store them in variables
$name=$_POST["Name"]; 
$telephone=$_POST["Telephone"]; 
$fax=$_POST["Fax"]; 
$webaddress=$_POST["Webaddress"]; 
$state=$_POST["State"]; 
$address=$_POST["Address"]; 
?>

<?php 
$sql="INSERT INTO `android_app`.`islamic_organisation` ( `Name` , `Telephone` , `Fax` , `WebAddress` , `state` , `Address`) VALUES ( '$name','$telephone', '$fax', '$webaddress' , '$state', '$address')"; 
    mysqli_query($con,$sql); 
?>

<?php
//Redirects to the specified page
header("Location: http://localhost/wordpress/?page_id=857"); 
?>

I hope somebody can give some help

thanks

  • 1
    The form validation code is javascript, not PHP. This question has almost nothing to do with WordPress, should be migrated over to SO – anu May 3 '13 at 11:51
  • @anu "SO" you mean Stack overflow? – user2309720 May 3 '13 at 11:56
  • Don't recommend closing - better add an example of how it should be done. – kaiser May 3 '13 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.