Hi I'm trying to submit a webform and insert the data into mysql. The problem I have is that I have setup the fields to have multiple input boxes. For example instead of just "name" I have "first name", "last name" and my address is divided into many fields to ensure the end user does not miss certain parts of their address.
The problem I have is that I can't submit those multiple fields into mysql. If I wanted to simply submit the "name" field I can, but not first name + last name. To be more clear, I have a column named "name" and I want the "firstname" and "lastname" both to be stored there. Same thing with the address.
Here is my html code
<ul>
<li id=name">
<label class="description" for="element_1">Name </label>
<span>
<input id="first" name= "first" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="last" name= "last" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li>
<li id="phone">
<label class="description" for="element_2">Phone </label>
<span>
<input id="parea" name="parea" class="element text" size="3" maxlength="3" value="" type="text" /> -
<label for="parea">(###)</label>
</span>
<span>
<input id="pfirst" name="pfirst" class="element text" size="3" maxlength="3" value="" type="text" /> -
<label for="pfirst">###</label>
</span>
<span>
<input id="plast" name="plast" class="element text" size="4" maxlength="4" value="" type="text" />
<label for="plast">####</label>
</span>
</li>
<li id="email">
<label class="description" for="element_3">Email </label>
<div>
<input id="email1" name="email1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="address">
<label class="description" for="element_4">Address </label>
<div>
<input id="street" name="street" class="element text large" value="" type="text">
<label for="element_4_1">Street Address</label>
</div>
<div>
<input id="element_4_2" name="element_4_2" class="element text large" value="" type="text" />
<label for="element_4_2">Address Line 2</label>
</div>
<div class="left">
<input id="element_4_3" name="element_4_3" class="element text medium" value="" type="text" />
<label for="element_4_3">City</label>
</div>
<div class="right">
<input id="element_4_4" name="element_4_4" class="element text medium" value="" type="text" />
<label for="element_4_4">State / Province / Region</label>
</div>
<div class="left">
<input id="element_4_5" name="element_4_5" class="element text medium" maxlength="15" value="" type="text" />
<label for="element_4_5">Postal / Zip Code</label>
</div>
</li>
</ul>
And my PHP variables are as such:
$name=$_POST['name'];
$email=$_POST['email'];
$address=$_POST['address'];
$pod=$_POST['pod'];
$sku=$_PST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$phone=$_POST['phone'];
$name=$_POST['first'] ." ". $_POST['last'];
$email=$_POST['email'];
$address=$_POST['address'];
$pod=$_POST['pod'];
$sku=$_PST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$phone=$_POST['phone'];
Ideally you need to redesign your table but for making it work with the existing schema, you need to serialize and de-serialize data. see
http://php.net/manual/en/function.serialize.php
So in name column you store something like {firstname:lastname}
$name[0] = $firstname;
$name[1] = $lastname;
$ser = serialize($name); \\--->put this in db
Related
Im trying to add data to multiple tables using a single query.
These two tables are contacts and address. I think the issue is with my address table. IS it a good idea to separate my address table? since multiple contacts can share the same address.(family)
Query for inserting data
$sql = "INSERT INTO contacts (firstName,lastName,nickName,cellNumber,homeNumber,workNumber) VALUES ($firstName,$lastName,$nickName,$cellNumber,$homeNumber,$workNumber) "
. "INSERT INTO address(street,city,state,country) VALUES($street,$city,$state,$country) INSERT INTO contacts (email,birthday,memo)"
. "values($email,$birthday,$memo)";
My HTML form
<fieldset>
<legend>Register Form</legend>
<div>
<input type="text" name="firstName" placeholder="First Name"/>
</div>
<div>
<input type="text" name="lastName" placeholder="Last Name"/>
</div>
<div>
<input type="text" name="nickName" placeholder="Nick Name"/>
</div>
<div>
<input type="text" name="cellNumber" placeholder="Cell Number"/>
</div>
<div>
<input type="text" name="homeNumber" placeholder="Home Number"/>
</div>
<div>
<input type="text" name="workNumber" placeholder="Work Number"/>
</div>
<div>
<input type="text" name="street" placeholder="Street"/>
</div>
<div>
<input type="text" name="city" placeholder="City"/>
</div>
<div>
<input type="text" name="state" placeholder="state"/>
</div>
<div>
<input type="text" name="country" placeholder="country"/>
</div>
<div>
<input type="text" name="email" placeholder="Email"/>
</div>
<div>
<input type="text" name="birthday" placeholder="Birthday"/>
</div>
<div>
<div class="small"></div>
<textarea name="memo" placeholder="Memo"></textarea>
</div>
<input type="submit" name="addContact" value="Send"/>
</fieldset>
Thomas i try your query u should modify and try this query:
Code :
$sql = "INSERT INTO contacts (firstName,lastName,nickName,cellNumber,homeNumber,workNumber) VALUES ($firstName,$lastName,$nickName,$cellNumber,$homeNumber,$workNumber) " ; "INSERT INTO address(street,city,state,country) VALUES($street,$city,$state,$country)"; "INSERT INTO contacts (email,birthday,memo)
values($email,$birthday,$memo)";
I think it should be must helpful.
I created a form using phpform.org And with some help from Mohamed Athif have now got a partially working mail.php , I am now receiving emails but I cant get the user input into the email. I Understand That I have to add the elements in for each field in the .php file. If someone can give some guidance to getting these few element working withing the email so I can then apply them to the all the other elements myself here is the html code.
For Element 1,8,6 in the email I want it to be as follows or similar to this
What alias do you want to use - (User Input)
Is this about - (whatever the user clicked either good Job or bad Job)
What is the name of the workplace.. (user Input)
Currently in the email Im getting this
From: alias
Message: Is this about a , Where is this Business Located? element6,
so you can see that the user input is missing.
<form method="post" action="mail.php">
<div class="form_description">
<h2>GoodJob - BadJob</h2>
<p>some text here</p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">What is the Alias you want to use </label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_1"><small>You don't have to use your real name - Just remember your Alias for Comments</small></p>
</li> <li id="li_8" >
<label class="description" for="element_8">Is this about a ...... </label>
<span>
<input id="element_8_1" name="element_8" class="element radio" type="radio" value="1" />
<label class="choice" for="element_8_1">Bad job</label>
<input id="element_8_2" name="element_8" class="element radio" type="radio" value="2" />
<label class="choice" for="element_8_2">Good Job</label>
</span>
</li> <li id="li_6" >
<label class="description" for="element_6">What is the name of the workplace you want to tell us about? </label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_6"><small>Type in the Name of the Business</small></p>
</li> <li id="li_16" >
<label class="description" for="element_16">Where is this Business Located? </label>
<div>
<input id="element_16" name="element_16" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_16"><small>Type in the town, or you can find the business on google maps and click on share and copy the link and paste it here.</small></p>
</li> <li id="li_7" >
<label class="description" for="element_7">If you want to mention the bosses name, Put it here. </label>
<div>
<input id="element_7" name="element_7" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_7"><small>Type in the Name of the Boss</small></p>
</li> <li id="li_15" >
<label class="description" for="element_15">If you know the personal page you can copy and paste it in here </label>
<div>
<input id="element_15" name="element_15" class="element text large" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_15"><small>Go to the top address bar of the boss/owner you want to tag for this post. Select all the text and paste it in the box.</small></p>
</li> <li id="li_9" >
<label class="description" for="element_9">How many hours a week do you work? </label>
<span>
<input id="element_9_1" name="element_9" class="element radio" type="radio" value="1" />
1 to 10
10 to 20
20 to 30
30 to 40
40 to 50
50 hours Plus
</span><p class="guidelines" id="guide_9"><small>Keep it REAL. </small></p>
</li> <li id="li_18" >
<label class="description" for="element_18">Exactly how many hours do you work? </label>
<div>
<input id="element_18" name="element_18" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_11" >
<label class="description" for="element_11">Does your Job Pay Extra Hours? </label>
<span>
<input id="element_11_1" name="element_11" class="element radio" type="radio" value="1" />
Yes
No
</span>
</li> <li id="li_10" >
<label class="description" for="element_10">What type of contract do you have? </label>
<span>
<input id="element_10_1" name="element_10" class="element radio" type="radio" value="1" />
Part Time
Full Time
Hourly per week
Dont know
</span><p class="guidelines" id="guide_10"><small>DON'T GUESS..This is crucial. Every worker MUST have a copy of their contract. If you don't have one ask your boss or go to the Employment office with ALL your credentials and they will tell you there what contract you have.</small></p>
</li> <li id="li_12" >
<label class="description" for="element_12">Did you get Holiday pay? </label>
<span>
<input id="element_12_1" name="element_12" class="element radio" type="radio" value="1" />
Yes
No
</span>
</li> <li id="li_17" >
<label class="description" for="element_17">How much holiday pay did you get? </label>
<div>
<input id="element_17" name="element_17" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_17"><small>A NUMBER ONLY no symbols or text</small></p>
</li> <li id="li_13" >
<label class="description" for="element_13">Did you know That </label>
<span>
<input id="element_13_1" name="element_13" class="element radio" type="radio" value="1" />
Yes
No
</span><p class="guidelines" id="guide_13"><small>Its true, In Spain ins a 14 month pay scheme, where you get a double pay in summer and another Christmas. Most employers will actually incorporate these two payments within your monthly wage</small></p>
</li> <li id="li_14" >
<label class="description" for="element_14">Got a story to tell about this Job? Bad or good - let it rip here!</label>
<div>
<textarea id="element_14" name="element_14" class="element textarea large"></textarea>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="1136056" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
and the PHP is as follows
<?php
$element1 = $_POST['element_1'];
$element8 = $_POST['element_8'];
$element6 = $_POST['element_6'];
$formcontent="From: $element1 \n Message: Is this about a $element81, Where is this Business Located? element6, blah blah blah";
$recipient = "me#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $element1 \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "<script type='text/javascript'>alert('Mail sent successfully!')</script>";
?>
In your original code, you
1) called an non-existing variable $element81
2) there is a $ sign missing before element6
that's why you didn't get the required content.
The code below will give you the following content in your email (as per your request)
What alias do you want to use - (User Input)
Is this about - (whatever the user clicked either good Job or bad Job)
What is the name of the workplace.. (user Input)
replace
$formcontent="From: $element1 \n Message: Is this about a $element81, Where is this Business Located? element6, blah blah blah";
with
$formcontent="What alias do you want to use - $element1\n";
$formcontent.="Is this about - $element8\n";
$formcontent.="Where is this Business Located? - $element6\n";
I am making a basic new customer database with mysql and php. I would like when people click on the radio button"different mailing address" for another couple of input fields to appear for the mailing address. Im not quite sure how to handle this with inputs and not variables. Is there a way to do an if statement here is my html form code below
<form method="POST" action="insert.php">
<fieldset>
<legend>New Customer data</legend>
<label>Complete Below</label>
<div class="controls controls-row">
<input class="span4" name="firstname" type="text" placeholder="First name">
<input class="span3" name="lastname" type="text" placeholder="Last Name">
<input class="span3" name="phone" type="text" placeholder="Phone">
</div>
<div class="controls controls-row">
<input class="span4" name="address" type="text" placeholder="Address">
<input class="span2" name="city" type="text" placeholder="City">
<input class="span1" name="state" type="text" placeholder="State">
</div>
<div class="controls controls-row">
<input class="span4" name="zip" type="text" placeholder="Zip Code">
<input class="span2" name="email" type="text" placeholder="Email">
<input class="span2" name="ccemail" type="text" placeholder="cc email">
</div>
<span class="help-block">When is the customers due date monthly</span>
<label class="radio">
<input type="radio" name="duedate" id="optionsRadios1" value="1" checked>
1st of the month</label>
<label class="radio">
<input type="radio" name="duedate" id="optionsRadios2" value="15">
15th of the month
</label>
<span class="help-block">Mailing address</span>
<label class="radio">
<input type="radio" name="mailingaddress" id="optionsRadios3" value="1" checked>
Check if mailing address is the same as the service address
</label>
<label class="radio">
<input type="radio" name="mailingaddress" id="optionsRadios4" value="0">
Check if mailing address is different
</label>
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>
Using jQuery, have two inputs that are initially hidden. Once the user checks the box, '$.show()' on those two inputs. Id have a div containing two inputs, and just show or hide the div depending on whether the box is checked or not
you can try this.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" >
</script>
<script>
$(document).ready(function(){
$("#checkme").on('change',function(){
if($("#checkme").is(":checked")){
$("input#myemail").fadeIn();
}else{
$("input#myemail").fadeOut();
}
});
});
</script>
</head>
<body>
show: <input type="checkbox" id="checkme" /><br />
<input type="text" id="myemail" hidden />
</body>
</html>
I have a HTML form within one of my webpages, and i am now having trouble configuring it to the sendmail.php. When I fill in the form, and click submit, its asking me to save the file 'sendmail.php' but I want it to send to the email specified in the 'sendmail.php' file.
in my 'sendmail.php' file I currently have:
<?php
$element_1_1 = $_POST['element_1_1'];
$element_1_2 = $_POST['element_1_2'];
if(isset($_POST['submit'])){
$to = "sales#atechdigital.co.uk"; // this is your Email address
$from = $_POST['element_4']; // this is the sender's Email address
$first_name = $_POST['element_1_1'];
$last_name = $_POST['element_1_2'];
$subject = "Form submission";
$message = $element_1_1 . " " . $element_1_2 . " Has Sent A Quote Request";
$element_2 = $_POST['element_2'];
$element_3 = $_POST['element_3'];
$element_4 = $_POST['element_4'];
$element_5_1 = $_POST['element_5_1'];
$element_5_2 = $_POST['element_5_2'];
$element_5_3 = $_POST['element_5_3'];
$element_5_4 = $_POST['element_5_4'];
$element_5_5 = $_POST['element_5_5'];
$element_5_6 = $_POST['element_5_6'];
mail ($to,$element_4,$element_2,$element_3,$element_4,$element_5,$element_5_1,$element_5_2,$element_5_3,$element_5_4,$element_5_5,$element_5_6);
echo " Thank you " . $first_name . ", One of our sales team is dealing with you're request! We will contact you shortly.";
}
?>
and the html form is as follows:
<form id="form_824601" class="appnitro" method="post" action="sendmail.php">
<ul >
<li id="li_1" >
<label class="description" for="element_1">Name </label>
<span>
<input id="element_1_1" name= "element_1_1" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="element_1_2" name= "element_1_2" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li>
<li id="li_2" >
<label class="description" for="element_2">Company Name </label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_3" >
<label class="description" for="element_3">Enter Contact Telephone Number </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_4" >
<label class="description" for="element_4">Enter Email Address </label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_5" >
<label class="description" for="element_5">Request A Quote For ... </label>
<span>
<input id="element_5_1" name="element_5" class="element radio" type="radio" value="1" />
<label class="choice" for="element_5_1">Web Design</label>
<input id="element_5_2" name="element_5" class="element radio" type="radio" value="2" />
<label class="choice" for="element_5_2">SEO</label>
<input id="element_5_3" name="element_5" class="element radio" type="radio" value="3" />
<label class="choice" for="element_5_3">Social Media</label>
<input id="element_5_4" name="element_5" class="element radio" type="radio" value="4" />
<label class="choice" for="element_5_4">Graphic Design</label>
<input id="element_5_5" name="element_5" class="element radio" type="radio" value="5" />
<label class="choice" for="element_5_5">Video Marketing</label>
<input id="element_5_6" name="element_5" class="element radio" type="radio" value="6" />
<label class="choice" for="element_5_6">Maintenance</label>
</span>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="824601" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
I Hope someone can shed light on the issue I'm having!!
This will never work while you are running the script locally. You need to run it on a server that can handle PHP. The only way you could run it locally and that is if you have a local web server set up.
I hope this helps!
You can't run .php files just from the folder, you will need a web server to handle it for you. if you are running windows or mac , you can set one up using software like XAMPP (win + osx) , WAMP (win) , MAMP (osx).
If you happen you run a linux distribution, you can set up a LAMP server.
Here are some links:
https://www.apachefriends.org/index.html
http://www.wampserver.com/en/
http://www.mamp.info/en/
From the links above, xampp has always worked out the best for me performance wise. parsing a huge xml feed and putting it into a mysql database takes like half the time on xampp compared to wamp.
Hi I'm doing a small project for learning php, and I wrote a few functions :
In the this piece of code, I basically check all the fields in my form and change values in a hash from false to true if they are filled in, at the end I loop the hash, and add the key (which is the error) to the array if its value is false.
function testBabysitterForAllElements(){
global $db;
$errorArray;
$naamarray["naam"]=false;
$naamarray["voornaam"]=false;
$naamarray["adres"]=false;
$naamarray["woonplaats"]=false;
$naamarray["postcode"]=false;
$naamarray["telefoonnummer"]=false;
$naamarray["geboortedatum"]=false;
$naamarray["adres"]=false;
$naamarray["wachtwoord"]=false;
$naamarray["email"]=false;
if(isset($_POST['element_1'])){
$naamarray["naam"]=true;
}
if(isset($_POST['element_2'])){
$naamarray["voornaam"]=true;
}
if(isset($_POST['element_3'])){
$naamarray["adres"]=true;
}
if(isset($_POST['element_4'])){
$naamarray["woonplaats"]=true;
}
if(isset($_POST['element_5'])){
$naamarray["postcode"]=true;
}
if(isset($_POST['element_6'])){
$naamarray["telefoonnummer"]=true;
}
if(isset($_POST['element_7'])){
$naamarray["email"]=true;
connectToDB();
$sql='SELECT inlognaam FROM kauffman.login WHERE inlognaam like \''.$_POST['element_7'].'\';';
$rows=$db->queryRow($sql);
if($rows){
array_push($errorArray,"email adres is reeds geregistreerd.");
}
}
if(isset($_POST['element_8_1']) && isset($_POST['element_8_2']) && isset($_POST['element_8_3'])){
$naamarray["geboortedatum"]=true;
}
if(isset($_POST['element_10']) && isset($_POST['element_10_1'])){
$naamarray['wachtwoord']=true;
}
foreach($naamarray as $key => $value){
if($value == false){
array_push($errorArray,$key);
}
}
if(!empty($errorArray)){return $errorArray;}
}
Here I add the fields to the DB, it calls the previous function to check if all fields are filled in.
function babysitterToevoegenAanDB(){
global $db;
if(isset($_POST['submit'])){
$errorArray=testBabysitterForAllElements();
echo $errorArray;
$succes=('succesvol toegevoegd');
$result;
if(!empty($errorArray)){
connectToDB();
$sql = "INSERT into kauffman.login(inlognaam,functie,paswoord) VALUES ('".antiInjectie($_POST['element_7'])."','gezin','".pwHashGenerator(antiInjectie($_POST['element_10_1']))."');";
$sql2 = 'SELECT serialKey from kauffman.login WHERE inlognaam='.antiInjectie($_POST['element_7']).';' ;
$result= $succes;
}else{
$result= $errorArray;
}
echo $result;
}
}
Here I create my form that also has the babysitterToevoegenAanDB() function. This and the form are returned and can be called on a page.
function babysitterForm(){
return babysitterToevoegenAanDB().' <form id="babysitForm" class="appnitro" method="post" action="'.htmlentities($_SERVER['PHP_SELF']).'">
<div class="form_description">
<h2>Babysitter</h2>
<p>Gelieve je hier in te schrijven als babysitter</p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">Naam </label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value="'.
((isset($_POST['element_1']))? htmlentities($_POST['element_1']):'')
. '"/>
</div><p class="guidelines" id="guide_1"><small>Voer uw naam in.</small></p>
</li> <li id="li_2" >
<label class="description" for="element_2">Voornaam </label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_2']))? htmlentities($_POST['element_2']):'').'"/>
</div><p class="guidelines" id="guide_2"><small>Vul uw voornaam in.</small></p>
</li> <li id="li_3" >
<label class="description" for="element_3">Adres </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_3']))? htmlentities($_POST['element_3']):'').'"/>
</div><p class="guidelines" id="guide_3"><small>vul uw straat en huisnummer in.</small></p>
</li> <li id="li_4" >
<label class="description" for="element_4">Woonplaats </label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_4']))? htmlentities($_POST['element_4']):'').'"/>
</div><p class="guidelines" id="guide_4"><small>vul uw woonplaats in.</small></p>
</li> <li id="li_5" >
<label class="description" for="element_5">Postcode </label>
<div>
<input id="element_5" name="element_5" class="element text small" type="text" maxlength="255" value="'.((isset($_POST['element_5']))? htmlentities($_POST['element_5']):'').'"/>
</div><p class="guidelines" id="guide_5"><small>Vul uw Postcode hier in</small></p>
</li> <li id="li_6" >
<label class="description" for="element_6">telefoonnummer </label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_6']))? htmlentities($_POST['element_6']):'').'"/>
</div><p class="guidelines" id="guide_6"><small>Vul uw telefoonnummer in.</small></p>
</li> <li id="li_7" >
<label class="description" for="element_7">email </label>
<div>
<input id="element_7" name="element_7" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_7']))? htmlentities($_POST['element_7']):'').'"/>
</div><p class="guidelines" id="guide_7"><small>vul uw email in.</small></p>
</li> <li id="li_8" >
<label class="description" >Geboortedatum </label>
<span>
<input id="element_8_1" name="element_8_1" class="element text" size="2" maxlength="2" value="'.((isset($_POST['element_8_1']))? htmlentities($_POST['element_8_1']):'').'" type="text"> /
<label for="element_8_1">MM</label>
</span>
<span>
<input id="element_8_2" name="element_8_2" class="element text" size="2" maxlength="2" value="'.((isset($_POST['element_8_2']))? htmlentities($_POST['element_8_2']):'').'" type="text"> /
<label for="element_8_2">DD</label>
</span>
<span>
<input id="element_8_3" name="element_8_3" class="element text" size="4" maxlength="4" value="'.((isset($_POST['element_8_3']))? htmlentities($_POST['element_8_3']):'').'" type="text">
<label for="element_8_3">YYYY</label>
</span>
<li id="li_10" >
<label class="description" for="element_10">Wachtwoord </label>
<div>
<input id="element_10" name="element_10" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_10']))? htmlentities($_POST['element_10']):'').'"/>
<input id="element_10_1" name="element_10_1" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_10_1']))? htmlentities($_POST['element_10_1']):'').'"/>
</div><p class="guidelines" id="guide_10"><small>Vul uw wachtwoord twee maal in. Hierdoor voorkomt men typfouten door validatie.</small></p>
</li>
<li id="li_9" >
<label class="description" for="element_9">Opmerkingen </label>
<div>
<textarea id="element_9" name="element_9" class="element textarea medium" ></textarea>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="206335" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form> ';
}
What basically happens is :
I call the last function babysitteForm which shows a form to apply
BabysitterForm includes the babySitterToevoegenAanDB function that checks if submit is set
If so it checks all the fields if there are errors it has to return an array with errors
However if I click submit without filling anyhting in, there is nothing added to the errorArray.
Its normal that nothing gets added to your error array.
The function isset($_POST['anything']) will only check if that field is set in your post var.
The post var gets filled up by your form.
Basicly, if your form contains 7 input fields, all these input fields their value will be placed into
$_POST.
A print of your $_POST var would be something like:
print_r($_POST);
result:
array('element_1'=>'','element_2'=>'' ...
so your isset function will check if the value 'element_x' is set, wich it is, it just contains nothing.
u need to re-write your checks so they check the content, not the existance. Isset is only of
use when checking f.e. $_GET vars if u are not sure they are set and not post vars in a form (since these will always be set).
I would suggest re-writing your checks in the form of:
$naamarray["naam"]=true;
$naamarray["voornaam"]=true;
$naamarray["adres"]=true;
$naamarray["woonplaats"]=true;
$naamarray["postcode"]=true;
$naamarray["telefoonnummer"]=true;
$naamarray["geboortedatum"]=true;
$naamarray["adres"]=true;
$naamarray["wachtwoord"]=true;
$naamarray["email"]=true;
if($_POST['element_1'] == ""){
$naamarray["naam"]=false;
}
do this for all your checks.
also reverse your foreach loop:
foreach($naamarray as $key => $value){
if($value == true){
array_push($errorArray,$key);
}
}
I also have some doubts with the returning of the function before your form. I think its clearer
to create a function and just include the php page instead of this.
then u would get code like:
require_once('inc/functions.php');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
babysitterToevoegenAanDB();
} else {
babysitterForm();
}
And the final tip: give your input field clear names, not just element_x ... .