Dynamic form posting

Jxck

got that old thing back
Apr 5, 2014
135
34
I have a site that produces form's from a table called 'form_parts' this the dictates what type of field it is, what the ghost text is and its ID etc. I then display this on pages that have 'link to form' active. I hope to then process this to mail it via the PHP mail function. However I don't know how to dynamically pull the fields (will be different fields for every page) and then email them as a content. Here is my existing code, I can't even get it to mail with basic hard coded contents.

$mail is defined in an include file that is required by the file that requires this file. It is the users email address. A lot of the code has been changed but I haven't changed the commenting from my original non-dynamic method which seemingly worked fine.

Code:
<?php
//A temp check to see if the field 'Full Name' was completed before submission. What needs to happen is a check of all mandatory fields and highlight incomplete ones

if(isset($_REQUEST['submit'])){

//Basic information in order to send the email, for now the 'admin_email' is the track it monitor

$admin_email ="*";

//This pulls all the information that is required and not optional or based on another selection.


//Sending the mail function
mail($admin_email,"Testing self service.","testing","From:". $mail);

//The action performed after sending the email, in this case a dismissable balloon alert.
echo "Thank you for contacting us!";
}

else{
?>
<formmethod="post">
<divclass='panel panel-default'>
<divclass='panel-body'id='form'>
<?php

$getFormQuery ="SELECT id,type,sortno,dropdownid,contentid,label,shadowtext,active FROM form_parts WHERE contentid = $contentid AND active = 1 ORDER BY sortno ASC"ordie("Error!:". mysqli_error($link));
$getForm = $link->query($getFormQuery);

while($formInfo = mysqli_fetch_array($getForm)){

$label = $formInfo["label"];
$ftype = $formInfo["type"];
$shadowtext = $formInfo["shadowtext"];

if(($ftype)=="Text"){
echo "<label>$label</label>";
echo "<br><center><input type='text' class='form-control' placeholder='$shadowtext'></center><br>";
}
if(($ftype)=="Date"){
echo "<label>$label</label>";
echo "<br><center><input type='date' class='form-control' placeholder='$shadowtext'></center><br>";
}
}

?>
<br>
<inputtype="submit"class="btn btn-success"value="Submit">
</div></div>
</form>

<?php
}
?>
 

BIOS

ಠ‿ಠ
Apr 25, 2012
906
247
What even is this for? I don't understand what outcome you are trying to get as the result of this

Why are you setting the type of input via the db?
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,142
2,468
Your input fields don't have a name="" element. So, they can't be identified when you submit the form. Besides it's form method and not formmethod. Same for div class and not divclass.
 

Jxck

got that old thing back
Apr 5, 2014
135
34
@BIOS The purpose of this is to be able to create forms on pages and have those forms submitted to an email address that then deals with it via a software suite called Track It

@eckostylez SMTP is on and working through our internal Exchange server.

@JohnDorian I realise that but I can't name them as each form will have different input fields, some may only have one or two others could have up to 20 so how do I make it so whatever number of fields or whatever name it submits them all?
 

Users who are viewing this thread

Top