shadiadiph Posted January 5, 2014 Share Posted January 5, 2014 $formhtml="<form action="sometext" method="POST">"; Please this is driving me nuts how can i remove an action="sometext" or action="" from a form? Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/ Share on other sites More sharing options...
Barand Posted January 5, 2014 Share Posted January 5, 2014 Select the text then hit the DEL button on keyboard. Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463947 Share on other sites More sharing options...
shadiadiph Posted January 5, 2014 Author Share Posted January 5, 2014 I mean automatically to change the html Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463949 Share on other sites More sharing options...
Ch0cu3r Posted January 5, 2014 Share Posted January 5, 2014 You need to explain your problem in more detail. Such as how and when do you want the form action to change. Are you wanting to change the action when a user clicks a button/link? if so then this will be handled by javavscript not PHP. Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463952 Share on other sites More sharing options...
shadiadiph Posted January 5, 2014 Author Share Posted January 5, 2014 I am dynamically creating a form from two seperate sources and need to remove the action="something" or action="" or if there is a way to change the action="someting or nothing" can't seem to get the correct regex to replace any text between it so i am trying to remove it and recreate it. The php variable is $formhtl="<form action="something or nothing" method="post">(form fields etc</form>"; I tried str_replace and preg_replace but cant get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463953 Share on other sites More sharing options...
Ch0cu3r Posted January 5, 2014 Share Posted January 5, 2014 (edited) If you are generating the form html in your PHP code then define the action as a variable. $action = "something or nothing"; $formhtl='<form action="'.$action.'" method="post">(form fields etc</form>'; Edited January 5, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463957 Share on other sites More sharing options...
shadiadiph Posted January 5, 2014 Author Share Posted January 5, 2014 There is already an action attribute on the form i am calling i am just adding to the input fields with php but i want to change the action on the fly Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463959 Share on other sites More sharing options...
jazzman1 Posted January 5, 2014 Share Posted January 5, 2014 You could start your first posting showing your script. If you have some actual error(s), would help. Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463974 Share on other sites More sharing options...
JIXO Posted January 5, 2014 Share Posted January 5, 2014 (edited) You may be looking for preg_replace() function. <?php $formhtml = '<form action="" method="post">'; $pattern = '/action=""/'; $replacements = array(); $replacements[0] = ''; $replacements[1] = 'action="action1"'; echo preg_replace($pattern, $replacements[0], $formhtml)."<br />"; echo preg_replace($pattern, $replacements[1], $formhtml); Will output : <form method="post"> <form action="action1" method="post"> Edited January 5, 2014 by JIXO Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1463981 Share on other sites More sharing options...
dakota367 Posted January 6, 2014 Share Posted January 6, 2014 This regex patturn will match the action="***" part of the string. Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1464025 Share on other sites More sharing options...
objnoob Posted January 6, 2014 Share Posted January 6, 2014 Just don't dynamically create the form using this line. $formhtml="<form action="sometext" method="POST">"; Quote Link to comment https://forums.phpfreaks.com/topic/285112-remove-action-from-a-form/#findComment-1464034 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.