GriefCode Posted December 14, 2016 Posted December 14, 2016 Hey, I have created a wizard which includes per step different forms, all over i have the code here:https://github.com/gamershost/Forum-Application/blob/master/modules/front/report/add.php Now my issues: Is there any way to define your custom template for a Radio Button, I really dislike using html on php:https://github.com/gamershost/Forum-Application/blob/master/modules/front/report/add.php#L92-L108 When i'm continueing to the next step, it appears that the form was submited once, i'm getting always an validation error that a field is reuired. I assume that somehow the form gets submited by just opening continue the wizard: What is a good way to clean up the wizard at the end? I have locally continued the coding, my last step looks like this: $steps['information'] = function( $data ) { $form = new \IPS\Helpers\Form(); $form->addHeader('More Information'); $form->add(new \IPS\Helpers\Form\Editor('report_description', NULL, TRUE, array('app' => 'dvstats', 'key' => 'report', 'autoSaveKey' => 'report', 'attachIds' => NULL))); $form->add(new \IPS\Helpers\Form\TextArea('report_comment', null, true)); if ($values = $form->values()) { $report = new \IPS\dvstats\Report; $account = \IPS\dvstats\BNetAccount\Account::load(\IPS\Member::loggedIn()->member_id); $report->reporter_player_id = $account->dota_player_id; $report->reporter_forum_id = \IPS\Member::loggedIn()->member_id; $report->player_id = $data['playerid']; $report->game_id = $data['gameid']; $report->reason = $data['reason']; $report->description = $values['report_description']; $report->comment = $values['report_comment']; $report->save(); \IPS\Output::i()->redirect(\IPS\Http\Url::internal( 'app=dvstats&module=report&controller=view', 'front' ), 'dvstats_report_added'); } return $form; }; However, after the submission when i visit back the form wizard im still on my last step and can submit the form again. By manually jumping back to the first step will result an allover mess because of the mentioned issue on #2 where the form will be submited again. Any help would be really nice I know the code is not perfect and i know some tweaks, i mostly adjust them after, as well as direct translations that are currently added into the code.
Ilya Hoilik Posted December 14, 2016 Posted December 14, 2016 1. Sounds awful, but you can hook into core → global → forms → radio template and change what you need. Or you can hook into \IPS\Helpers\Form\Radio::html() and return your own template for radio buttons. 2. Faced the same problem in the main functionality week or two ago. Sounds like a bug. 3. About third question. Did you tried like so? I'm not actually sure, but it might works: /* Define $url at the start of your method */ $url = \IPS\Http\Url::internal('app=dvstats&module=report&controller=add'); /* And then unset data in $_SESSION when necessary */ unset( $_SESSION[ 'wizard-' . md5( $url ) . '-data' ] ); It will be funny if all of my answers are wrong
GriefCode Posted December 14, 2016 Author Posted December 14, 2016 Just now, Ilya Hoilik said: 1. Sounds awful, but you can hook into core → global → forms → radio template and change what you need. Or you can hook into \IPS\Helpers\Form\Radio::html() and return your own template for radio buttons. 2. Faced the same problem in the main functionality week or two ago. Sounds like a bug. 3. About third question. Did you tried like so? I'm not actually sure, but it might works: /* Define $url at the start of your method */ $url = \IPS\Http\Url::internal('app=dvstats&module=report&controller=add'); /* And then unset data in $_SESSION when necessary */ unset( $_SESSION[ 'wizard-' . md5( $url ) . '-data' ] ); It will be funny if all of my answers are wrong Also if they should be wrong it doesn't matter, at least you tried to help which is nice :-) 1. The hook would be really not my thoughts on that, i thought there would be another solution, this sounds a bit overloaded for the functionality i require. 2. Okay good to know, thanks 3. Does sadly not work.
Martin A. Posted December 14, 2016 Posted December 14, 2016 $url needs to be the same URL used when initializing the wizard. Also throwing "_new=1" in the query string on the first page will force the wizard to remove old data. EDIT: Wizard::__toString() will reset it no matter how many times you unset() $_SESSION.
GriefCode Posted December 14, 2016 Author Posted December 14, 2016 11 minutes ago, Martin A. said: $url needs to be the same URL used when initializing the wizard. Also throwing "_new=1" in the query string on the first page will force the wizard to remove old data. Thanks, the _new=1 did it :-)
teraßyte Posted December 14, 2016 Posted December 14, 2016 1) There is no need to add an hook, rather it adds an unnecessary step. You can create your own PHP class that extends \IPS\Helpers\Form\Radio. From there simply define your new html() function to return the template you want. Let's say you name it MyCustomRadioList and place the file inside \applications\dvstats\sources\Form: namespace IPS\dvstats\Form; /* To prevent PHP errors (extending class does not exist) revealing path */ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' ); exit; } /** * Custom Radio input helper for Form Builder */ class _MyCustomRadioList extends \IPS\Helpers\Form\Radio { /** * Get HTML * * @return string */ public function html() { # Your code here, be sure to add the same checks the original file has! } } Then in your form you simply call your own form helper: $form->add( new \IPS\dvstats\Form\MyCustomRadioList( ... ) );
Recommended Posts
Archived
This topic is now archived and is closed to further replies.