, Guest!
Already a Member? Login or Register.

Menu



Showcase


Due to the volume of spam happening on our forums, posting is now restricted to verified members only.  If you're not verified, drop us a note with your username.

Home > FlexCMS Support Forum > User Help > General Support Requests > Working with FORMS on a page

FlexCMS Support Forum


Working with FORMS on a page
Started March 11, 2008 @ 3:21pm by Wolf
Post Message 
Wolf




Posts: 65
 
Working with FORMS on a pageMarch 11, 2008 @ 3:21pm
I'm working on creating an HTML form on a page. After the form is filled in by the user, I'd like to process it and then return back to the same form with the results displayed on the page with the form.

In normal HTML I'd do something like this to redirect myself back to the same page:


Code

<form action ="<?php print $PHP_SELF?> method="POST">


When I try this, Flex displays the following message instead of the page:


Code

Error Displaying Page

We're sorry, but the requested page or function either could not be located, has passed or not yet started its viewing period, or your permissions are not sufficient to view it. Please go back and try again, and contact the webmaster if you believe this to be in error.


Any suggestions as to what form action I should used to re-enter the page?

Thanks!

Cheers,
Wolf
 

Last Edit: March 11, 2008 @ 3:23pm by Wolf
DCSun
Administrator



Posts: 625
 
March 11, 2008 @ 5:13pm
Wolf,

