Jump to content

How to store form in variable?


Dan06

Recommended Posts

I'm trying to create a conditional form. The idea is that there is one page with two forms and based on the user's previous page/form selections one of the new forms will be shown. I've figured out (in theory) that I can store the form in a variable, run an if/then statement, and then print to a selected div tag. The problem I'm having is storing the form in a variable. Following is the code for my form:

 

<form action="<?php echo $editFormAction; ?>" method="post" name="indProForm" id="indProForm">
            <table align="center">
              <tr valign="baseline">
                <td nowrap="nowrap" align="right">City:</td>
                <td><input type="text" name="City" value="<?php echo htmlentities($row_profileRegister['City'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right">State:</td>
                <td><input type="text" name="State" value="<?php echo htmlentities($row_profileRegister['State'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right">Zip:</td>
                <td><input type="text" name="Zip" value="<?php echo htmlentities($row_profileRegister['Zip'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"> </td>
                <td> </td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"> </td>
                <td><input type="submit" value="Update record" /></td>
              </tr>
            </table>
            <input type="hidden" name="MM_update" value="indProForm" />
            <input type="hidden" name="Id" value="<?php echo $row_profileRegister['Id']; ?>" />
</form>
<p> </p>

 

How can I store the above form in a variable? Help and insight are much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/125553-how-to-store-form-in-variable/
Share on other sites

Uhh...If you already had that going on and you didn't want to change it:

 

<?php
ob_start();
?>
<form action="<?php echo $editFormAction; ?>" method="post" name="indProForm" id="indProForm">
            <table align="center">
              <tr valign="baseline">
                <td nowrap="nowrap" align="right">City:</td>
                <td><input type="text" name="City" value="<?php echo htmlentities($row_profileRegister['City'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right">State:</td>
                <td><input type="text" name="State" value="<?php echo htmlentities($row_profileRegister['State'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right">Zip:</td>
                <td><input type="text" name="Zip" value="<?php echo htmlentities($row_profileRegister['Zip'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"> </td>
                <td> </td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"> </td>
                <td><input type="submit" value="Update record" /></td>
              </tr>
            </table>
            <input type="hidden" name="MM_update" value="indProForm" />
            <input type="hidden" name="Id" value="<?php echo $row_profileRegister['Id']; ?>" />
</form>
<p> </p>
<?php
$form = ob_get_clean();
?>

I tried using ob_start(); and ob_get_clean(); but when I do I get the following error: Parse error: syntax error, unexpected '<' in D:\Apache\htdocs\profileregister.php on line 47

 

Here is the code:

ob_start();
		  <form action="<?php echo $editFormAction; ?>" method="post" name="busProForm" id="busProForm">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">Company Name:</td>
                  <td><input type="text" name="CompanyName" value="<?php echo htmlentities($row_profileRegister['CompanyName'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">Telephone Number:</td>
                  <td><input type="text" name="TelNumber" value="<?php echo htmlentities($row_profileRegister['TelNumber'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">Street:</td>
                  <td><input type="text" name="Street" value="<?php echo htmlentities($row_profileRegister['Street'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">Street 2:</td>
                  <td><input type="text" name="Street2" value="<?php echo htmlentities($row_profileRegister['Street2'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">City:</td>
                  <td><input type="text" name="City" value="<?php echo htmlentities($row_profileRegister['City'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">State:</td>
                  <td><input type="text" name="State" value="<?php echo htmlentities($row_profileRegister['State'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">Zip:</td>
                  <td><input type="text" name="Zip" value="<?php echo htmlentities($row_profileRegister['Zip'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"> </td>
                  <td> </td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"> </td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="busProForm" />
              <input type="hidden" name="Id" value="<?php echo $row_profileRegister['Id']; ?>" />
            </form>
          <p> </p>

$busFormType = ob_get_clean();
<head>...</head>

Thanks. The <?php ?> tags were the issue. I had placed the entire block of code within the <?php ?> tags, rather then just the ob_start(); and ob_get_clean(); functions.

 

Storing the forms in the variables allowed me to use the if/then statements and div tags to create the conditional form. But is there a better or more efficient way of creating conditional forms based on previous form selections? If anyone knows or has any suggestions please share them; I'd be interested in reading them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.