0

I am currently programming a plugin for wordpress which needs to execute a PHP command in the action tag of a form. This is my current code which gets echoed (of course with closing tags in the end):

<form action="'<?php echo admin_url('admin-ajax.php'); ?>'" method="post" >
<?php wp_nonce_field('csv_submit','csv_nonce'); ?>
<input type="hidden" name="action" value="csv_submit">

When I execute it like this the browser tries to open localhost/'<?php echo admin_url('admin-ajax.php'); which, of course, doesn't exist. How can I fix it so the browser won't see it as reference, but like PHP code?

Edit 1:
The code is placed in the shortcode-function of my plugin. It is the beginning of a String that is returned at the end of the function.


function csvcontact(){

 $output = file_get_contents('csvcontact/formstart.php', true); //Here lies the shown code

     
 // Here happens something with the  given attributes

 
$output .= '</form>';

 return $output;
}
EinSteini
  • 13
  • 3
  • 1
    Why are you putting double _and_ single quotes around the value? – CBroe Jul 07 '20 at 10:13
  • 1
    If `` did not get executed, then you probably weren’t in a PHP parser context to begin with here. You need to give us more details, where exactly you placed this code. – CBroe Jul 07 '20 at 10:14
  • @CBroe i've seen this on the internet. doesn't work with or without these. – EinSteini Jul 07 '20 at 10:17

1 Answers1

0

Edit:

Please check whether the PHP script is being executed properly by the interpreter, the file has proper extension and is not using short open tag <? ... ?> instead of <?php ... ?>. Try adding simple echo statements to verify.

Additionally, I'd like to address that the redundant set of quotes are unnecessary inside the action attribute, removing the outer single quotes,

<form action="<?php echo admin_url('admin-ajax.php'); ?>" method="post" >
<?php wp_nonce_field('csv_submit','csv_nonce'); ?>
<input type="hidden" name="action" value="csv_submit">
Sohel Aman
  • 482
  • 4
  • 6