Recent Topics

1 Jan 06, 2011 00:54    

My b2evolution Version: 4

Does anyone have a suggestion for an easy way to build forms and submit them?

I'd like to be able to build HTML forms and have them submit through a generic php file if possible. I modified the built in message_send.php file to allow for more fields but I'm looking for a more elegant solution. Any ideas?

2 Jan 20, 2011 04:07

Create a file myform.php with this content

<?php

/**
 * First thing: Do the minimal initializations required for b2evo:
 */
require_once dirname(__FILE__).'/conf/_config.php';

$use_session = false;
require_once $inc_path.'_main.inc.php';

if( param( 'form_sent', 'boolean' ) )
{
	$number = param( 'fm_number', 'integer' );
	$name = param( 'fm_name', 'string' );
	$select = param( 'fm_select', 'string' );
	$text = param( 'fm_text', 'html' );
	
	if( param( 'fm_box', 'boolean' ) )
	{
		echo 'Box checked';
	}
	else
	{
		echo 'Box not checked';
	}
	echo '<br />fm_number: '.$number;
	echo '<br />fm_name: '.$name;
	echo '<br />fm_text: '.$text;
	echo '<br />fm_select: '.$select;
}
else
{
	echo '<head>
		<link rel="stylesheet" href="'.$adminskins_url.'chicago/rsc/css/chicago.css" type="text/css" />
		</head>
		<div style="width:700px; margin:30px auto; padding:20px; background:#FFF">';
	
	$Form = new Form( NULL, 'form' );
	$Form->begin_form('fform', 'My brand new form');
	$Form->hidden( 'form_sent', 'true' );
	
	$Form->begin_fieldset( 'Form info' );
	$Form->info( 'Info field', 'This is an info field' );
	$Form->end_fieldset();
	
	$Form->begin_fieldset( 'Whatever' );
	$Form->checkbox( 'fm_box', 0, 'Check this box', 'some notes here' );
	$Form->text( 'fm_number', '', 5, 'Enter some number', 'some notes here', 3 );
	$Form->text( 'fm_name', '', 30, 'Enter name' );
	$Form->select_input_options( 'fm_select', '<option name="opt1">Option 1</option><option name="opt2">Option 2</option>', 'Select an option' );
	$Form->textarea( 'fm_text', '', 4, 'Text' );
	$Form->end_fieldset();
	
	$Form->end_form( array( array( 'submit', 'submit', 'Test the form!' ) ) );
	
	echo '</div>';
}

tested ;)

?>


Form is loading...