How to display and process forms in a Joomla article using DirectPHP? |
| Written by kksou | ||
| Thursday, 30 June 2011 | ||
|
With DirectPHP, you can easily display forms in a Joomla article by using PHP's echo() function to display the HTML form. However, many people have asked in the forum how to process this HTML form within the Joomla article? Displaying the FormBelow is a sample form displayed using DirectPHP: The code above is displayed using the following PHP statements: <?php echo '<form action="index.php" method="POST"> var1: <input name="var1"><br /> var2: <input name="var2"><br /> <input type="hidden" name="option" value="com_content"> <input type="hidden" name="Itemid" value="1"> <input type="hidden" name="id" value="2014"> <input type="hidden" name="task" value="view"> <input type="submit" value="Submit"> </form>'; ?> Submitted Form ValueTry enter some string into Submitted value of var1: Submitted value of var2: The code to displayed the submitted values are as follows: echo "Submitted value of var1: ".$_POST['var1']."<br />"; echo "Submitted value of var2: ".$_POST['var2']."<br />"; ExplanationPlease refer to the article: How to pass variables or parameters from one Joomla article to another using DirectPHP? As explained in the article, you need to pass in the following parameters in order to come back to the same Joomla article:
When using a form, we pass along these parameters using the <input type="hidden" name="option" value="com_content"> <input type="hidden" name="Itemid" value="1"> <input type="hidden" name="id" value="2014"> <input type="hidden" name="task" value="view"> Note that we are using the echo "Submitted value of var1: ".$_POST['var1']."<br />"; echo "Submitted value of var2: ".$_POST['var2']."<br />"; If you are using the echo "Submitted value of var1: ".$_GET['var1']."<br />"; echo "Submitted value of var2: ".$_GET['var2']."<br />"; ConclusionJoomla is written in PHP. So it's easy to incorporate HTML forms into a Joomla article through the use of DirectPHP. Just make sure you pass along the additional Joomla parameters (i.e. |
||
| < Prev | Next > |
|---|


