suess0r Posted December 12, 2006 Share Posted December 12, 2006 hey guys, i was wondering if there was a way in php to randomize the submit value of my form button to say 1 of 10 different sayings...for instance, on random load button would say "Make it so" or "What's the score?" or "Happy Feet" something like that? thanks ;D Quote Link to comment https://forums.phpfreaks.com/topic/30373-randomize-submit-form-button-value/ Share on other sites More sharing options...
hitman6003 Posted December 12, 2006 Share Posted December 12, 2006 [code]<?php$button_text = array('Make it so','What's the score?','Happy Feet');echo '<input type="submit" name="submit" value="' . $button_text[array_rand($button_text)] . '">'; ?>[/code]You may have to move the array_rand function out from between the brackets ( [ and ] ), but the idea is the same. Quote Link to comment https://forums.phpfreaks.com/topic/30373-randomize-submit-form-button-value/#findComment-139751 Share on other sites More sharing options...
suess0r Posted December 12, 2006 Author Share Posted December 12, 2006 thanks, works perfect.. thanks ;D Quote Link to comment https://forums.phpfreaks.com/topic/30373-randomize-submit-form-button-value/#findComment-139763 Share on other sites More sharing options...
Daniel0 Posted December 12, 2006 Share Posted December 12, 2006 In fact it wont work perfect as the ' in key 1 in the array has to be escaped, but you seem to have got the point. Quote Link to comment https://forums.phpfreaks.com/topic/30373-randomize-submit-form-button-value/#findComment-139811 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.