Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 07-04-2014, 07:59 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,348
Kyttias is on a distinguished road
Default FormBuilder class?

Working here with v1.3.4, and I'm trying to recreate this, basically:
Code:
<form id="gamescore" action="" method="post">
<input type="hidden" value="100" name="amount" />
<button class="btn btn-default" id="sendtest">Click!</button>
</form>
I've tried echoing it out and, yeah, I can get it to appear just fine, I'm just not sure how to point the action attribute to the script I want to run. (A class file in the classes folder.) So I decided to go stare at what other pages are doing.

I see FormBuilder() working here:
PHP Code:
$donateForm = new FormBuilder("donateform""donate""post");
        
$donateForm->buildComment("Donate to: "FALSE)
                   ->
buildTextField("recipient")
                   ->
buildComment("Amount to donate: "FALSE)
                   ->
buildTextField("amount")
                   ->
buildButton("Donate""submit""submit");
        
$document->add($donateForm); 
Two questions come to mind...

The first variable in FormBuilder() seems to be the form's id, and the last one is the method. The middle seems to be the action, but that's not a php page it's linking to, that's just a mere word?? So I'm guessing FormBuilder automatically tacks on the .php extension, and, in that case, the form's action location is the one just in the root folder, not one inside classes. Is this right? Minimum, what do I need to set up a page in the root to run a function? Specifically something like~

PHP Code:
public function gamescore() {
$mysidia Registry::get("mysidia");
if(
$mysidia->input->post("amount")){ 
$amount $mysidia->input->post("amount");
$this->money += $amount
$mysidia->db->update("users", array("money" => $this->money), "username = '{$this->username}'");
$document->setTitle("Success");
$document->add(new Comment("Obtained {$amount} {$mysidia->settings->cost}!"));
$this->refresh(3);
return;
}

And even that may be terribly wrong, I won't know until I know my form is actually submitting somewhere.

The second question is harder, as I need to create an input field with type="hidden". I assume a type="text" is what has now become ->buildTextField, so what is the equivalent for hidden input fields?

Note that I also need the FormBuilder() to add on class and id attributes to the button, too, please? I'd also like insight on how to add classes to various things in Mysidia through the architecture given to us, rather than having to hack it in later with jQuery.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 07-04-2014 at 08:15 AM.
Reply With Quote
  #2  
Old 07-04-2014, 02:48 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,375
IntoRain is on a distinguished road
Default

I like to use forms the same way it's used in registerview.php. I find it more simple and I think it's a good example.

Unless it's ajax, you don't need to have the action code in a different function at all:

In registerview.php you will notice this line:

$securityField->add(new Button("Register", "submit", "submit"));

The form is sending through POST and you might notce the "submit" in the button above:

if($mysidia->input->post("submit"){
//means the button was clicked, check sent data here
}

And all inputs can be checked like that:

$requiredField->add(new TextField("username"));
$mysidia->input->post("username");//in register.php

---

You want a class in the classes folder or to create a new page?
__________________


asp.net stole my soul.

Last edited by IntoRain; 07-04-2014 at 02:50 PM.
Reply With Quote
  #3  
Old 07-04-2014, 04:14 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,348
Kyttias is on a distinguished road
Default

I need to get a confirmation callback live in jQuery if and when the function I'm needing fires, that way I can display a confirmation in place. Inevitably I'm disabling the default form functionality (see the very last example on this page), so maybe Ajax isn't important, but I still need to know what file/where to point to, so I can get a response from it. =/

My intentions:

My long term goal here is to attach a function to the template that will make a display a giftbox on any page at an extremely rare random. Without leaving the current page whatsoever, the user will click the giftbox, it will open reward them with currency, and tell them just how much they obtained. There will be an 'x' in the corner to dismiss the opened box, clicking anywhere else after the box has been opened will dismiss the box, and it definitely won't be there again on a reload unless they have somehow obtained a new, unopened giftbox. If the giftbox were to appear on an important page, such as one that contained a confirm or next button, the user absolutely would not want to be redirected elsewhere as that would disrupt their navigation of the website.

I absolutely do not want to create a new page anywhere in this process, except if I need to make a new one in root just to process the form data, and I need to know how and where to point to it. But the form itself created in class_template.php and is invisible, hence me asking how to create a hidden text field with the FormBuilder, since I know how to do it if I could manually write the form, and is just the 'submit' button, which is in the shape of a giftbox, and not even a button, visually, at all.

Thank you so much for always being helpful!

In classes/class_template.php I've added in this (where we doing stuff before):

PHP Code:
$giftboxform '<form action="addcash.php" id="giftbox">
        <input type="hidden" value="100" name="amount" />
        <input type="submit" class="giftbox">Click!</input>
        </form>'
;
        
$giftboxresult '<div id="result"></div>';
        
$giftboxjquery '<script>
        // Attach a submit handler to the form
        $( "#giftbox" ).submit(function( event ) {
        
        // Stop form from submitting normally
        event.preventDefault();
        
        // Get some values from elements on the page:
        var $form = $( this ),
        amount = $form.find( "input[name=\'amount\']" ).val(),
        url = $form.attr( "action" );
        
        // Send the data using post
        var getgift = $.post( url, { amount: amount } );
        
        // Put the results in a div
        getgift.done(function( msg ) {
        $( "#gamescore" ).hide(); // hide the form
        $( "#result" ).html( msg );
        });
        
        // If failure
        getgift.fail(function( jqXHR, textStatus ) {
        alert( "Request failed: " + textStatus );
        });
        });
        </script>'
;
        
$this->assign("giftbox","{$giftboxform}{$giftboxresult}{$giftboxjquery}"); 
This successfully renders the invisible form and it's submit button (though the intention is for it to look like a giftbox, not a button, with css). It also renders a div whose contents will be filled with the result, and the jQuery necessary to process the form inline and return the result. It does successfully pass a variable to php.

However, I need to now go make "addcash.php" in the root... and add the function to it:
PHP Code:
public function gamescore() {
$mysidia Registry::get("mysidia");
if(
$mysidia->input->post("amount")){ 
$amount $mysidia->input->post("amount");
$this->money += $amount
$mysidia->db->update("users", array("money" => $this->money), "username = '{$this->username}'");

return 
"Obtained" $amount ".";
}

That's the remaining thing I need help with, but I'm going to try and imitate what's there... so I'm off to try that.

edit: Ok no matter what I try, it's still be terribly dumb and never updating the database, even if I use an actual standard database request with normal php and not the Mysidia way. Regardless of it ever returning data for confirmation's sake, it should at LEAST do that much and it never accomplishes that.

If you can think of a better way to do all this, anyway at all, so long as there is not a page redirect or reload, give it a shot. Heck, even do one that does require a reload. I really just need a way to give users cash at the click of a button or the run of a Javascript function (giftbox, gamescore, anything).
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 07-04-2014 at 07:28 PM.
Reply With Quote
Reply

Tags
formbuilder


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with the class controller Isura Questions and Supports 4 04-09-2014 03:21 PM
Problem: smarty class 1.3.4 draugluin Questions and Supports 8 11-15-2013 02:29 AM
Critical Errors (PDO Class not Found) LucasA33 Questions and Supports 2 11-21-2012 05:38 PM


All times are GMT -5. The time now is 07:44 AM.

Currently Active Users: 9727 (0 members and 9727 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636