The $MainURL value contains the site domain name and script name (ie: http://www.yourdomain.com/index.php), so if you'll know the name of the page you could do action="'.$MainURL.'/pages/pagename".

Does that help you out?


David


FlexCMS v3.2 Has Been Released!
 
Wolf




Posts: 65
 
March 11, 2008 @ 11:02pm
Hi David,

Thanks for pointing me in the right direction! It's exactly what I'm looking for.

For whatever reason, I ended up having to include "/index.php" to the string you gave me, coding it as:


Code

<form action="<?php '.$MainURL.'?>/index.php/pages/yourPageNameGoesHere.html" method="POST">


For those interested in the technique... a nonsense example of it working follows:


Code

$num_to_guess = 99;
$message = "";
if (!isset($guess)){
$message = "Welcome to the guessing machine!";
} elseif ($guess > $num_to_guess){
$message = "$guess is too big!";
} elseif ($guess < $num_to_guess){
$message = "$guess is too small!";
} else {
$message = "Well done!";
}
print $message
?>

<form action="<?php '.$MainURL.'?>/index.php/pages/yourPageNameGoesHere.html" method="POST">
Type in your guess here: <input type="text" name="guess">
</form>


One more question David, is there a Flex variable that contains the current page name (so I don't have to hard code it in the script at all)?

Thanks bunches! U Rock.

Cheers,
Wolf
 

Last Edit: March 14, 2008 @ 12:03am by Wolf
Wolf




Posts: 65
 
Querying user records via a formMarch 12, 2008 @ 12:26am
Got the production code working!

Here's the deal...

I added custom fields to my user records and needed to be able to use a form to perform queries and return all matching records while re-displaying the form for more queries.


Code

$message = "";
if (!isset($block)){
$message = "List neighborhood watch block houses [home = block 23].";
} elseif ($block < 1){
$message = "Error: block number [$block] cannot be less than 1";
} elseif ($block >100){
$message = "Erorr: block number [$block] cannot be greater than 100";
} else {
$message = "Searching for BLOCK NUMBER [$block]";
}
?>

<form action="<?php '.$MainURL.'?>/index.php/pages/test_block_query.html" method="POST">
Type block number here: <input type="text" name="block">
</form

<?PHP
$query55="SELECT * FROM `"."core-Users` WHERE Custom2 = "."\"Block $block\" order by `Custom1` asc, `Address2` asc, `Address1` asc";

print '<div><b>'.$message.'</b><br><br></div>';
print '<div>'.$query55.'</div>';


$result55 = mysql_query($query55) or die (mysql_error());

if (mysql_num_rows($result55) > 0)
{
print '<div>mysql_num_rows = '.mysql_num_rows($result55).'</div><br>';

while ($row55 = mysql_fetch_array($result55))
{
print $row55['Custom1'] .', ';
print $row55['Custom2'] .', ';
print $row55['Address1'] .' ';
print $row55['Address2'] .' ';
print $row55['Address3'] .', ';

print $row55['FirstName'] .' ';
print $row55['LastName'] .', ';
print $row55['Email'] .', ';
print $row55['Phone'] .'<br>';


$row55_custom1 = $row55['Custom1']; // save section number
}
};


The code's still a bit rough, but I'll work on tidying it up and adding more form options. But the basic idea floats!

I couldn't have done it without the excellent support from the FlexCMS staff!

Many thanks.

Wolf
 

Last Edit: March 12, 2008 @ 12:28am by Wolf
DCSun
Administrator



Posts: 625
 
March 12, 2008 @ 2:27pm

Quote (Wolf)


One more question David, is there a Flex variable that contains the current page name (so I don't have to hard code it in the script at all)?


Yes, you have a few options. You can access the whole thing as sent by the server with the $QS variable. That might be what you were looking for initially. $QSData will also give you the whole query string portion after the domain name and script name (everything after the ? or / depending on how yours is set up). And finally you can access all the portions of the query string individually with the $Arguments1, $Arguments2, etc variables. So in this case, $Arguments1 would be "pages", and $Arguments2 would be the name of your page.

I'm slightly concerned about why you had to add "/index.php" on the end of $MainURL. Perhaps you're in a function and didn't globalize the $MainURL variable? It should definitely include that already. You can see what $MainURL contains with a print statement (just a basic "print $MainURL") to see where you're at.

I don't know how much of your example code you sent, but if those things such as $block are just coming from a form element called "block" you'll only get that to work on certain systems (those with PHP Register Globals enabled). You can also make use of the FlexCMS form processing function if you like. Details on it are available here


David


FlexCMS v3.2 Has Been Released!
 
Wolf




Posts: 65
 
March 14, 2008 @ 12:24am
David,

Yep, the code I displayed above is the entire contents of a page with Process PHP code set to enabled.

I included the print statement (2x) to display $mainURL as you suggested.

I included it BEFORE my <form> tag and indeed it does show

Code

http://mysite.com/index.php


I included it AFTER my <form> tag and it also shows

Code

http://mysite.com/index.php


BUT, when I include it in the actual form action tag... I end up with a page not found and the index.php portion of the variable is missing? Very curious.

The entire page contents is:


Code

$message = "";
if (!isset($block)){
$message = "List neighborhood watch block houses [home = block 23].";
} elseif ($block < 1){
$message = "Error: block number [$block] cannot be less than 1";
} elseif ($block >100){
$message = "Erorr: block number [$block] cannot be greater than 100";
} else {
$message = "Searching for BLOCK NUMBER [$block]";
}

print '<div>MainURL=['.$MainURL.']</div>';
?>

<form action="<?php '.$MainURL.'?>/index.php/pages/test_block_query.html" method="POST">
Type block number here: <input type="text" name="block">
</form

<?PHP
$query55="SELECT * FROM `"."core-Users` WHERE Custom2 = "."\"Block $block\" order by `Custom1` asc, `Address2` asc, `Address1` asc";

print '<div>MainURL=['.$MainURL.']</div>';
print '<div><b>'.$message.'</b><br><br></div>';
print '<div>'.$query55.'</div>';


$result55 = mysql_query($query55) or die (mysql_error());

if (mysql_num_rows($result55) > 0)
{
print '<div>mysql_num_rows = '.mysql_num_rows($result55).'</div><br>';

while ($row55 = mysql_fetch_array($result55))
{
print $row55['Custom1'] .', ';
print $row55['Custom2'] .', ';
print $row55['Address1'] .' ';
print $row55['Address2'] .' ';
print $row55['Address3'] .', ';

print $row55['FirstName'] .' ';
print $row55['LastName'] .', ';
print $row55['Email'] .', ';
print $row55['Phone'] .'<br>';


$row55_custom1 = $row55['Custom1']; // save section number
}
};


I believe I'm running the same code/server setup as you and Otter... aren't we all using BC - a day at the beach?
 
DCSun
Administrator



Posts: 625
 
March 14, 2008 @ 8:43pm
Ah yes the wonderful beach with the occasional tidal wave!

I've not used the format where PHP is turned off and on throughout an HTML page as much as I probably should to become familiar with it, but my understanding is those sections still need to be properly formatted PHP code. So for this section:
Quote

<form action="<?php '.$MainURL.'?>/index.php/pages/test_block_query.html" method="POST">
should it not be
Code

<form action="<?php print $MainURL; ?>/pages/test_block_query.html" method="POST">
?


David


FlexCMS v3.2 Has Been Released!
 
Wolf




Posts: 65
 
March 14, 2008 @ 10:13pm
Embarrassed Of course! That does the trick. I'll be the first to admit I'm really just hacking in the dark most of the time! <g>

I really appreciate your feedback and help.

Learning more each day!

FlexCMS and support is da'bomb.

Cheers,
Wolf
 
DCSun
Administrator



Posts: 625
 
March 14, 2008 @ 11:34pm
I'm a big fan of the trial and error learning method myself!

David


FlexCMS v3.2 Has Been Released!
 

Post Message 




Try & Buy FeedForAll - Easy to use RSS Feed Creator - great for iTunes users!

MEMBERS




All Contents, Code, Scripts and Technologies Copyright 2003-2009 FlexCMS.
All Rights Reserved. Software License Agreement

Processing Time: 0.09010 seconds.
 
Management Login

Powered By FlexCMS
Powered By FlexCMS