Convert forms to html helpers

74 views
Skip to first unread message

LoveWeb2py

unread,
Jul 13, 2015, 7:46:32 AM7/13/15
to web...@googlegroups.com
Hello,

Is there something within web2py that automatically converts html forms to html HELPER SYNTAX?

for example here is my form:
        <div id="checkout-area" style="display: none;">
        <h4><i class="icon-shopping-cart"></i> Secure Checkout</h4>
        <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
        <div id="checkout-form" style="display: none;">
        <form id="CardForm">
            <div class="control-group">
            <label>Cardholder Name</label>
            <input id="CardName">
                        <span class="help-inline"></span>
                    </div>
                    
                    <div class="control-group">
            <label>Address</label>
            <input id="address">
                        <span class="help-inline"></span>
                    </div>
                    
                    <div class="control-group">
            <label>City</label>
            <input id="city">
                        <span class="help-inline"></span>
                    </div>
                    
                    <div class="control-group">
            <label>State</label>
            <input id="state">
                        <span class="help-inline"></span>
                    </div>
                    
                    <div class="control-group">
            <label>Zip Code</label>
            <input id="zip">
                        <span class="help-inline"></span>
                    </div>
                        
            <div id="div-card" class="control-group">
            <label>Card Number</label>
            <input id="CardNumber" placeholder="4242424242424242"/>
                <span id="span-card" class="help-inline"></span>
               </div>
               
               <div id="div-exp" class="control-group">
            <label>Expiration</label>
            <input id="CardExpiration" placeholder="12/2013"/>
                    <span id="span-exp" class="help-inline"></span>
                    </div>
                    
                    <div id="div-cvc" class="control-group">
            <label>CVC Code</label>
            <input id="CardCVC" placeholder="123"/>
                    <span id="span-cvc" class="help-inline"></span>
                    </div>
                    
            <div class="form-actions">
            <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
</form>
       </div>

and I want to convert it something like this: DIV(H4(I(_class='icon-shopping-cart')), _id="checkout_area", _style="display: none;"
)

What is the most efficient way to do this? 

黄祥

unread,
Jul 13, 2015, 8:50:42 AM7/13/15
to web...@googlegroups.com
i think your approached is the most efficient way.
please read this discussion :
http://stackoverflow.com/questions/8091487/what-are-the-benefits-of-building-html-markup-with-html-helpers-in-web2py

best regards,
stifan

LoveWeb2py

unread,
Jul 13, 2015, 9:20:48 AM7/13/15
to web...@googlegroups.com
Hi Stifan,

Thank you for replying. Do you know if there is anything that converts forms automatically? I'd think there would be something to do this by now?

Anthony

unread,
Jul 13, 2015, 9:41:09 AM7/13/15
to web...@googlegroups.com, atayl...@gmail.com
I don't think I've seen any such tools. In general, it is not very common to create large static sections of the DOM using the web2py HTML helpers. They are more useful when you need to generate DOM programmatically (e.g., input some form configuration parameters and automatically produce a form DOM, such as how SQLFORM works) -- in that case, though, you would be writing a function to generate the DOM, not merely parsing some existing HTML and converting it to web2py helper code.

What exactly are you trying to achieve? Why do you want to convert that HTML markup to web2py helper code?

Note, if you just want to parse some existing HTML into a helper object that can then be manipulated (rather than producing actual helper code), you can use the parsing functionality of the TAG helper as described here: http://web2py.com/books/default/chapter/29/05/the-views#Parsing

Anthony

黄祥

unread,
Jul 13, 2015, 9:45:33 AM7/13/15
to web...@googlegroups.com
Do you know if there is anything that converts forms automatically?

had you already read the book? web2py provides many way to create a form (FORM, SQLFORM, crud, SQLFORM.grid, SQLFORM.factory, form custom) to convert form automatically, i don't think it have.

i think the closer method to catch up with your code is using form.custom, please take a look at the book.
ref:
http://web2py.com/books/default/chapter/29/07/forms-and-validators#Custom-forms

best regards,
stifan

LoveWeb2py

unread,
Jul 13, 2015, 9:50:46 AM7/13/15
to web...@googlegroups.com
Parsing!! Not sure how I missed that. Thank you, Anthony. This is exactly what I was looking for.
Reply all
Reply to author
Forward
0 new messages