Forums

How to include external php file

DHLao 24 Mar, 2009
The Form Wizard can't fulfill my requirement. So, I need to create a custom form in Form Code.

My form content is inside an external php file. What I need is to include this file in Form HTML.

But I don't know where I should put this file. I had try put it in web root directory and \components\com_chronocontact
GreyHead 24 Mar, 2009
Hi DHLao,

You can put it anywhere you like, personally I tend to create a com_chronocontact/includes folder

You could also copy and paste the html from your external file into the Form HTML box (or at least the part between the <form> tags.

Bob
DHLao 24 Mar, 2009
Thanks for the reply,

but make <form> tag in Form HTML box cause error message "You are not allowed to access this URL " in frontend.

I know many people encounter this problem and I can't find a solution for this.

I'm using Joomla 1.5.9

Below is the code in Form HTML

<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
<input type="submit" />
</form>


Below is the code of the external php file "insert.php"

<?php
  $con = mysql_connect("localhost","root","abcdef") or die("failed connect" . mysql_error());
  mysql_select_db("joomla_db", $con);
  $sql="INSERT INTO profile (firstName, lastName) VALUES('$_POST[firstname]','$_POST[lastname]')";
  if (mysql_query($sql,$con)){
    echo "1 record added";
  }
  else{
    echo "failed send";
  }
  mysql_close($con);
?>
GreyHead 24 Mar, 2009
Hi Dhlao,

Sorry, I wasn't clear - paste the code inside the <form . . .> and </form> tags but not the tags themselves.

ChronoForms creates it's own form tags, and form tags cannot be nested inside other form tags.

Your Form HTML should be
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
<input type="submit" />
You could also insert the code from your external file into the OnSubmit After box. But you don't need to - ChronoForms will do the database save for you, into a new table if you use the Create Table icon, or into an existing table using the Database Connection tab.

Please see the Tutorials in the DownLoads area here.

Bob




.
nml375 24 Mar, 2009
I would like to add, that your code is not safe against SQL injection attacks. I'd recommend going with Bob's suggestion of using the DB Connection feature.
This topic is locked and no more replies can be posted.