php - Cant understand Why My Sites Keeps Navigating To Its Index Page? -
i creating website using php , jquery , have come problems rearding forms.
for example, index.php looks following:
<body> <?php echo "<div id=\"web_page\">"; require("public/templates/header.php"); require("public/templates/menu.php"); require("public/templates/home.php"); require("public/templates/footer.php"); echo "</div>"; ?> </body> it loads header, footer, menu area , starting page. files loaded encased in div areas final index.php rendered so:
<div id="web_page"> <div id="web_header"> //contents of header.php loaded div// </div> <div id="web_menu"> //contents of menu.php loaded div// </div> <div id="web_contents"> //contents of home.php loaded div// </div> <div id="web_footer"> //contents of footer.php loaded div// </div> </div> the menu items loaded web_contents div area using javascript code:
$('#web_menu a').click(function(e) { e.preventdefault(); $('#web_content').load($(this).attr('href'), function() { }); }); now code loads pages selected menu web_contents div area. have created page called register.php , has unexpected functuality. below rendered html it, load in web_contents div area:
<div id="reg_div"> <form id="reg_form> <label>desired username: </label><input type="text" name="uname" id="uname" /> <button>register</button> </form> </div> the index.php page rendered this:
<div id="web_page"> <div id="web_header"> //contents of header.php loaded div// </div> <div id="web_menu"> //contents of menu.php loaded div// </div> <div id="web_contents"> <div id="reg_div"> <form id="reg_form> <label>desired username: </label><input type="text" name="uname" id="uname" /> <button>register</button> </form> </div> </div> <div id="web_footer"> //contents of footer.php loaded div// </div> </div> the problem though form has no functionality , neither button, whenever button clicked, website navigates index.php page. cannot understand why?
could see why code cause triggered button navigate index.php. also, since index.php collection of require() pages, , register.php loaded there, causing page automatically discard web_contents div contained register.php , replace contents of home.php?
this confusing me?
any feedback appreciated. thanks.
firstly, missing quotation in line
<form id="reg_form> // <--- missing quote also, you'll want update this...
<form id="reg_form" onsubmit="return(false);"> // <--- should prevent form submittion
Comments
Post a Comment